Spaces:
Sleeping
Sleeping
junlin3
commited on
Commit
·
021d17f
1
Parent(s):
f43e234
fix sys prompt
Browse fileschange default agent to huggingface
- agent.py +24 -21
- requirements.txt +1 -1
- system_prompt.txt +5 -0
agent.py
CHANGED
@@ -127,10 +127,9 @@ def arvix_search(query: str) -> str:
|
|
127 |
return {'arvix_results': formatted_search_docs}
|
128 |
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
|
135 |
|
136 |
# System message
|
@@ -172,7 +171,7 @@ tools = [
|
|
172 |
]
|
173 |
|
174 |
# build graph function
|
175 |
-
def build_graph(tag: str='
|
176 |
"""Build the graph"""
|
177 |
|
178 |
if tag == 'local':
|
@@ -180,14 +179,14 @@ def build_graph(tag: str='google'):
|
|
180 |
elif tag == 'google':
|
181 |
# Google Gemini
|
182 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
endpoint_url=url,
|
188 |
temperature=0,
|
189 |
-
|
190 |
-
|
|
|
191 |
# bind tools to llm
|
192 |
llm_with_tools = llm.bind_tools(tools)
|
193 |
|
@@ -203,15 +202,19 @@ def build_graph(tag: str='google'):
|
|
203 |
|
204 |
builder = StateGraph(MessagesState)
|
205 |
builder.add_node('retriever', retriever)
|
206 |
-
builder.add_node('assistant', assistant)
|
207 |
-
builder.add_node('tools', ToolNode(tools))
|
208 |
-
builder.add_edge(START, 'retriever')
|
209 |
-
builder.add_edge('retriever', 'assistant')
|
210 |
-
builder.add_conditional_edges(
|
211 |
-
|
212 |
-
|
213 |
-
)
|
214 |
-
builder.add_edge('tools', 'assistant')
|
|
|
|
|
|
|
|
|
215 |
return builder.compile()
|
216 |
|
217 |
|
|
|
127 |
return {'arvix_results': formatted_search_docs}
|
128 |
|
129 |
|
130 |
+
# load the system prompt from the file
|
131 |
+
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
132 |
+
system_prompt = f.read()
|
|
|
133 |
|
134 |
|
135 |
# System message
|
|
|
171 |
]
|
172 |
|
173 |
# build graph function
|
174 |
+
def build_graph(tag: str='huggingface'):
|
175 |
"""Build the graph"""
|
176 |
|
177 |
if tag == 'local':
|
|
|
179 |
elif tag == 'google':
|
180 |
# Google Gemini
|
181 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
|
182 |
+
elif tag == "huggingface":
|
183 |
+
llm = ChatHuggingFace(
|
184 |
+
llm=HuggingFaceEndpoint(
|
185 |
+
endpoint_url="https://api-inference.huggingface.co/models/Meta-DeepLearning/llama-2-7b-chat-hf"),
|
|
|
186 |
temperature=0,
|
187 |
+
)
|
188 |
+
else:
|
189 |
+
raise ValueError("Invalid provider. Choose 'google', 'groq' or 'huggingface'.")
|
190 |
# bind tools to llm
|
191 |
llm_with_tools = llm.bind_tools(tools)
|
192 |
|
|
|
202 |
|
203 |
builder = StateGraph(MessagesState)
|
204 |
builder.add_node('retriever', retriever)
|
205 |
+
# builder.add_node('assistant', assistant)
|
206 |
+
# builder.add_node('tools', ToolNode(tools))
|
207 |
+
# builder.add_edge(START, 'retriever')
|
208 |
+
# builder.add_edge('retriever', 'assistant')
|
209 |
+
# builder.add_conditional_edges(
|
210 |
+
# 'assistant',
|
211 |
+
# tools_condition
|
212 |
+
# )
|
213 |
+
# builder.add_edge('tools', 'assistant')
|
214 |
+
|
215 |
+
builder.set_entry_point("retriever")
|
216 |
+
builder.set_finish_point("retriever")
|
217 |
+
|
218 |
return builder.compile()
|
219 |
|
220 |
|
requirements.txt
CHANGED
@@ -10,4 +10,4 @@ faiss-cpu
|
|
10 |
langchain-ollama
|
11 |
langgraph
|
12 |
wikipedia
|
13 |
-
python-dotenv
|
|
|
10 |
langchain-ollama
|
11 |
langgraph
|
12 |
wikipedia
|
13 |
+
python-dotenv
|
system_prompt.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
You are a helpful assistant tasked with answering questions using a set of tools.
|
2 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
3 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
4 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, Apply the rules above for each element (number or string), ensure there is exactly one space after each comma.
|
5 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
|