Skip to content

Commit

Permalink
updated langchain csv and sqlite / sql workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyphantom committed Apr 11, 2023
1 parent 1e1c159 commit b039a4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
13 changes: 8 additions & 5 deletions 3_db.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import os
from dotenv import load_dotenv
from langchain import OpenAI, SQLDatabase
from langchain import SQLDatabaseChain
from langchain import OpenAI, SQLDatabase, SQLDatabaseChain

load_dotenv()

dburi = os.getenv("DATABASE_URL")
# dburi = os.getenv("DATABASE_URL")
dburi = "sqlite:///academy/academy.db"
db = SQLDatabase.from_uri(dburi)
llm = OpenAI(temperature=0)

db_chain = SQLDatabaseChain(llm=llm, database=db, verbose=True)

db_chain.run("How many responses do we have this year?")
db_chain.run("What is the average ratings for Samuel Chan in the responses table?")
db_chain.run("How many rows is in the responses table of this db?")
db_chain.run("Describe the responses table")
db_chain.run("What are the top 3 countries where these responses are from?")
db_chain.run("Give me a summary of how these customers come to hear about us. \
What is the most common way they hear about us?")
18 changes: 18 additions & 0 deletions 4_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dotenv import load_dotenv
from langchain import OpenAI
from langchain.document_loaders.csv_loader import CSVLoader

load_dotenv()

filepath = "academy/academy.csv"
loader = CSVLoader(filepath)
data = loader.load()
print(data)

llm = OpenAI(temperature=0)

from langchain.agents import create_csv_agent
agent = create_csv_agent(llm, filepath, verbose=True)
agent.run("What percentage of the respondents are students versus professionals?")
agent.run("List the top 3 devices that the respondents use to submit their responses")
agent.run("Consider iOS and Android as mobile devices. What is the percentage of respondents that discovered us through social media submitting this from a mobile device?")

0 comments on commit b039a4d

Please sign in to comment.