Spaces:
Running
Running
Update webscout.py
Browse files- webscout.py +23 -1
webscout.py
CHANGED
@@ -9,6 +9,9 @@ from random import choice
|
|
9 |
from threading import Event
|
10 |
from types import TracebackType
|
11 |
from typing import Dict, List, Optional, Tuple, Type, Union, cast
|
|
|
|
|
|
|
12 |
|
13 |
import pyreqwest_impersonate as pri
|
14 |
|
@@ -1722,4 +1725,23 @@ def fastai(user, model="llama3-70b", system="Answer as concisely as possible."):
|
|
1722 |
except json.JSONDecodeError:
|
1723 |
if line[len('data: '):] == '[DONE]':
|
1724 |
break
|
1725 |
-
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from threading import Event
|
10 |
from types import TracebackType
|
11 |
from typing import Dict, List, Optional, Tuple, Type, Union, cast
|
12 |
+
import asyncio
|
13 |
+
import json
|
14 |
+
import aiohttp
|
15 |
|
16 |
import pyreqwest_impersonate as pri
|
17 |
|
|
|
1725 |
except json.JSONDecodeError:
|
1726 |
if line[len('data: '):] == '[DONE]':
|
1727 |
break
|
1728 |
+
return output
|
1729 |
+
|
1730 |
+
|
1731 |
+
async def fastai_stream(user, model="llama3-8b", system="Answer as concisely as possible."):
|
1732 |
+
env_type = "tp16405b" if "405b" in model else "tp16"
|
1733 |
+
data = {'body': {'messages': [{'role': 'system', 'content': system}, {'role': 'user', 'content': user}], 'stream': True, 'model': model}, 'env_type': env_type}
|
1734 |
+
|
1735 |
+
async with aiohttp.ClientSession() as session:
|
1736 |
+
async with session.post('https://fast.snova.ai/api/completion', headers={'content-type': 'application/json'}, json=data) as response:
|
1737 |
+
async for line in response.content:
|
1738 |
+
line = line.decode('utf-8').strip()
|
1739 |
+
if line.startswith('data:'):
|
1740 |
+
try:
|
1741 |
+
data = json.loads(line[len('data: '):])
|
1742 |
+
content = data.get("choices", [{}])[0].get("delta", {}).get("content", '')
|
1743 |
+
if content:
|
1744 |
+
yield f"data: {json.dumps({'response': content})}\n\n"
|
1745 |
+
except json.JSONDecodeError:
|
1746 |
+
if line[len('data: '):] == '[DONE]':
|
1747 |
+
break
|