From e46b5fe043ffcdb87ddb97db14a7e699dd8a2690 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 9 Oct 2023 10:22:17 +0200 Subject: Add proxy support to all providers --- g4f/Provider/GPTalk.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'g4f/Provider/GPTalk.py') diff --git a/g4f/Provider/GPTalk.py b/g4f/Provider/GPTalk.py index c85399c1..afb6ff68 100644 --- a/g4f/Provider/GPTalk.py +++ b/g4f/Provider/GPTalk.py @@ -2,8 +2,8 @@ from __future__ import annotations import secrets, time, json from aiohttp import ClientSession -from typing import AsyncGenerator +from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider from .helper import format_prompt @@ -18,9 +18,10 @@ class GPTalk(AsyncGeneratorProvider): async def create_async_generator( cls, model: str, - messages: list[dict[str, str]], + messages: Messages, + proxy: str = None, **kwargs - ) -> AsyncGenerator: + ) -> AsyncResult: if not model: model = "gpt-3.5-turbo" timestamp = int(time.time()) @@ -48,7 +49,7 @@ class GPTalk(AsyncGeneratorProvider): "fingerprint": secrets.token_hex(16).zfill(32), "platform": "fingerprint" } - async with session.post(cls.url + "/api/chatgpt/user/login", json=data) as response: + async with session.post(cls.url + "/api/chatgpt/user/login", json=data, proxy=proxy) as response: response.raise_for_status() cls._auth = (await response.json())["data"] data = { @@ -68,11 +69,11 @@ class GPTalk(AsyncGeneratorProvider): headers = { 'authorization': f'Bearer {cls._auth["token"]}', } - async with session.post(cls.url + "/api/chatgpt/chatapi/text", json=data, headers=headers) as response: + async with session.post(cls.url + "/api/chatgpt/chatapi/text", json=data, headers=headers, proxy=proxy) as response: response.raise_for_status() token = (await response.json())["data"]["token"] last_message = "" - async with session.get(cls.url + "/api/chatgpt/chatapi/stream", params={"token": token}) as response: + async with session.get(cls.url + "/api/chatgpt/chatapi/stream", params={"token": token}, proxy=proxy) as response: response.raise_for_status() async for line in response.content: if line.startswith(b"data: "): -- cgit v1.2.3