Upload 4 files
Browse files- .env +2 -0
- Dockerfile +22 -0
- main.py +73 -0
- requirements.txt +9 -0
.env
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PHI_API_KEY=""
|
| 2 |
+
GROQ_API_KEY=""
|
Dockerfile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use the official Python image
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy files
|
| 8 |
+
COPY requirements.txt requirements.txt
|
| 9 |
+
COPY .env .env
|
| 10 |
+
COPY main.py main.py
|
| 11 |
+
|
| 12 |
+
# Install dependencies
|
| 13 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Expose the application port
|
| 16 |
+
EXPOSE 7860
|
| 17 |
+
|
| 18 |
+
# Debugging: Show files and env variables
|
| 19 |
+
RUN ls -al && cat .env
|
| 20 |
+
|
| 21 |
+
# Run the FastAPI application using uvicorn
|
| 22 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from phi.agent import Agent
|
| 4 |
+
from phi.model.groq import Groq
|
| 5 |
+
from phi.tools.yfinance import YFinanceTools
|
| 6 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
| 7 |
+
import os
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
|
| 10 |
+
import logging
|
| 11 |
+
|
| 12 |
+
logging.basicConfig(level=logging.INFO)
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
# Load environment variables
|
| 16 |
+
load_dotenv()
|
| 17 |
+
gorq_api_key = os.getenv("GROQ_API_KEY")
|
| 18 |
+
|
| 19 |
+
# Initialize FastAPI app
|
| 20 |
+
app = FastAPI()
|
| 21 |
+
|
| 22 |
+
# Define input schema
|
| 23 |
+
class QueryRequest(BaseModel):
|
| 24 |
+
input_text: str
|
| 25 |
+
|
| 26 |
+
# Web Search Agent
|
| 27 |
+
web_search_agent = Agent(
|
| 28 |
+
name="Web Search Agent",
|
| 29 |
+
role="Search the web for the information",
|
| 30 |
+
model=Groq(id="llama-3.3-70b-versatile"),
|
| 31 |
+
tools=[DuckDuckGo()],
|
| 32 |
+
instructions=["Always include sources"],
|
| 33 |
+
show_tools_calls=True,
|
| 34 |
+
markdown=True,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Financial Agent
|
| 38 |
+
finance_agent = Agent(
|
| 39 |
+
name="Finance AI Agent",
|
| 40 |
+
model=Groq(
|
| 41 |
+
id="llama-3.3-70b-versatile",
|
| 42 |
+
api_key=gorq_api_key,
|
| 43 |
+
role="Get financial data",
|
| 44 |
+
),
|
| 45 |
+
tools=[
|
| 46 |
+
YFinanceTools(
|
| 47 |
+
stock_price=True,
|
| 48 |
+
analyst_recommendations=True,
|
| 49 |
+
stock_fundamentals=True,
|
| 50 |
+
company_news=True,
|
| 51 |
+
),
|
| 52 |
+
],
|
| 53 |
+
instructions=["Use tables to display the data"],
|
| 54 |
+
show_tool_calls=True,
|
| 55 |
+
markdown=True,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Multi-Agent
|
| 59 |
+
multi_ai_agent = Agent(
|
| 60 |
+
team=[web_search_agent, finance_agent],
|
| 61 |
+
instructions=["Always include sources", "Use tables to display the data"],
|
| 62 |
+
show_tool_calls=True,
|
| 63 |
+
markdown=True,
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
@app.post("/query")
|
| 67 |
+
async def process_query(request: QueryRequest):
|
| 68 |
+
try:
|
| 69 |
+
response = multi_ai_agent.run(request.input_text)
|
| 70 |
+
return {"response": response}
|
| 71 |
+
except Exception as e:
|
| 72 |
+
logger.error(f"Error processing query: {e}")
|
| 73 |
+
return {"error": f"An error occurred: {str(e)}"}
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
phidata
|
| 2 |
+
python-dotenv
|
| 3 |
+
yfinance
|
| 4 |
+
packaging
|
| 5 |
+
duckduckgo-search
|
| 6 |
+
fastapi
|
| 7 |
+
uvicorn
|
| 8 |
+
groq
|
| 9 |
+
openai
|