Skip to main content

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

Execution code

llm = ChatOpenAI(
            openai_api_key=OPENAI_API_KEY,
            model_name='gpt-4o-mini',
            temperature=0.0
        )

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

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: plotly_agent-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 a14349751e5904c5d233bb88cb8cce41652a54e86f4d6cc094526a04fff64fda
MD5 40250408c968f586c12bfe49ffdcd4b1
BLAKE2b-256 cf417d4d8f7c598bcaff13f22e43334454dd80f6f23f29483bbf566cc2acf023

See more details on using hashes here.

File details

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

File metadata

  • Download URL: plotly_agent-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 abca0ff43cec33235e7ff0b45d344f595697de018fe985cf363a28fa476e70ee
MD5 54957ee8460035d367b09af5423a6628
BLAKE2b-256 d3b8ebafa34e41f3d1096a1d483b8f8b8cf94e17bb8f8afb6b074b04f59ace8a

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