Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -5,11 +5,19 @@ from typing import List, Dict, Any
|
|
5 |
from helper_functions_api import md_to_html, search_brave, fetch_and_extract_content, limit_tokens, together_response, insert_data
|
6 |
import os
|
7 |
from dotenv import load_dotenv, find_dotenv
|
|
|
|
|
|
|
8 |
|
9 |
# Load environment variables from .env file
|
10 |
#load_dotenv("keys.env")
|
11 |
|
12 |
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
13 |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
14 |
BRAVE_API_KEY = os.getenv('BRAVE_API_KEY')
|
15 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
@@ -54,7 +62,11 @@ class QueryModel(BaseModel):
|
|
54 |
output_format: str = Query(default="Tabular Report", description="Output format for the report", enum=["Chat", "Full Text Report", "Tabular Report", "Tables only"])
|
55 |
data_format: str = Query(default="Structured data", description="Type of data to extract from the internet", enum=["No presets", "Structured data", "Quantitative data"])
|
56 |
|
|
|
|
|
|
|
57 |
@app.post("/generate_report")
|
|
|
58 |
async def generate_report(request: Request, query: QueryModel):
|
59 |
query_str = query.topic
|
60 |
description = query.description
|
|
|
5 |
from helper_functions_api import md_to_html, search_brave, fetch_and_extract_content, limit_tokens, together_response, insert_data
|
6 |
import os
|
7 |
from dotenv import load_dotenv, find_dotenv
|
8 |
+
from datetime import datetime, timedelta
|
9 |
+
from fastapi_cache import FastAPICache
|
10 |
+
from fastapi_cache.backends.inmemory import InMemoryBackend
|
11 |
|
12 |
# Load environment variables from .env file
|
13 |
#load_dotenv("keys.env")
|
14 |
|
15 |
app = FastAPI()
|
16 |
+
|
17 |
+
@app.on_event("startup")
|
18 |
+
async def startup():
|
19 |
+
FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")
|
20 |
+
|
21 |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
22 |
BRAVE_API_KEY = os.getenv('BRAVE_API_KEY')
|
23 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
|
62 |
output_format: str = Query(default="Tabular Report", description="Output format for the report", enum=["Chat", "Full Text Report", "Tabular Report", "Tables only"])
|
63 |
data_format: str = Query(default="Structured data", description="Type of data to extract from the internet", enum=["No presets", "Structured data", "Quantitative data"])
|
64 |
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
@app.post("/generate_report")
|
69 |
+
@cache(expire=3600)
|
70 |
async def generate_report(request: Request, query: QueryModel):
|
71 |
query_str = query.topic
|
72 |
description = query.description
|