Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- agent.py +9 -32
- requirements.txt +0 -5
agent.py
CHANGED
@@ -19,23 +19,24 @@ from langchain_core.tools import tool
|
|
19 |
from langchain.tools.retriever import create_retriever_tool
|
20 |
from langchain_openai import ChatOpenAI
|
21 |
from langchain_anthropic import ChatAnthropic
|
22 |
-
|
23 |
from supabase.client import Client, create_client
|
24 |
-
|
25 |
-
|
26 |
import re
|
27 |
from langchain_community.document_loaders import WikipediaLoader
|
|
|
|
|
|
|
|
|
28 |
from langchain_core.tools import tool
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
|
31 |
-
from langchain_core.tools import tool
|
32 |
-
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
33 |
|
34 |
-
from langchain_core.tools import tool
|
35 |
-
from transformers import pipeline
|
36 |
|
37 |
|
38 |
-
import sys
|
39 |
|
40 |
# Before invoking your graph:
|
41 |
sys.setrecursionlimit(100) # Increase from default 25
|
@@ -173,7 +174,6 @@ def filtered_wiki_search(query: str, start_year: int = None, end_year: int = Non
|
|
173 |
@tool
|
174 |
def wolfram_alpha_query(query: str) -> str:
|
175 |
"""Query Wolfram Alpha with the given question and return the result."""
|
176 |
-
import wolframalpha
|
177 |
client = wolframalpha.Client(os.environ['WOLFRAM_APP_ID'])
|
178 |
res = client.query(query)
|
179 |
try:
|
@@ -199,25 +199,6 @@ def youtube_transcript(url: str) -> str:
|
|
199 |
|
200 |
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-mul-en")
|
205 |
-
|
206 |
-
@tool
|
207 |
-
def translate_to_english(text: str) -> str:
|
208 |
-
"""Translate input text in any language to English."""
|
209 |
-
try:
|
210 |
-
# HuggingFace translation expects a list of strings
|
211 |
-
translated = translator(text, max_length=512)
|
212 |
-
return translated[0]['translation_text']
|
213 |
-
except Exception as e:
|
214 |
-
return f"Translation error: {str(e)}"
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
from langchain_core.tools import tool
|
219 |
-
import sympy
|
220 |
-
|
221 |
@tool
|
222 |
def solve_algebraic_expression(expression: str) -> str:
|
223 |
"""Solve or simplify the given algebraic expression."""
|
@@ -229,7 +210,6 @@ def solve_algebraic_expression(expression: str) -> str:
|
|
229 |
return f"Error solving expression: {str(e)}"
|
230 |
|
231 |
|
232 |
-
from langchain_core.tools import tool
|
233 |
|
234 |
@tool
|
235 |
def run_python_code(code: str) -> str:
|
@@ -245,8 +225,6 @@ def run_python_code(code: str) -> str:
|
|
245 |
return f"Error executing code: {str(e)}"
|
246 |
|
247 |
|
248 |
-
from langchain_core.tools import tool
|
249 |
-
import requests
|
250 |
|
251 |
@tool
|
252 |
def wikidata_query(sparql_query: str) -> str:
|
@@ -305,7 +283,6 @@ tools = [
|
|
305 |
wolfram_alpha_query,
|
306 |
retriever_tool,
|
307 |
youtube_transcript,
|
308 |
-
translate_to_english,
|
309 |
solve_algebraic_expression,
|
310 |
run_python_code,
|
311 |
wikidata_query
|
|
|
19 |
from langchain.tools.retriever import create_retriever_tool
|
20 |
from langchain_openai import ChatOpenAI
|
21 |
from langchain_anthropic import ChatAnthropic
|
|
|
22 |
from supabase.client import Client, create_client
|
|
|
|
|
23 |
import re
|
24 |
from langchain_community.document_loaders import WikipediaLoader
|
25 |
+
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
26 |
+
import sympy
|
27 |
+
import wolframalpha
|
28 |
+
import sys
|
29 |
from langchain_core.tools import tool
|
30 |
+
import requests
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
|
36 |
|
|
|
|
|
37 |
|
|
|
|
|
38 |
|
39 |
|
|
|
40 |
|
41 |
# Before invoking your graph:
|
42 |
sys.setrecursionlimit(100) # Increase from default 25
|
|
|
174 |
@tool
|
175 |
def wolfram_alpha_query(query: str) -> str:
|
176 |
"""Query Wolfram Alpha with the given question and return the result."""
|
|
|
177 |
client = wolframalpha.Client(os.environ['WOLFRAM_APP_ID'])
|
178 |
res = client.query(query)
|
179 |
try:
|
|
|
199 |
|
200 |
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
@tool
|
203 |
def solve_algebraic_expression(expression: str) -> str:
|
204 |
"""Solve or simplify the given algebraic expression."""
|
|
|
210 |
return f"Error solving expression: {str(e)}"
|
211 |
|
212 |
|
|
|
213 |
|
214 |
@tool
|
215 |
def run_python_code(code: str) -> str:
|
|
|
225 |
return f"Error executing code: {str(e)}"
|
226 |
|
227 |
|
|
|
|
|
228 |
|
229 |
@tool
|
230 |
def wikidata_query(sparql_query: str) -> str:
|
|
|
283 |
wolfram_alpha_query,
|
284 |
retriever_tool,
|
285 |
youtube_transcript,
|
|
|
286 |
solve_algebraic_expression,
|
287 |
run_python_code,
|
288 |
wikidata_query
|
requirements.txt
CHANGED
@@ -24,8 +24,3 @@ youtube-transcript-api
|
|
24 |
sympy
|
25 |
sentencepiece
|
26 |
wolframalpha
|
27 |
-
|
28 |
-
transformers>=4.30.0
|
29 |
-
sentence-transformers>=2.2.2
|
30 |
-
codecarbon
|
31 |
-
torch
|
|
|
24 |
sympy
|
25 |
sentencepiece
|
26 |
wolframalpha
|
|
|
|
|
|
|
|
|
|