-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (40 loc) · 1.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from dotenv import load_dotenv
import os
import pandas as pd
from llama_index.query_engine import PandasQueryEngine
from prompts import new_prompt, instruction_str, context
from note_engine import note_engine
from llama_index.tools import QueryEngineTool, ToolMetadata
from llama_index.agent import ReActAgent
from llama_index.llms import OpenAI
from pdf import canada_engine
load_dotenv()
os.environ['OPENAI_API_KEY'] = "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"
population_path = os.path.join("data", "population.csv")
population_df = pd.read_csv(population_path)
population_query_engine = PandasQueryEngine(
df=population_df, verbose=True, instruction_str=instruction_str
)
population_query_engine.update_prompts({"pandas_prompt": new_prompt})
tools = [
note_engine,
QueryEngineTool(
query_engine=population_query_engine,
metadata=ToolMetadata(
name="population_data",
description="this gives information at the world population and demographics",
),
),
QueryEngineTool(
query_engine=canada_engine,
metadata=ToolMetadata(
name="canada_data",
description="this gives detailed information about canada the country",
),
),
]
llm = OpenAI(model="gpt-3.5-turbo-0613")
agent = ReActAgent.from_tools(tools, llm=llm, verbose=True, context=context)
while (prompt := input("Enter a prompt (q to quit): ")) != "q":
result = agent.query(prompt)
print(result)