Git Product home page Git Product logo

Comments (1)

dosubot avatar dosubot commented on August 16, 2024 2

Hello, @sakoser! I'm here to assist you with any bugs, questions, or contributions you may have while we wait for a human maintainer. Let's squash those bugs together! 🤖

Yes, you can receive an SQL query directly when connecting via the API without using a prompt. The execute_direct_sql_query method in the SQLConnector class allows you to execute an SQL query directly on the data source.

Here is the relevant code snippet:

def execute_direct_sql_query(self, sql_query):
    if not self._is_sql_query_safe(sql_query):
        raise MaliciousQueryError("Malicious query is generated in code")

    return pd.read_sql(sql_query, self._connection)

Additionally, you can configure the Agent to handle direct SQL queries by setting the direct_sql configuration to True. Here is an example using the PandasAI library with a PostgreSQL database:

import os
from pandasai import Agent
from pandasai.connectors import PostgreSQLConnector

# With a PostgreSQL database
order = PostgreSQLConnector(
    config={
        "host": "localhost",
        "port": 5432,
        "database": "testdb",
        "username": "postgres",
        "password": "123456",
        "table": "orders",
    }
)

order_details = PostgreSQLConnector(
    config={
        "host": "localhost",
        "port": 5432,
        "database": "testdb",
        "username": "postgres",
        "password": "123456",
        "table": "order_details",
    }
)

products = PostgreSQLConnector(
    config={
        "host": "localhost",
        "port": 5432,
        "database": "testdb",
        "username": "postgres",
        "password": "123456",
        "table": "products",
    }
)

# By default, unless you choose a different LLM, it will use BambooLLM.
# You can get your free API key signing up at https://pandabi.ai (you can also configure it in your .env file)
os.environ["PANDASAI_API_KEY"] = "your-api-key"

agent = Agent(
    [order, products, order_details],
    config={"direct_sql": True},
)

response = agent.chat("return orders with count of distinct products")
print(response)

This example demonstrates how to set up the Agent to execute direct SQL queries on a PostgreSQL database [1][2][3][4].

To continue talking to Dosu, mention @dosu.

from pandas-ai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.