Spaces:
Build error
Build error
Commit ·
d5d7a80
1
Parent(s): 4689e89
await for /search-assistant api
Browse files- utils/ModelCallingFunctions.py +21 -16
- utils/information.db +0 -0
utils/ModelCallingFunctions.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
from typing import List
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
import json
|
| 5 |
import pickle
|
| 6 |
|
|
@@ -16,6 +17,7 @@ from .HelperFunctions import web_search_result_processor
|
|
| 16 |
|
| 17 |
from .prompts import PROMPTS
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
TOGETHER_API = os.getenv("TOGETHER_API")
|
| 21 |
GEMINI_API = os.getenv("GEMINI_API")
|
|
@@ -71,15 +73,23 @@ def industry_finder(collection_id):
|
|
| 71 |
|
| 72 |
async def web_search(session, question):
|
| 73 |
data = {"query": question, "model_id": "openai/gpt-4o-mini"}
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
async def other_info(company_data):
|
|
@@ -98,14 +108,9 @@ async def other_info(company_data):
|
|
| 98 |
results = {}
|
| 99 |
async with aiohttp.ClientSession() as session:
|
| 100 |
tasks = [web_search(session, question) for question in questions.values()]
|
| 101 |
-
responses = await asyncio.gather(*tasks
|
| 102 |
-
|
| 103 |
for type_, response in zip(questions, responses):
|
| 104 |
-
|
| 105 |
-
results[type_] = {"error": str(response)}
|
| 106 |
-
else:
|
| 107 |
-
results[type_] = response
|
| 108 |
-
|
| 109 |
return results
|
| 110 |
|
| 111 |
|
|
|
|
| 1 |
import os
|
| 2 |
from typing import List
|
| 3 |
from PIL import Image
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
import json
|
| 6 |
import pickle
|
| 7 |
|
|
|
|
| 17 |
|
| 18 |
from .prompts import PROMPTS
|
| 19 |
|
| 20 |
+
load_dotenv("utils/.env")
|
| 21 |
|
| 22 |
TOGETHER_API = os.getenv("TOGETHER_API")
|
| 23 |
GEMINI_API = os.getenv("GEMINI_API")
|
|
|
|
| 73 |
|
| 74 |
async def web_search(session, question):
|
| 75 |
data = {"query": question, "model_id": "openai/gpt-4o-mini"}
|
| 76 |
+
try:
|
| 77 |
+
async with session.post(
|
| 78 |
+
"https://general-chat.elevatics.cloud/search-assistant",
|
| 79 |
+
json=data,
|
| 80 |
+
headers={"X-API-KEY": X_API_KEY, "Content-Type": "application/json"},
|
| 81 |
+
timeout=aiohttp.ClientTimeout(total=60), # Increase timeout to 60 seconds
|
| 82 |
+
) as response:
|
| 83 |
+
print(f"Status: {response.status}")
|
| 84 |
+
if response.status == 200:
|
| 85 |
+
content = await response.text()
|
| 86 |
+
return content
|
| 87 |
+
else:
|
| 88 |
+
return f"Error: HTTP {response.status}"
|
| 89 |
+
except asyncio.TimeoutError:
|
| 90 |
+
return "Error: Request timed out"
|
| 91 |
+
except aiohttp.ClientError as e:
|
| 92 |
+
return f"Error: {str(e)}"
|
| 93 |
|
| 94 |
|
| 95 |
async def other_info(company_data):
|
|
|
|
| 108 |
results = {}
|
| 109 |
async with aiohttp.ClientSession() as session:
|
| 110 |
tasks = [web_search(session, question) for question in questions.values()]
|
| 111 |
+
responses = await asyncio.gather(*tasks)
|
|
|
|
| 112 |
for type_, response in zip(questions, responses):
|
| 113 |
+
results[type_] = response
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
return results
|
| 115 |
|
| 116 |
|
utils/information.db
ADDED
|
Binary file (164 kB). View file
|
|
|