Spaces:
Paused
Paused
Update webscout.py
Browse files- webscout.py +38 -1
webscout.py
CHANGED
|
@@ -1708,4 +1708,41 @@ class LLM:
|
|
| 1708 |
result = requests.post(url=url, data=data, headers=headers)
|
| 1709 |
return result.json()['choices'][0]['message']['content']
|
| 1710 |
except:
|
| 1711 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1708 |
result = requests.post(url=url, data=data, headers=headers)
|
| 1709 |
return result.json()['choices'][0]['message']['content']
|
| 1710 |
except:
|
| 1711 |
+
return None
|
| 1712 |
+
class FastAI:
|
| 1713 |
+
def __init__(self, model="llama3-70b", system="Answer as concisely as possible."):
|
| 1714 |
+
self.model = model
|
| 1715 |
+
self.system = system
|
| 1716 |
+
|
| 1717 |
+
def _prepare_data(self, user):
|
| 1718 |
+
env_type = "tp16405b" if "405b" in self.model else "tp16"
|
| 1719 |
+
return {
|
| 1720 |
+
'body': {
|
| 1721 |
+
'messages': [
|
| 1722 |
+
{'role': 'system', 'content': self.system},
|
| 1723 |
+
{'role': 'user', 'content': user}
|
| 1724 |
+
],
|
| 1725 |
+
'stream': True,
|
| 1726 |
+
'model': self.model
|
| 1727 |
+
},
|
| 1728 |
+
'env_type': env_type
|
| 1729 |
+
}
|
| 1730 |
+
|
| 1731 |
+
def generate_response(self, user):
|
| 1732 |
+
data = self._prepare_data(user)
|
| 1733 |
+
response_text = ''
|
| 1734 |
+
with requests.post(
|
| 1735 |
+
'https://fast.snova.ai/api/completion',
|
| 1736 |
+
headers={'content-type': 'application/json'},
|
| 1737 |
+
json=data,
|
| 1738 |
+
stream=True
|
| 1739 |
+
) as response:
|
| 1740 |
+
for line in response.iter_lines(decode_unicode=True):
|
| 1741 |
+
if line.startswith('data:'):
|
| 1742 |
+
try:
|
| 1743 |
+
data = json.loads(line[len('data: '):])
|
| 1744 |
+
response_text += data.get("choices", [{}])[0].get("delta", {}).get("content", '')
|
| 1745 |
+
except json.JSONDecodeError:
|
| 1746 |
+
if line[len('data: '):] == '[DONE]':
|
| 1747 |
+
break
|
| 1748 |
+
return response_text
|