Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,24 +1,27 @@
|
|
1 |
from fastapi import FastAPI, HTTPException, Request, Query
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from pydantic import BaseModel
|
4 |
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 |
from datetime import datetime, timedelta
|
9 |
-
from fastapi_cache import FastAPICache
|
10 |
-
from fastapi_cache.backends.inmemory import InMemoryBackend
|
11 |
-
from fastapi_cache.decorator import cache
|
12 |
import asyncio
|
13 |
import re
|
14 |
# Load environment variables from .env file
|
15 |
#load_dotenv("keys.env")
|
16 |
|
17 |
-
app = FastAPI()
|
18 |
|
19 |
-
@app.on_event("startup")
|
20 |
-
async def startup():
|
21 |
-
FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")
|
22 |
|
23 |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
24 |
BRAVE_API_KEY = os.getenv('BRAVE_API_KEY')
|
@@ -83,7 +86,7 @@ async def generate_report(query: QueryModel):
|
|
83 |
if query.internet:
|
84 |
search_query = re.sub(r'[^\w\s]', '', description).strip()
|
85 |
try:
|
86 |
-
urls, optimized_search_query = search_brave(search_query, num_results=8)
|
87 |
all_text_with_urls = fetch_and_extract_content(data_format, urls, description)
|
88 |
additional_context = limit_tokens(str(all_text_with_urls))
|
89 |
prompt = f"Write a factual answer to the query:: {description} #### , refer the provided internet search results reference:{additional_context}"
|
|
|
1 |
from fastapi import FastAPI, HTTPException, Request, Query
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
from fastapi_cache import FastAPICache
|
4 |
+
from fastapi_cache.backends.inmemory import InMemoryBackend
|
5 |
+
from fastapi_cache.decorator import cache
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
@app.on_event("startup")
|
10 |
+
async def startup():
|
11 |
+
FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")
|
12 |
+
|
13 |
from pydantic import BaseModel
|
14 |
from typing import List, Dict, Any
|
15 |
from helper_functions_api import md_to_html, search_brave, fetch_and_extract_content, limit_tokens, together_response, insert_data
|
16 |
import os
|
17 |
from dotenv import load_dotenv, find_dotenv
|
18 |
from datetime import datetime, timedelta
|
|
|
|
|
|
|
19 |
import asyncio
|
20 |
import re
|
21 |
# Load environment variables from .env file
|
22 |
#load_dotenv("keys.env")
|
23 |
|
|
|
24 |
|
|
|
|
|
|
|
25 |
|
26 |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
27 |
BRAVE_API_KEY = os.getenv('BRAVE_API_KEY')
|
|
|
86 |
if query.internet:
|
87 |
search_query = re.sub(r'[^\w\s]', '', description).strip()
|
88 |
try:
|
89 |
+
urls, optimized_search_query = await search_brave(search_query, num_results=8)
|
90 |
all_text_with_urls = fetch_and_extract_content(data_format, urls, description)
|
91 |
additional_context = limit_tokens(str(all_text_with_urls))
|
92 |
prompt = f"Write a factual answer to the query:: {description} #### , refer the provided internet search results reference:{additional_context}"
|