OuroborosM commited on
Commit
fbb9428
·
1 Parent(s): ba05602

introduce agent

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import openai
2
  import os
3
  from langchain.vectorstores import Chroma
@@ -7,11 +8,30 @@ from langchain.chat_models import AzureChatOpenAI
7
  from langchain.document_loaders import DirectoryLoader
8
  from langchain.chains import RetrievalQA
9
  from langchain.vectorstores import Pinecone
 
 
 
 
 
10
  import pinecone
11
  from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
12
  import gradio as gr
13
  import time
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  os.environ["OPENAI_API_TYPE"] = "azure"
16
  os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
17
  os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE")
@@ -37,7 +57,9 @@ index = pinecone.Index(index_name)
37
  # print(pinecone.whoami())
38
  # print(index.describe_index_stats())
39
 
40
-
 
 
41
 
42
  global vectordb
43
  vectordb = Chroma(persist_directory='db', embedding_function=embeddings)
@@ -68,7 +90,7 @@ def chathmi(message, history):
68
  # yield history
69
 
70
  def chathmi2(message, history):
71
- response = QAQuery(message)
72
  time.sleep(0.3)
73
  print(history)
74
  yield response
@@ -77,7 +99,7 @@ def chathmi2(message, history):
77
  # chatbot = gr.Chatbot(color_map =("blue", "pink"))
78
 
79
  demo = gr.ChatInterface(
80
- chathmi,
81
  title="STLA BABY - YOUR FRIENDLY GUIDE ",
82
  description= "v0.2: Powered by MECH Core Team",
83
  )
 
1
+ from typing import Any, Coroutine
2
  import openai
3
  import os
4
  from langchain.vectorstores import Chroma
 
8
  from langchain.document_loaders import DirectoryLoader
9
  from langchain.chains import RetrievalQA
10
  from langchain.vectorstores import Pinecone
11
+ from langchain.agents import initialize_agent
12
+ from langchain.agents import AgentType
13
+ from langchain.agents import tool
14
+ from langchain.tools import BaseTool
15
+
16
  import pinecone
17
  from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
18
  import gradio as gr
19
  import time
20
 
21
+ class DB_Search(BaseTool):
22
+ name = "Vector Databse Search"
23
+ description = "This is the vector database to search local information"
24
+ def _run(self, message: str) -> Any:
25
+ response, source = QAQuery_p(message)
26
+ return response
27
+
28
+ def _arun(self, query: str):
29
+ raise NotImplementedError("N/A")
30
+
31
+ tools = [DB_Search()]
32
+
33
+
34
+
35
  os.environ["OPENAI_API_TYPE"] = "azure"
36
  os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
37
  os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE")
 
57
  # print(pinecone.whoami())
58
  # print(index.describe_index_stats())
59
 
60
+ agent = initialize_agent(tools, chat,
61
+ agent="zero-shot-react-description",
62
+ verbose = True)
63
 
64
  global vectordb
65
  vectordb = Chroma(persist_directory='db', embedding_function=embeddings)
 
90
  # yield history
91
 
92
  def chathmi2(message, history):
93
+ response = agent(message)
94
  time.sleep(0.3)
95
  print(history)
96
  yield response
 
99
  # chatbot = gr.Chatbot(color_map =("blue", "pink"))
100
 
101
  demo = gr.ChatInterface(
102
+ chathmi2,
103
  title="STLA BABY - YOUR FRIENDLY GUIDE ",
104
  description= "v0.2: Powered by MECH Core Team",
105
  )