forked from onlyphantom/llm-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated langchain csv and sqlite / sql workflow
- Loading branch information
1 parent
1e1c159
commit b039a4d
Showing
2 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?") |