mirror of https://github.com/xtekky/gpt4free
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
11 months ago
|
from __future__ import annotations
|
||
|
|
||
|
from aiohttp import ClientSession
|
||
|
from hashlib import sha256
|
||
9 months ago
|
from ...typing import AsyncResult, Messages, Dict
|
||
11 months ago
|
|
||
9 months ago
|
from ..base_provider import AsyncGeneratorProvider
|
||
|
from ..helper import format_prompt
|
||
11 months ago
|
|
||
|
|
||
|
class Cromicle(AsyncGeneratorProvider):
|
||
11 months ago
|
url: str = 'https://cromicle.top'
|
||
10 months ago
|
working: bool = False
|
||
11 months ago
|
supports_gpt_35_turbo: bool = True
|
||
11 months ago
|
|
||
|
@classmethod
|
||
|
async def create_async_generator(
|
||
|
cls,
|
||
|
model: str,
|
||
11 months ago
|
messages: Messages,
|
||
11 months ago
|
proxy: str = None,
|
||
|
**kwargs
|
||
11 months ago
|
) -> AsyncResult:
|
||
11 months ago
|
async with ClientSession(
|
||
|
headers=_create_header()
|
||
|
) as session:
|
||
|
async with session.post(
|
||
11 months ago
|
f'{cls.url}/chat',
|
||
11 months ago
|
proxy=proxy,
|
||
11 months ago
|
json=_create_payload(format_prompt(messages))
|
||
11 months ago
|
) as response:
|
||
|
response.raise_for_status()
|
||
|
async for stream in response.content.iter_any():
|
||
|
if stream:
|
||
|
yield stream.decode()
|
||
|
|
||
|
|
||
11 months ago
|
def _create_header() -> Dict[str, str]:
|
||
11 months ago
|
return {
|
||
|
'accept': '*/*',
|
||
|
'content-type': 'application/json',
|
||
|
}
|
||
|
|
||
|
|
||
11 months ago
|
def _create_payload(message: str) -> Dict[str, str]:
|
||
11 months ago
|
return {
|
||
11 months ago
|
'message': message,
|
||
|
'token': 'abc',
|
||
|
'hash': sha256('abc'.encode() + message.encode()).hexdigest()
|
||
|
}
|