Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from fastapi import FastAPI, HTTPException, Query
|
2 |
from fastapi.responses import JSONResponse
|
3 |
-
from webscout import WEBS, transcriber, LLM
|
4 |
from typing import Optional, List, Dict, Union
|
5 |
from fastapi.encoders import jsonable_encoder
|
6 |
from bs4 import BeautifulSoup
|
@@ -151,26 +151,12 @@ async def llm_chat(
|
|
151 |
except Exception as e:
|
152 |
raise HTTPException(status_code=500, detail=f"Error during LLM chat: {e}")
|
153 |
|
154 |
-
def snova_ai(user, model="llama3-70b", system="Answer as concisely as possible."):
|
155 |
-
env_type = "tp16405b" if "405b" in model else "tp16"
|
156 |
-
data = {'body': {'messages': [{'role': 'system', 'content': system}, {'role': 'user', 'content': user}], 'stream': True, 'model': model}, 'env_type': env_type}
|
157 |
-
with requests.post('https://fast.snova.ai/api/completion', headers={'content-type': 'application/json'}, json=data, stream=True) as response:
|
158 |
-
output = ''
|
159 |
-
for line in response.iter_lines(decode_unicode=True):
|
160 |
-
if line.startswith('data:'):
|
161 |
-
try:
|
162 |
-
data = json.loads(line[len('data: '):])
|
163 |
-
output += data.get("choices", [{}])[0].get("delta", {}).get("content", '')
|
164 |
-
except json.JSONDecodeError:
|
165 |
-
if line[len('data: '):] == '[DONE]':
|
166 |
-
break
|
167 |
-
return output
|
168 |
|
169 |
@app.get("/api/fastAI")
|
170 |
async def fast_ai(user: str, model: str = "llama3-70b", system: str = "Answer as concisely as possible."):
|
171 |
"""Get a response from the Snova AI service."""
|
172 |
try:
|
173 |
-
response = await asyncio.to_thread(
|
174 |
return JSONResponse(content={"response": response})
|
175 |
except Exception as e:
|
176 |
raise HTTPException(status_code=500, detail=f"Error during Snova AI request: {e}")
|
|
|
1 |
from fastapi import FastAPI, HTTPException, Query
|
2 |
from fastapi.responses import JSONResponse
|
3 |
+
from webscout import WEBS, transcriber, LLM, fastai
|
4 |
from typing import Optional, List, Dict, Union
|
5 |
from fastapi.encoders import jsonable_encoder
|
6 |
from bs4 import BeautifulSoup
|
|
|
151 |
except Exception as e:
|
152 |
raise HTTPException(status_code=500, detail=f"Error during LLM chat: {e}")
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
@app.get("/api/fastAI")
|
156 |
async def fast_ai(user: str, model: str = "llama3-70b", system: str = "Answer as concisely as possible."):
|
157 |
"""Get a response from the Snova AI service."""
|
158 |
try:
|
159 |
+
response = await asyncio.to_thread(fastai, user, model, system)
|
160 |
return JSONResponse(content={"response": response})
|
161 |
except Exception as e:
|
162 |
raise HTTPException(status_code=500, detail=f"Error during Snova AI request: {e}")
|