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.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
11 months ago
|
from __future__ import annotations
|
||
|
|
||
10 months ago
|
from ...typing import Messages
|
||
11 months ago
|
from curl_cffi.requests import AsyncSession
|
||
10 months ago
|
from ..base_provider import AsyncProvider, format_prompt
|
||
11 months ago
|
|
||
|
|
||
|
class ChatgptDuo(AsyncProvider):
|
||
|
url = "https://chatgptduo.com"
|
||
|
supports_gpt_35_turbo = True
|
||
11 months ago
|
working = False
|
||
11 months ago
|
|
||
|
@classmethod
|
||
|
async def create_async(
|
||
|
cls,
|
||
|
model: str,
|
||
11 months ago
|
messages: Messages,
|
||
11 months ago
|
proxy: str = None,
|
||
11 months ago
|
timeout: int = 120,
|
||
11 months ago
|
**kwargs
|
||
|
) -> str:
|
||
11 months ago
|
async with AsyncSession(
|
||
|
impersonate="chrome107",
|
||
|
proxies={"https": proxy},
|
||
|
timeout=timeout
|
||
|
) as session:
|
||
11 months ago
|
prompt = format_prompt(messages),
|
||
|
data = {
|
||
|
"prompt": prompt,
|
||
|
"search": prompt,
|
||
|
"purpose": "ask",
|
||
|
}
|
||
11 months ago
|
response = await session.post(f"{cls.url}/", data=data)
|
||
|
response.raise_for_status()
|
||
|
data = response.json()
|
||
11 months ago
|
|
||
11 months ago
|
cls._sources = [{
|
||
|
"title": source["title"],
|
||
|
"url": source["link"],
|
||
|
"snippet": source["snippet"]
|
||
|
} for source in data["results"]]
|
||
11 months ago
|
|
||
11 months ago
|
return data["answer"]
|
||
11 months ago
|
|
||
|
@classmethod
|
||
|
def get_sources(cls):
|
||
|
return cls._sources
|
||
|
|
||
|
@classmethod
|
||
|
@property
|
||
|
def params(cls):
|
||
|
params = [
|
||
|
("model", "str"),
|
||
|
("messages", "list[dict[str, str]]"),
|
||
|
("stream", "bool"),
|
||
|
]
|
||
|
param = ", ".join([": ".join(p) for p in params])
|
||
|
return f"g4f.provider.{cls.__name__} supports: ({param})"
|