# DSPy signature for the data_viz_agent classdata_viz_agent(dspy.Signature): """ You are AI agent who uses the goal to generate data visualizations in Plotly. You have to use the tools available to your disposal If row_count of dataset > 50000, use sample while visualizing use this if len(df)>50000: ....... Only this agent does the visualization Also only use x_axis/y_axis once in update layout {dataset} {styling_index} You must give an output as code, in case there is no relevant columns, just state that you don't have the relevant information Make sure your output is as intended! DO NOT OUTPUT THE DATASET/STYLING INDEX ONLY OUTPUT THE CODE AND COMMENTARY. ONLY USE ONE OF THESE 'K','M' or 1,000/1,000,000. NOT BOTH You may be give recent agent interactions as a hint! With the first being the latest DONT INCLUDE GOAL/DATASET/STYLING INDEX IN YOUR OUTPUT! You can add trendline into a scatter plot to show it changes,only if user mentions for it in the query! You are logged in streamlit use st.write instead of print """ goal = dspy.InputField(desc="用户定义的目标,包括他们想要绘制的数据和图表的信息") dataset = dspy.InputField(desc="提供有关数据框中数据的信息。仅使用列名和数据框名称") styling_index = dspy.InputField(desc='提供有关如何样式化您的Plotly图表的说明') code= dspy.OutputField(desc="根据查询和数据框索引及样式上下文可视化用户需求的Plotly代码") commentary = dspy.OutputField(desc="关于正在执行的分析的评论,这不应包括代码")
# Defining a module query ="可视化 X 与 Y" data_viz_ai = dspy.ChainOfThought(data_viz_agent)
#For information on the dataframe index & styling index, visit this: # https://readmedium.com/building-auto-analyst-a-data-analytics-ai-agentic-system-3ac2573dcaf0 data_viz_ai(goal=query, styling_index=styling_index, dataset=dataset_)
classcode_fix(dspy.Signature): """ You are an AI which fixes the data analytics code from another agent, your fixed code should only fix the faulty part of the code, rest should remain the same You take the faulty code, and the error generated and generate the fixed code that performs the exact analysis the faulty code intends to do You are also give user given context that guides you how to fix the code! please reflect on the errors of the AI agent and then generate a correct step-by-step solution to the problem. You are logged in streamlit use st.write instead of print """ faulty_code = dspy.InputField(desc="The faulty code that did not work") previous_code_fixes = dspy.InputField(desc="User adds additional context that might help solve the problem") error = dspy.InputField(desc="The error generated")
faulty_code = dspy.OutputField(desc="Only include the faulty code here") fixed_code= dspy.OutputField(desc="The fixed code")