返回提交历史
Deleted
g4f/client/AsyncClient.py
+0
-38
Modified
g4f/client/__init__.py
+1
-2
XFEstudio/gpt4free
Update (g4f/client/)
b5c432f7
代码差异
2 个文件
+1
-40
@@ -1,38 +0,0 @@
1
from __future__ import annotations
2
3
from .Client import Client, Chat, Images, Completions
4
from .Client import async_iter_response, async_iter_append_model_and_provider
5
from aiohttp import ClientSession
6
from typing import Union, AsyncIterator
7
8
class AsyncClient(Client):
9
def __init__(self, *args, **kwargs):
10
super().__init__(*args, **kwargs)
11
self.chat = AsyncChat(self)
12
self._images = AsyncImages(self)
13
14
@property
15
def images(self) -> 'AsyncImages':
16
return self._images
17
18
class AsyncCompletions(Completions):
19
async def async_create(self, *args, **kwargs) -> Union['ChatCompletion', AsyncIterator['ChatCompletionChunk']]:
20
response = await super().async_create(*args, **kwargs)
21
async for result in response:
22
return result
23
24
class AsyncChat(Chat):
25
def __init__(self, client: AsyncClient):
26
self.completions = AsyncCompletions(client)
27
28
class AsyncImages(Images):
29
async def async_generate(self, *args, **kwargs) -> 'ImagesResponse':
30
return await super().async_generate(*args, **kwargs)
31
32
async def _fetch_image(self, url: str) -> bytes:
33
async with ClientSession() as session:
34
async with session.get(url) as resp:
35
if resp.status == 200:
36
return await resp.read()
37
else:
38
raise Exception(f"Failed to fetch image from {url}, status code {resp.status}")
@@ -1,3 +1,2 @@
1
1
from .stubs import ChatCompletion, ChatCompletionChunk, ImagesResponse
2
from .client import Client
3
from .client import AsyncClient
2
from .client import Client, AsyncClient