pvanand commited on
Commit
04f3799
1 Parent(s): 7334dbe

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -0
main.py CHANGED
@@ -5,6 +5,9 @@ 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")
@@ -54,7 +57,12 @@ 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 fastapi_cache import FastAPICache
9
+ from fastapi_cache.decorator import cache
10
+ from fastapi_cache.backends.inmemory import InMemoryBackend
11
 
12
  # Load environment variables from .env file
13
  #load_dotenv("keys.env")
 
57
  output_format: str = Query(default="Tabular Report", description="Output format for the report", enum=["Chat", "Full Text Report", "Tabular Report", "Tables only"])
58
  data_format: str = Query(default="Structured data", description="Type of data to extract from the internet", enum=["No presets", "Structured data", "Quantitative data"])
59
 
60
+ @app.on_event("startup")
61
+ async def startup():
62
+ FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")
63
+
64
  @app.post("/generate_report")
65
+ @cache(expire=60 * 60 * 24 * 7) # Cache for 7 days
66
  async def generate_report(request: Request, query: QueryModel):
67
  query_str = query.topic
68
  description = query.description