2023-07-28 13:07:17 +03:00
|
|
|
import time
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from ..typing import Any, CreateResult
|
|
|
|
from .base_provider import BaseProvider
|
|
|
|
|
|
|
|
|
|
|
|
class Acytoo(BaseProvider):
|
2023-08-27 18:37:44 +03:00
|
|
|
url = 'https://chat.acytoo.com/'
|
|
|
|
working = True
|
2023-07-28 13:07:17 +03:00
|
|
|
supports_gpt_35_turbo = True
|
|
|
|
|
2023-08-24 22:32:22 +03:00
|
|
|
@classmethod
|
2023-07-28 13:07:17 +03:00
|
|
|
def create_completion(
|
2023-08-24 22:32:22 +03:00
|
|
|
cls,
|
2023-07-28 13:07:17 +03:00
|
|
|
model: str,
|
|
|
|
messages: list[dict[str, str]],
|
2023-08-27 18:37:44 +03:00
|
|
|
stream: bool, **kwargs: Any) -> CreateResult:
|
2023-07-28 13:07:17 +03:00
|
|
|
|
2023-08-27 18:37:44 +03:00
|
|
|
response = requests.post(f'{cls.url}api/completions',
|
|
|
|
headers=_create_header(), json=_create_payload(messages, kwargs.get('temperature', 0.5)))
|
|
|
|
|
2023-07-28 13:07:17 +03:00
|
|
|
response.raise_for_status()
|
2023-08-27 18:37:44 +03:00
|
|
|
response.encoding = 'utf-8'
|
|
|
|
|
2023-07-28 13:07:17 +03:00
|
|
|
yield response.text
|
|
|
|
|
|
|
|
|
|
|
|
def _create_header():
|
|
|
|
return {
|
2023-08-27 18:37:44 +03:00
|
|
|
'accept': '*/*',
|
|
|
|
'content-type': 'application/json',
|
2023-07-28 13:07:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-22 09:59:58 +03:00
|
|
|
def _create_payload(messages: list[dict[str, str]], temperature):
|
2023-07-28 13:07:17 +03:00
|
|
|
payload_messages = [
|
2023-08-27 18:37:44 +03:00
|
|
|
message | {'createdAt': int(time.time()) * 1000} for message in messages
|
2023-07-28 13:07:17 +03:00
|
|
|
]
|
2023-08-27 18:37:44 +03:00
|
|
|
|
2023-07-28 13:07:17 +03:00
|
|
|
return {
|
2023-08-27 18:37:44 +03:00
|
|
|
'key' : '',
|
|
|
|
'model' : 'gpt-3.5-turbo',
|
|
|
|
'messages' : payload_messages,
|
|
|
|
'temperature' : temperature,
|
|
|
|
'password' : ''
|
|
|
|
}
|