Skip to main content

Visualize your data with Langchain and Plotly through a Plotly agent

Reason this release was yanked:

this version is deprecated, install plotly-agent >= 0.1.4 instead

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

Execution code

# judge if a input deserve a data visualization
judgment = judge(text=prompt, openai_api_key=OPENAI_API_KEY)

if judgment:
        llm = ChatOpenAI(
            openai_api_key=OPENAI_API_KEY,
            # gpt-4-turbo had a better perform than gpt-4o and gpt-4o-mini
            model_name='gpt-4-turbo',
            temperature=0.0
        )

        plotly_agent = create_plotly_agent(llm=llm, max_interations=8, verbose=True)
        plotly_response = plotly_agent.invoke({'input': prompt})
        
        # Get python code from llm reponse
        fig_code = extract_python_code(plotly_response['output'])
        fig_dict = {"fig": Figure}
        exec(fig_code, fig_dict)
        
        # Returns a plottable figure
        fig = fig_dict.get("fig", None)

Project details


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.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

plotly_agent-0.1.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file plotly_agent-0.1.3.tar.gz.

File metadata

  • Download URL: plotly_agent-0.1.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/11

File hashes

Hashes for plotly_agent-0.1.3.tar.gz
Algorithm Hash digest
SHA256 220c58ee8bf8b81190953279b9844243b0a41c3554f8c00b01254159a0b59851
MD5 f14c02f78561ce76f785cf710287c544
BLAKE2b-256 6e7f97552666b8924b35c608d69ca52be3a656fbf19b70ecb9edcf5190d01143

See more details on using hashes here.

File details

Details for the file plotly_agent-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: plotly_agent-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/11

File hashes

Hashes for plotly_agent-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b76ae8d406f606967576728f4a54f012fcec0f0c3da930ff4d8f5280088bf41f
MD5 819d79dbfd7a1b7c3aa6f6576299eedd
BLAKE2b-256 44e4b689e8ad341edb7f4ef8705237f390ee4ad672182b773fb0b6ddcf93aa0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page