Sborole commited on
Commit
cf59801
·
verified ·
1 Parent(s): d684283

Update tools/FinalAnswerTool

Browse files
Files changed (1) hide show
  1. tools/FinalAnswerTool +17 -39
tools/FinalAnswerTool CHANGED
@@ -1,42 +1,20 @@
1
  from smolagents import LiteLLMModel
2
- from settings import settings
3
- from utils import InputTokenRateLimiter
 
 
 
4
 
5
- class FinalAnswerTool:
6
- def __init__(self):
7
- self.model = LiteLLMModel(
8
- model_id=settings.llm_model_id,
9
- api_key=settings.llm_api_key,
10
- temperature=0.1,
11
- max_tokens=20,
12
- )
13
- self.token_rate_limiter = InputTokenRateLimiter()
14
- self.expected_tokens_per_step = 10000
15
 
16
-
17
- def forward(self):
18
- self.token_rate_limiter.maybe_wait(self.expected_tokens_per_step)
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