Class to call AI to generate a plotly figure from a table. The data of the table is not transferered to OpenAI, only the provided text.
chat: OpenAiChat
message_dispatcher: MessageDispatcher
table: Table
Initialize self. See help(type(self)) for accurate signature.
Table
OpenAiChat
Any
Method to build the variables that will be accessible in the generated code. It is recommended to use known object types for the inputs, like dict, list, Dataframe, int ... so the AI can understand the structure of the input.
dict
Method to define the context rules for the code generation, so the generated code is executable. This method can be overrided to change the way of describing the code context.
List
str
Method that is automatically called by the task to build the context. This method can be overided to change the way of describing the context.
Dict
str
Method that is automatically called by the task to describe the inputs that are accessible in the generated code. This method can be overrided to change the way of describing the inputs, or to add more information (like the number of rows for a dataframe, the structure of a json ...)
Dict
str
Method to build the context of the openAI chat. This should define the main goal of the task. You can use context variable to build main context.
The recommended order is :
- INTRO
- Text to explain the goal of the task (Ex: "The code purpose is to generate a plotly express figure from a DataFrame.")
- INPUTS
- OUTPUTS
- CODE_RULES
You can insert text after a variable to add more information, like :
- inputs_description + 'The dataframe has ' + str(table.nb_rows) + ' rows and ' + str(table.nb_columns) + ' columns.'
- outputs_description + 'Only build the figure object, do not display the figure using 'show' method.'
AIPromptCodeContext
str
Method to build the output based on the generated code outputs.
dict
PlotlyResource
Method that is automatically called by the task to describe the outputs that are accessible in the generated code. This method can be overrided to change the way of describing the outputs.
str
Generate the agent code that will be used to run the code in the agent.
str
Method to retrieve the package names that can be used by the AI in the generated the code. The package must be installed in the lab. This is used by build_code_context to retrieve the version of the package are write a text to describe the packages. Return empty list if no package is needed.
List
Method to describe the output names (keys) and types (values) expected by the generated code. The AI will receive instructions to generate code that returns variables with the specified names and types. This is used by build_task_outputs to retrieve the output of the generated code.
Dict
Any
Get the task output config for the generate_agent_code task.
OutputSpec