Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -179,24 +179,53 @@ class VideoTranscriptionTool(Tool):
|
|
179 |
except Exception as e:
|
180 |
return f"Error in extracting YouTube transcript: {str(e)}"
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
class BasicAgent:
|
183 |
def __init__(self):
|
184 |
token = os.environ.get("HF_API_TOKEN")
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
200 |
You are my general AI assistant. Your task is to answer the question I asked.
|
201 |
First, provide an explanation of your reasoning, step by step, to arrive at the answer.
|
202 |
Then, return your final answer in a single line, formatted as follows: "FINAL ANSWER: [YOUR FINAL ANSWER]".
|
@@ -205,12 +234,20 @@ If the answer is a number, do not use commas or units (e.g., $, %) unless specif
|
|
205 |
If the answer is a string, do not use articles or abbreviations (e.g., for cities), and write digits in plain text unless specified.
|
206 |
If the answer is a comma-separated list, apply the above rules for each element based on whether it is a number or a string.
|
207 |
"""
|
|
|
|
|
208 |
self.agent = CodeAgent(
|
209 |
-
model=
|
210 |
-
tools=
|
211 |
add_base_tools=True
|
212 |
)
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
def __call__(self, question: str) -> str:
|
216 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
179 |
except Exception as e:
|
180 |
return f"Error in extracting YouTube transcript: {str(e)}"
|
181 |
|
182 |
+
|
183 |
+
class HFModelWrapper:
|
184 |
+
def __init__(self, model_id: str, token: str, temperature: float = 0.1):
|
185 |
+
self.api_url = f"https://api-inference.huggingface.co/models/{model_id}"
|
186 |
+
self.headers = {
|
187 |
+
"Authorization": f"Bearer {token}",
|
188 |
+
"Content-Type": "application/json"
|
189 |
+
}
|
190 |
+
self.temperature = temperature
|
191 |
+
|
192 |
+
def __call__(self, prompt: str) -> str:
|
193 |
+
payload = {
|
194 |
+
"inputs": prompt,
|
195 |
+
"parameters": {
|
196 |
+
"temperature": self.temperature,
|
197 |
+
"max_new_tokens": 512,
|
198 |
+
"return_full_text": False
|
199 |
+
}
|
200 |
+
}
|
201 |
+
response = requests.post(self.api_url, headers=self.headers, json=payload)
|
202 |
+
if response.status_code == 200:
|
203 |
+
return response.json()[0]["generated_text"]
|
204 |
+
else:
|
205 |
+
raise RuntimeError(f"Hugging Face API error: {response.status_code} - {response.text}")
|
206 |
+
|
207 |
+
|
208 |
class BasicAgent:
|
209 |
def __init__(self):
|
210 |
token = os.environ.get("HF_API_TOKEN")
|
211 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
212 |
+
model = HFModelWrapper(model_id=model_id, token=token)
|
213 |
+
|
214 |
+
# Tool initialization
|
215 |
+
tools = [
|
216 |
+
DuckDuckGoSearchTool(),
|
217 |
+
WikiSearchTool(),
|
218 |
+
StringReverseTool(),
|
219 |
+
KeywordsExtractorTool(),
|
220 |
+
SpeechToTextTool(),
|
221 |
+
VisitWebpageTool(),
|
222 |
+
FinalAnswerTool(),
|
223 |
+
parse_excel_to_json,
|
224 |
+
VideoTranscriptionTool()
|
225 |
+
]
|
226 |
+
|
227 |
+
# Custom system prompt
|
228 |
+
system_prompt = """
|
229 |
You are my general AI assistant. Your task is to answer the question I asked.
|
230 |
First, provide an explanation of your reasoning, step by step, to arrive at the answer.
|
231 |
Then, return your final answer in a single line, formatted as follows: "FINAL ANSWER: [YOUR FINAL ANSWER]".
|
|
|
234 |
If the answer is a string, do not use articles or abbreviations (e.g., for cities), and write digits in plain text unless specified.
|
235 |
If the answer is a comma-separated list, apply the above rules for each element based on whether it is a number or a string.
|
236 |
"""
|
237 |
+
|
238 |
+
# Instantiate CodeAgent with wrapped model
|
239 |
self.agent = CodeAgent(
|
240 |
+
model=model,
|
241 |
+
tools=tools,
|
242 |
add_base_tools=True
|
243 |
)
|
244 |
+
|
245 |
+
# Add system prompt safely
|
246 |
+
if "system_prompt" in self.agent.prompt_templates:
|
247 |
+
self.agent.prompt_templates["system_prompt"] += system_prompt
|
248 |
+
else:
|
249 |
+
self.agent.prompt_templates["system_prompt"] = system_prompt
|
250 |
+
|
251 |
|
252 |
def __call__(self, question: str) -> str:
|
253 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|