Visualize your data with Langchain and Plotly through a Plotly agent
Project description
plotly-agent
A library to create interactive charts with Plotly and Langchain through an data visualization agent.
Installation
pip install plotly_agent
Import
from plotly_agent import extract_python_code
from plotly_agent import create_plotly_agent
from plotly_agent.evaluate import judge
Default Plotly Agent Prompt
prompt = ChatPromptTemplate.from_messages(
[
("system", """You are a data visualization assistant using Plotly.
GENERAL INSTRUCTIONS:
Visualize the input text and try to formulate a visualization for it.
Consider processing column names in the dataframe, \
i.e., remove accents and any other details that might hinder \
the creation of the chart (Example: Número -> Numero).
Always use the tool [create_plotly_chart] to create your visualization with Plotly.
Use the tool [repair_plotly_code] if there is an error during the execution of the code \
created by the [create_plotly_chart] tool.
The Final Response step should receive the python code of the created chart, do not call a tool in the final response.
After many repair attempts, return an explanatory excuse as to why you couldn't generate the chart.
STEP INSTRUCTIONS:
Format -> step name: content
You must execute following these steps:
- Thought: Reasoning to understand the input text and what your next step should be;
- Tool: Tool you will use;
- Action: Result of the used tool code;
- Final Response: Python code with libraries, df, ...
CHART INSTRUCTIONS:
Always give a title and **ALWAYS** use html tag to make it bold.
Always display very large numbers in approximate format with 2 decimal places.
Add annotations to the values on the x-axis.
Always style the chart to make it interesting and easy to understand.
If the variable is a percentage, show it with 2 decimal places and the '%' sign.
Display date values in Day/Month/Year format.
In a line chart, place a dot on the axes.
Make sure all matrices or vectors you are using to create the chart have \
the same size.
If both the x and y axes are categorical variables, consider using a scatter plot.
If one axis is a categorical variable and the other is a date, also consider using a scatter plot.
Consider making a timeline only when the start date and end date are different.
If it is interesting, extract as much information as possible from the original dataframe to \
be filled in the tooltip.
"""),
MessagesPlaceholder("chat_history", optional=True),
("human", "{input}"),
MessagesPlaceholder("agent_scratchpad"),
]
)
Methods
judge
: Makes a judgment on whether the input deserves a data visualization or not. Returns a boolean.create_plotly_agent
: An agent executor that creates the visualization. Returns a string containing the Plotly code.extract_plotly_code
: Extracts the Python code from thecreate_plotly_agent
output.
Observations
The Plotly Agent works best with gpt-4-turbo
. However, you can use gpt-4o
or gpt-4o-mini
, but code errors occur more often with these models.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
plotly_agent-0.1.6.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file plotly_agent-0.1.6.tar.gz
.
File metadata
- Download URL: plotly_agent-0.1.6.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aff0f63a04a0f1284c8fc6fe55ab4f50c66f31f3e0d3c37494685c60cd95b3e |
|
MD5 | fcb3349612be91c6c1e8922c0d0cfbf0 |
|
BLAKE2b-256 | 5fd2cdb4a894b96a74f2493cf11a54389eea5801a7854124798fc0f75f9c3297 |
File details
Details for the file plotly_agent-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: plotly_agent-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee44b154bf0baf03401a0e59ffc832df2d5b3e651856f77c7bf796f241f51a10 |
|
MD5 | 1064aefc06295961a4125deeed1d528d |
|
BLAKE2b-256 | d14e5147e2181d66ec893a5c9360daa4df1d667e6ee0b6d773e7e8762ebf2c6a |