Spaces:
Sleeping
Sleeping
Create agent.py
Browse files
agent.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import nest_asyncio
|
| 3 |
+
from llama_index.core.agent.workflow import AgentWorkflow
|
| 4 |
+
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
| 5 |
+
from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
|
| 6 |
+
from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool
|
| 7 |
+
|
| 8 |
+
async def smart_agent(question : str, api_key : str) -> str:
|
| 9 |
+
llm = HuggingFaceInferenceAPI(
|
| 10 |
+
model_name="deepseek-ai/DeepSeek-R1-0528",
|
| 11 |
+
token=api_key,
|
| 12 |
+
provider="auto",
|
| 13 |
+
max_iterations=10,
|
| 14 |
+
max_execution_time=60
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Create Alfred, our gala agent, with the guest info tool
|
| 18 |
+
llamaindex_agent = AgentWorkflow.from_tools_or_functions(
|
| 19 |
+
[wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
|
| 20 |
+
llm=llm,
|
| 21 |
+
)
|
| 22 |
+
# Example query Alfred might receive during the gala
|
| 23 |
+
response = await llamaindex_agent.run(question)
|
| 24 |
+
return response
|