Skip to content

Commit 5a750f8

Browse files
Merge pull request #3 from yashksaini-coder/kush
Main python server file update
2 parents 8583b83 + 01f4542 commit 5a750f8

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

app.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import os
99
from dotenv import load_dotenv
1010
# Load API key from .env file
11-
11+
from fastapi.middleware.cors import CORSMiddleware
12+
from topStocks import get_top_stocks
1213
load_dotenv(dotenv_path=".env")
1314
GROQ_API_KEY = os.getenv("api_key")
1415

@@ -19,6 +20,14 @@
1920

2021
app = FastAPI()
2122
# Web searching agent
23+
app.add_middleware(
24+
CORSMiddleware,
25+
allow_origins=["*"],
26+
allow_credentials=True,
27+
allow_methods=["*"],
28+
allow_headers=["*"],
29+
)
30+
2231
web_search_agent = Agent(
2332
name="web_agent",
2433
role="search the web for information based on the user given input",
@@ -66,6 +75,12 @@
6675
markdown=True,
6776
)
6877

78+
@app.get("/top-stocks")
79+
async def read_top_stocks():
80+
top_stocks = ['AAPL', 'GOOGL', 'MSFT', 'AMZN', 'TSLA']
81+
stock_info = get_top_stocks(top_stocks)
82+
return stock_info
83+
6984
@app.get("/ask")
7085
def ask(query: str):
7186
"""

main.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import groq
33
import os
44
from dotenv import load_dotenv
5-
from fastapi.middleware.cors import CORSMiddleware
6-
from topStocks import get_top_stocks
5+
76
# Load API key from .env file
87

98
load_dotenv(dotenv_path=".env")
@@ -17,13 +16,7 @@
1716

1817
app = FastAPI()
1918

20-
app.add_middleware(
21-
CORSMiddleware,
22-
allow_origins=["*"],
23-
allow_credentials=True,
24-
allow_methods=["*"],
25-
allow_headers=["*"],
26-
)
19+
2720

2821
@app.get("/ask")
2922
def ask(query: str):
@@ -45,9 +38,3 @@ def ask(query: str):
4538

4639
except Exception as e:
4740
return {"error": str(e)}
48-
49-
@app.get("/top-stocks")
50-
async def read_top_stocks():
51-
top_stocks = ['AAPL', 'GOOGL', 'MSFT', 'AMZN', 'TSLA']
52-
stock_info = get_top_stocks(top_stocks)
53-
return stock_info

0 commit comments

Comments
 (0)