Spaces:
Sleeping
Sleeping
Asaad Almutareb
commited on
Commit
•
c536b8c
1
Parent(s):
d6922d4
added a second executor for a search without web tools, e.g. google
Browse files- hf_mixtral_agent.py +21 -4
hf_mixtral_agent.py
CHANGED
@@ -44,13 +44,18 @@ llm = HuggingFaceEndpoint(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
44 |
)
|
45 |
|
46 |
|
47 |
-
|
48 |
arxiv_search,
|
49 |
wikipedia_search,
|
50 |
google_search,
|
51 |
# get_arxiv_paper,
|
52 |
]
|
53 |
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
prompt = hub.pull("hwchase17/react-json")
|
56 |
prompt = prompt.partial(
|
@@ -72,9 +77,20 @@ agent = (
|
|
72 |
)
|
73 |
|
74 |
# instantiate AgentExecutor
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
agent=agent,
|
77 |
-
tools=
|
78 |
verbose=True,
|
79 |
max_iterations=6, # cap number of iterations
|
80 |
#max_execution_time=60, # timout at 60 sec
|
@@ -94,12 +110,13 @@ if __name__ == "__main__":
|
|
94 |
sources = collect_urls(all_sources)
|
95 |
src_list = '\n'.join(sources)
|
96 |
response_w_sources = response['output']+"\n\n\n Sources: \n\n\n"+src_list
|
|
|
97 |
history[-1][1] = response_w_sources
|
98 |
return history
|
99 |
|
100 |
def infer(question, history):
|
101 |
query = question
|
102 |
-
result =
|
103 |
{
|
104 |
"input": question,
|
105 |
}
|
|
|
44 |
)
|
45 |
|
46 |
|
47 |
+
tools_all = [
|
48 |
arxiv_search,
|
49 |
wikipedia_search,
|
50 |
google_search,
|
51 |
# get_arxiv_paper,
|
52 |
]
|
53 |
|
54 |
+
tools_papers = [
|
55 |
+
arxiv_search,
|
56 |
+
wikipedia_search,
|
57 |
+
]
|
58 |
+
|
59 |
|
60 |
prompt = hub.pull("hwchase17/react-json")
|
61 |
prompt = prompt.partial(
|
|
|
77 |
)
|
78 |
|
79 |
# instantiate AgentExecutor
|
80 |
+
agent_executor_all = AgentExecutor(
|
81 |
+
agent=agent,
|
82 |
+
tools=tools_all,
|
83 |
+
verbose=True,
|
84 |
+
max_iterations=6, # cap number of iterations
|
85 |
+
#max_execution_time=60, # timout at 60 sec
|
86 |
+
return_intermediate_steps=True,
|
87 |
+
handle_parsing_errors=True,
|
88 |
+
)
|
89 |
+
|
90 |
+
# instantiate AgentExecutor
|
91 |
+
agent_executor_noweb = AgentExecutor(
|
92 |
agent=agent,
|
93 |
+
tools=tools_papers,
|
94 |
verbose=True,
|
95 |
max_iterations=6, # cap number of iterations
|
96 |
#max_execution_time=60, # timout at 60 sec
|
|
|
110 |
sources = collect_urls(all_sources)
|
111 |
src_list = '\n'.join(sources)
|
112 |
response_w_sources = response['output']+"\n\n\n Sources: \n\n\n"+src_list
|
113 |
+
intermediate_steps = response['intermediate_steps']
|
114 |
history[-1][1] = response_w_sources
|
115 |
return history
|
116 |
|
117 |
def infer(question, history):
|
118 |
query = question
|
119 |
+
result = agent_executor_all.invoke(
|
120 |
{
|
121 |
"input": question,
|
122 |
}
|