Spaces:
Sleeping
Sleeping
HermanDragesund commited on
Commit ·
b7d144f
1
Parent(s): 81917a3
Add agent with multiple tools
Browse files
app.py
CHANGED
|
@@ -3,6 +3,16 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -10,8 +20,15 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from llama_index.core.schema import Document
|
| 7 |
+
from llama_index.core.tools import FunctionTool
|
| 8 |
+
from llama_index.retrievers.bm25 import BM25Retriever
|
| 9 |
+
from llama_index.core.agent.workflow import AgentWorkflow
|
| 10 |
+
from llama_index.llms.openai import OpenAI
|
| 11 |
+
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
|
| 12 |
+
from llama_index.core.tools import FunctionTool
|
| 13 |
+
from huggingface_hub import list_models
|
| 14 |
+
import random
|
| 15 |
+
import asyncio
|
| 16 |
|
| 17 |
# (Keep Constants as is)
|
| 18 |
# --- Constants ---
|
|
|
|
| 20 |
|
| 21 |
# --- Basic Agent Definition ---
|
| 22 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 23 |
+
|
| 24 |
+
|
| 25 |
class BasicAgent:
|
| 26 |
def __init__(self):
|
| 27 |
+
llm = OpenAI(model="gpt-3.5-turbo", api_key="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")
|
| 28 |
+
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 29 |
+
[search_tool],
|
| 30 |
+
llm=llm,
|
| 31 |
+
)
|
| 32 |
print("BasicAgent initialized.")
|
| 33 |
def __call__(self, question: str) -> str:
|
| 34 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|