Markiian Tsalyk
commited on
Commit
·
36a7313
1
Parent(s):
fc21e56
upd
Browse files- llama_index_agent.py +4 -11
- tools.py +8 -1
llama_index_agent.py
CHANGED
@@ -17,7 +17,8 @@ class LlamaIndexAgent:
|
|
17 |
# model_name: str = "meta-llama/llama-4-maverick:free",
|
18 |
# model_name: str = "meta-llama/llama-4-scout:free",
|
19 |
# model_name: str = "microsoft/phi-4-reasoning-plus:free",
|
20 |
-
model_name: str = "google/gemini-2.5-flash-preview",
|
|
|
21 |
temperature: float = 0.7,
|
22 |
verbose: bool = True,
|
23 |
):
|
@@ -132,14 +133,6 @@ class LlamaIndexAgent:
|
|
132 |
""",
|
133 |
)
|
134 |
|
135 |
-
self.small_agent = ReActAgent.from_tools(
|
136 |
-
[final_answer_tool],
|
137 |
-
llm=self.llm,
|
138 |
-
verbose=verbose,
|
139 |
-
max_iterations=5,
|
140 |
-
system_prompt="You are approached to prepare answer for the user question in desired format. You always need to use final_answer tool, it will help you.",
|
141 |
-
)
|
142 |
-
|
143 |
def __call__(self, query_text: str, **kwds) -> str:
|
144 |
"""
|
145 |
Process a user query through the agent.
|
@@ -154,9 +147,9 @@ class LlamaIndexAgent:
|
|
154 |
response = self.agent.chat(query_text).response
|
155 |
except:
|
156 |
response = ""
|
157 |
-
final_response =
|
158 |
|
159 |
-
return final_response
|
160 |
|
161 |
|
162 |
if __name__ == "__main__":
|
|
|
17 |
# model_name: str = "meta-llama/llama-4-maverick:free",
|
18 |
# model_name: str = "meta-llama/llama-4-scout:free",
|
19 |
# model_name: str = "microsoft/phi-4-reasoning-plus:free",
|
20 |
+
# model_name: str = "google/gemini-2.5-flash-preview",
|
21 |
+
model_name: str = "x-ai/grok-3-beta",
|
22 |
temperature: float = 0.7,
|
23 |
verbose: bool = True,
|
24 |
):
|
|
|
133 |
""",
|
134 |
)
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
def __call__(self, query_text: str, **kwds) -> str:
|
137 |
"""
|
138 |
Process a user query through the agent.
|
|
|
147 |
response = self.agent.chat(query_text).response
|
148 |
except:
|
149 |
response = ""
|
150 |
+
final_response = tools.final_answer(answer=response)
|
151 |
|
152 |
+
return final_response
|
153 |
|
154 |
|
155 |
if __name__ == "__main__":
|
tools.py
CHANGED
@@ -309,7 +309,10 @@ def final_answer(answer: str, **kwargs) -> str:
|
|
309 |
Return:
|
310 |
The final answer.
|
311 |
"""
|
312 |
-
|
|
|
|
|
|
|
313 |
Final answer from agent: {answer}
|
314 |
Make final answer as short as possible.
|
315 |
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 above rules depending of whether the element to be put in the list is a number or a string.
|
@@ -317,6 +320,10 @@ def final_answer(answer: str, **kwargs) -> str:
|
|
317 |
And on the other hand, the question might request some exact string value. Don't explain it, just return this value (For example, insted of `In response to the question, desired person is X` return only `X`)
|
318 |
Again, you don't need to modify or solve answer, you just need to format it properly.
|
319 |
"""
|
|
|
|
|
|
|
|
|
320 |
|
321 |
|
322 |
# print(wikipedia_search("Mercedes Sosa studio albums"))
|
|
|
309 |
Return:
|
310 |
The final answer.
|
311 |
"""
|
312 |
+
resp = llm.chat(
|
313 |
+
messages=[
|
314 |
+
ChatMessage(
|
315 |
+
content=f"""
|
316 |
Final answer from agent: {answer}
|
317 |
Make final answer as short as possible.
|
318 |
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 above rules depending of whether the element to be put in the list is a number or a string.
|
|
|
320 |
And on the other hand, the question might request some exact string value. Don't explain it, just return this value (For example, insted of `In response to the question, desired person is X` return only `X`)
|
321 |
Again, you don't need to modify or solve answer, you just need to format it properly.
|
322 |
"""
|
323 |
+
)
|
324 |
+
]
|
325 |
+
)
|
326 |
+
return resp.message.content
|
327 |
|
328 |
|
329 |
# print(wikipedia_search("Mercedes Sosa studio albums"))
|