Spaces:
Sleeping
Sleeping
Update tools/FinalAnswerTool
Browse files- tools/FinalAnswerTool +17 -39
tools/FinalAnswerTool
CHANGED
|
@@ -1,42 +1,20 @@
|
|
| 1 |
from smolagents import LiteLLMModel
|
| 2 |
-
from settings import
|
| 3 |
-
from utils import InputTokenRateLimiter
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
self.expected_tokens_per_step = 10000
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
response = self.model.generate(
|
| 20 |
-
[
|
| 21 |
-
{ "role": "system",
|
| 22 |
-
"content": [
|
| 23 |
-
{
|
| 24 |
-
"type": "text",
|
| 25 |
-
"text": (
|
| 26 |
-
"You are an assistant that answers questions with exactly one word. "
|
| 27 |
-
"Always choose the most direct, unambiguous word. "
|
| 28 |
-
"Do NOT use sentences. If the answer is unknown or invalid, respond 'N/A'."
|
| 29 |
-
),
|
| 30 |
-
}
|
| 31 |
-
],
|
| 32 |
-
},
|
| 33 |
-
{
|
| 34 |
-
"role": "user",
|
| 35 |
-
"content": "Generate a final answer to the question given the context provided. Only use the context to provide the final answer. Do not provide any additional thinking or commentary in the response, the final answer only.",
|
| 36 |
-
}
|
| 37 |
-
]
|
| 38 |
-
)
|
| 39 |
-
tokens_used = getattr(response, "token_usage", None)
|
| 40 |
-
if tokens_used:
|
| 41 |
-
self.token_rate_limiter.add_tokens(tokens_used.input_tokens)
|
| 42 |
-
return response.content
|
|
|
|
| 1 |
from smolagents import LiteLLMModel
|
| 2 |
+
from src.settings import Settings
|
| 3 |
+
from src.utils import InputTokenRateLimiter
|
| 4 |
+
from smolagents.tools import Tool
|
| 5 |
+
from litellm import completion
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
+
settings = Settings()
|
| 9 |
+
print(settings.llm_model_id)
|
| 10 |
+
class FinalAnswerTool(Tool):
|
| 11 |
+
name = "final_answer"
|
| 12 |
+
description = "Provides the exact, final answer to the given question."
|
| 13 |
+
inputs = {
|
| 14 |
+
"answer": {"type": "string", "description": "The final, correctly formatted answer string."},
|
| 15 |
+
}
|
| 16 |
+
output_type = "string"
|
|
|
|
| 17 |
|
| 18 |
+
def forward(self, answer: str) -> str:
|
| 19 |
+
final_answer = f"FINAL ANSWER: {answer}"
|
| 20 |
+
return final_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|