omlakhani commited on
Commit
e649211
1 Parent(s): 6b21961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -8,8 +8,9 @@ import s3fs
8
  load_dotenv('myenvfile.env')
9
 
10
  openai_api_key = os.environ['OPENAI_API_KEY']
11
- aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
12
- aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY']
 
13
  from llama_index import GPTListIndex, GPTSimpleVectorIndex
14
  from langchain.agents import load_tools, Tool, initialize_agent
15
  from langchain.llms import OpenAI
@@ -18,37 +19,30 @@ from langchain.agents import initialize_agent, Tool
18
  from langchain import OpenAI, LLMChain
19
  from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader
20
 
21
-
22
-
23
  index = GPTSimpleVectorIndex.load_from_disk('index.json')
24
 
25
-
26
  def querying_db(query: str):
27
- response = index.query(query)
28
- return response
29
-
30
 
31
  tools = [
32
- Tool(
33
- name="QueryingDB",
34
- func=querying_db,
35
- description="This function takes a query string as input and returns the most relevant answer from the documentation as output"
36
- )
37
  ]
38
 
39
  llm = OpenAI(temperature=0)
40
 
41
-
42
  def get_answer(query_string):
43
- agent = initialize_agent(tools, llm, agent="zero-shot-react-description")
44
- result = agent.run(query_string)
45
- return result
46
-
47
 
48
  def qa_app(query):
49
- answer = get_answer(query)
50
- return answer
51
-
52
 
53
  inputs = gr.inputs.Textbox(label="Enter your question:")
54
  output = gr.outputs.Textbox(label="Answer:")
 
8
  load_dotenv('myenvfile.env')
9
 
10
  openai_api_key = os.environ['OPENAI_API_KEY']
11
+ aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID']
12
+ aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY']
13
+
14
  from llama_index import GPTListIndex, GPTSimpleVectorIndex
15
  from langchain.agents import load_tools, Tool, initialize_agent
16
  from langchain.llms import OpenAI
 
19
  from langchain import OpenAI, LLMChain
20
  from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader
21
 
 
 
22
  index = GPTSimpleVectorIndex.load_from_disk('index.json')
23
 
 
24
  def querying_db(query: str):
25
+ response = index.query(query)
26
+ return response
 
27
 
28
  tools = [
29
+ Tool(
30
+ name="QueryingDB",
31
+ func=querying_db,
32
+ description="This function takes a query string as input and returns the most relevant answer from the documentation as output"
33
+ )
34
  ]
35
 
36
  llm = OpenAI(temperature=0)
37
 
 
38
  def get_answer(query_string):
39
+ agent = initialize_agent(tools, llm, agent="zero-shot-react-description")
40
+ result = agent.run(query_string)
41
+ return result
 
42
 
43
  def qa_app(query):
44
+ answer = get_answer(query)
45
+ return answer
 
46
 
47
  inputs = gr.inputs.Textbox(label="Enter your question:")
48
  output = gr.outputs.Textbox(label="Answer:")