Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -3,7 +3,7 @@ from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
|
| 3 |
|
| 4 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 5 |
from langchain_community.document_loaders import WikipediaLoader
|
| 6 |
-
from llama_index.core.
|
| 7 |
from llama_index.core.schema import Document
|
| 8 |
from llama_index.core.tools import FunctionTool
|
| 9 |
from langchain_core.tools import tool
|
|
@@ -12,10 +12,6 @@ from llama_index.core.agent.workflow import AgentWorkflow
|
|
| 12 |
|
| 13 |
llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-VL-32B-Instruct")
|
| 14 |
|
| 15 |
-
class ToolMetadata(Metadata):
|
| 16 |
-
name: str
|
| 17 |
-
description: str
|
| 18 |
-
|
| 19 |
@tool
|
| 20 |
def web_search(query: str) -> list:
|
| 21 |
"""Search Tavily for a query and return a maximum 3 results as LlamaIndex Documents.
|
|
@@ -62,8 +58,9 @@ def wiki_search(query: str) -> list:
|
|
| 62 |
|
| 63 |
return llama_docs
|
| 64 |
|
|
|
|
| 65 |
web_search = FunctionTool(
|
| 66 |
-
web_search,
|
| 67 |
metadata=ToolMetadata(name="web_search", description="Tavily 3-hit search")
|
| 68 |
)
|
| 69 |
|
|
@@ -71,6 +68,7 @@ wiki_search = FunctionTool(
|
|
| 71 |
wiki_search,
|
| 72 |
metadata=ToolMetadata(name="wiki_search", description="Wikipedia 2-hit search")
|
| 73 |
)
|
|
|
|
| 74 |
tools = [web_search, wiki_search]
|
| 75 |
|
| 76 |
agent = AgentWorkflow.from_tools_or_functions(tools, llm=llm)
|
|
|
|
| 3 |
|
| 4 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 5 |
from langchain_community.document_loaders import WikipediaLoader
|
| 6 |
+
from llama_index.core.tools.types import ToolMetadata
|
| 7 |
from llama_index.core.schema import Document
|
| 8 |
from llama_index.core.tools import FunctionTool
|
| 9 |
from langchain_core.tools import tool
|
|
|
|
| 12 |
|
| 13 |
llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-VL-32B-Instruct")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
@tool
|
| 16 |
def web_search(query: str) -> list:
|
| 17 |
"""Search Tavily for a query and return a maximum 3 results as LlamaIndex Documents.
|
|
|
|
| 58 |
|
| 59 |
return llama_docs
|
| 60 |
|
| 61 |
+
|
| 62 |
web_search = FunctionTool(
|
| 63 |
+
web_search,
|
| 64 |
metadata=ToolMetadata(name="web_search", description="Tavily 3-hit search")
|
| 65 |
)
|
| 66 |
|
|
|
|
| 68 |
wiki_search,
|
| 69 |
metadata=ToolMetadata(name="wiki_search", description="Wikipedia 2-hit search")
|
| 70 |
)
|
| 71 |
+
|
| 72 |
tools = [web_search, wiki_search]
|
| 73 |
|
| 74 |
agent = AgentWorkflow.from_tools_or_functions(tools, llm=llm)
|