Spaces:
Runtime error
Runtime error
Commit
·
0209368
1
Parent(s):
8c3956a
update prompt for ai
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ 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.agents import load_tools
|
15 |
from langchain.tools import BaseTool
|
16 |
from langchain.tools import DuckDuckGoSearchRun
|
17 |
from langchain.utilities import WikipediaAPIWrapper
|
@@ -101,11 +101,41 @@ index = pinecone.Index(index_name)
|
|
101 |
# print(pinecone.whoami())
|
102 |
# print(index.describe_index_stats())
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
agent = initialize_agent(tools, llm,
|
106 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
107 |
verbose = True,
|
108 |
-
handle_parsing_errors = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
print(agent.agent.llm_chain.prompt.template)
|
111 |
|
|
|
11 |
from langchain.agents import initialize_agent
|
12 |
from langchain.agents import AgentType
|
13 |
from langchain.agents import Tool
|
14 |
+
# from langchain.agents import load_tools
|
15 |
from langchain.tools import BaseTool
|
16 |
from langchain.tools import DuckDuckGoSearchRun
|
17 |
from langchain.utilities import WikipediaAPIWrapper
|
|
|
101 |
# print(pinecone.whoami())
|
102 |
# print(index.describe_index_stats())
|
103 |
|
104 |
+
PREFIX = """Answer the following questions as best you can. You must always check internal vector database first and try to answer the question based on the information in internal vector database only.
|
105 |
+
Only when there is no information available from vector database, you can search information by using another tools.
|
106 |
+
You have access to the following tools:
|
107 |
+
|
108 |
+
Vector Database Search: This is the internal database to search information firstly. If information is found, it is trustful.
|
109 |
+
Duckduckgo Internet Search: Useful to search information in internet when it is not available in other tools
|
110 |
+
Python REPL: Useful when you need python to answer questions. You should input python code.
|
111 |
+
Calculator: Useful for when you need to answer questions about math."""
|
112 |
+
|
113 |
+
FORMAT_INSTRUCTIONS = """Use the following format:
|
114 |
+
|
115 |
+
Question: the input question you must answer
|
116 |
+
Thought: you should always think about what to do
|
117 |
+
Action: the action to take, should be one of [Vector Database Search, Duckduckgo Internet Search, Python REPL, Calculator]
|
118 |
+
Action Input: the input to the action
|
119 |
+
Observation: the result of the action
|
120 |
+
... (this Thought/Action/Action Input/Observation can repeat N times)
|
121 |
+
Thought: I now know the final answer
|
122 |
+
Final Answer: the final answer to the original input question"""
|
123 |
+
|
124 |
+
SUFFIX = """Begin!
|
125 |
+
Question: {input}
|
126 |
+
Thought:{agent_scratchpad}"""
|
127 |
|
128 |
agent = initialize_agent(tools, llm,
|
129 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
130 |
verbose = True,
|
131 |
+
handle_parsing_errors = True,
|
132 |
+
max_iterations = 3,
|
133 |
+
agent_kwargs={
|
134 |
+
'prefix': PREFIX,
|
135 |
+
'format_instructions': FORMAT_INSTRUCTIONS,
|
136 |
+
'suffix': SUFFIX
|
137 |
+
}
|
138 |
+
)
|
139 |
|
140 |
print(agent.agent.llm_chain.prompt.template)
|
141 |
|