Spaces:
Paused
Paused
File size: 2,085 Bytes
bc36919 c3b999b bc36919 2cd7c87 bc36919 2cd7c87 bc36919 2cd7c87 bc36919 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | from fastapi import FastAPI
from pydantic import BaseModel
from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.yfinance import YFinanceTools
# from phi.tools.duckduckgo import DuckDuckGo
# google search
from phi.tools.googlesearch import GoogleSearch
import os
from dotenv import load_dotenv
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Load environment variables
load_dotenv()
gorq_api_key = os.getenv("GROQ_API_KEY")
# Initialize FastAPI app
app = FastAPI()
# Define input schema
class QueryRequest(BaseModel):
input_text: str
# Web Search Agent
web_search_agent = Agent(
name="Web Search Agent",
role="Search the web for the information",
model=Groq(id="Deepseek-R1-Distill-Llama-70b", api_key=gorq_api_key),
tools=[GoogleSearch()],
instructions=["Always include sources"],
show_tools_calls=True,
markdown=True,
)
# Financial Agent
finance_agent = Agent(
name="Finance AI Agent",
model=Groq(
id="Deepseek-R1-Distill-Llama-70b",
api_key=gorq_api_key,
role="Get financial data",
),
tools=[
YFinanceTools(
stock_price=True,
analyst_recommendations=True,
stock_fundamentals=True,
company_news=True,
company_info=True,
historical_prices=True
),
],
instructions=["Use tables to display the data"],
show_tool_calls=True,
markdown=True,
)
# Multi-Agent
multi_ai_agent = Agent(
model=Groq(id="Deepseek-R1-Distill-Llama-70b", api_key=gorq_api_key),
team=[web_search_agent, finance_agent],
instructions=["Always include sources", "Use tables to display the data"],
show_tool_calls=True,
markdown=True,
)
@app.post("/query")
async def process_query(request: QueryRequest):
try:
response = multi_ai_agent.run(request.input_text)
return {"response": response}
except Exception as e:
logger.error(f"Error processing query: {e}")
return {"error": f"An error occurred: {str(e)}"}
|