summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Aichat.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-09-07 19:45:04 +0200
committerGitHub <noreply@github.com>2023-09-07 19:45:04 +0200
commit7ca1a59d95b52f94f674e8f981eab910b2f03518 (patch)
treeca506c3c152f3906a5b727a4cc6ebba1fd59d335 /g4f/Provider/Aichat.py
parent~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff)
parentFix imports in Bing (diff)
downloadgpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar
gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.gz
gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.bz2
gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.lz
gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.xz
gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.zst
gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.zip
Diffstat (limited to 'g4f/Provider/Aichat.py')
-rw-r--r--g4f/Provider/Aichat.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/g4f/Provider/Aichat.py b/g4f/Provider/Aichat.py
index 59640533..8edd17e2 100644
--- a/g4f/Provider/Aichat.py
+++ b/g4f/Provider/Aichat.py
@@ -1,25 +1,22 @@
from __future__ import annotations
-import requests
+from aiohttp import ClientSession
-from ..typing import Any, CreateResult
-from .base_provider import BaseProvider
+from .base_provider import AsyncProvider, format_prompt
-class Aichat(BaseProvider):
+class Aichat(AsyncProvider):
url = "https://chat-gpt.org/chat"
working = True
supports_gpt_35_turbo = True
@staticmethod
- def create_completion(
+ async def create_async(
model: str,
messages: list[dict[str, str]],
- stream: bool, **kwargs: Any) -> CreateResult:
-
- chat = "\n".join(f"{message['role']}: {message['content']}" for message in messages)
- chat += "\nassistant: "
-
+ proxy: str = None,
+ **kwargs
+ ) -> str:
headers = {
"authority": "chat-gpt.org",
"accept": "*/*",
@@ -35,21 +32,23 @@ class Aichat(BaseProvider):
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
}
-
- json_data = {
- "message": base,
- "temperature": kwargs.get('temperature', 0.5),
- "presence_penalty": 0,
- "top_p": kwargs.get('top_p', 1),
- "frequency_penalty": 0,
- }
-
- response = requests.post(
- "https://chat-gpt.org/api/text",
- headers=headers,
- json=json_data,
- )
- response.raise_for_status()
- if not response.json()['response']:
- raise Exception("Error Response: " + response.json())
- yield response.json()["message"]
+ async with ClientSession(
+ headers=headers
+ ) as session:
+ json_data = {
+ "message": format_prompt(messages),
+ "temperature": kwargs.get('temperature', 0.5),
+ "presence_penalty": 0,
+ "top_p": kwargs.get('top_p', 1),
+ "frequency_penalty": 0,
+ }
+ async with session.post(
+ "https://chat-gpt.org/api/text",
+ proxy=proxy,
+ json=json_data
+ ) as response:
+ response.raise_for_status()
+ result = await response.json()
+ if not result['response']:
+ raise Exception(f"Error Response: {result}")
+ return result["message"]