返回提交历史
Modified
README.md
+1
-1
Modified
docs/async_client.md
+5
-4
Modified
docs/client.md
+2
-2
Modified
docs/docker.md
+1
-1
Modified
docs/git.md
+1
-1
Modified
docs/interference-api.md
+3
-3
Modified
g4f/client/client.py
+21
-7
XFEstudio/gpt4free
Update (docs/ README.md g4f/client/client.py)
21a26f68
代码差异
7 个文件
+34
-19
@@ -174,7 +174,7 @@ from g4f.client import Client
174
174
175
175
client = Client()
176
176
response = client.chat.completions.create(
177
model="gpt-3.5-turbo",
177
model="gpt-4o-mini",
178
178
messages=[{"role": "user", "content": "Hello"}],
179
179
# Add any other necessary parameters
180
180
)
@@ -57,7 +57,7 @@ client = Client(
57
57
**Here’s an improved example of creating chat completions:**
58
58
```python
59
59
response = await async_client.chat.completions.create(
60
model="gpt-3.5-turbo",
60
model="gpt-4o-mini",
61
61
messages=[
62
62
{
63
63
"role": "user",
@@ -99,7 +99,7 @@ async def main():
99
99
client = Client()
100
100
101
101
response = await client.chat.completions.async_create(
102
model="gpt-3.5-turbo",
102
model="gpt-4o-mini",
103
103
messages=[
104
104
{
105
105
"role": "user",
@@ -230,7 +230,7 @@ async def main():
230
230
client = Client()
231
231
232
232
task1 = client.chat.completions.async_create(
233
model="gpt-3.5-turbo",
233
model="gpt-4o-mini",
234
234
messages=[
235
235
{
236
236
"role": "user",
@@ -262,6 +262,7 @@ The G4F AsyncClient supports a wide range of AI models and providers, allowing y
262
262
263
263
### Models
264
264
- GPT-3.5-Turbo
265
- GPT-4o-Mini
265
266
- GPT-4
266
267
- DALL-E 3
267
268
- Gemini
@@ -306,7 +307,7 @@ Implementing proper error handling and following best practices is crucial when
306
307
```python
307
308
try:
308
309
response = await client.chat.completions.async_create(
309
model="gpt-3.5-turbo",
310
model="gpt-4o-mini",
310
311
messages=[
311
312
{
312
313
"role": "user",
@@ -62,7 +62,7 @@ client = Client(
62
62
**Here’s an improved example of creating chat completions:**
63
63
```python
64
64
response = client.chat.completions.create(
65
model="gpt-3.5-turbo",
65
model="gpt-4o-mini",
66
66
messages=[
67
67
{
68
68
"role": "user",
@@ -104,7 +104,7 @@ from g4f.client import Client
104
104
client = Client()
105
105
106
106
response = client.chat.completions.create(
107
model="gpt-3.5-turbo",
107
model="gpt-4o-mini",
108
108
messages=[
109
109
{
110
110
"role": "user",
@@ -71,7 +71,7 @@ import requests
71
71
72
72
url = "http://localhost:1337/v1/chat/completions"
73
73
body = {
74
"model": "gpt-3.5-turbo",
74
"model": "gpt-4o-mini",
75
75
"stream": False,
76
76
"messages": [
77
77
{"role": "assistant", "content": "What can you do?"}
@@ -95,7 +95,7 @@ from g4f.client import Client
95
95
client = Client()
96
96
97
97
response = client.chat.completions.create(
98
model="gpt-3.5-turbo",
98
model="gpt-4o-mini",
99
99
messages=[
100
100
{
101
101
"role": "user",
@@ -64,7 +64,7 @@ curl -X POST "http://localhost:1337/v1/chat/completions" \
64
64
"content": "Hello"
65
65
}
66
66
],
67
"model": "gpt-3.5-turbo"
67
"model": "gpt-4o-mini"
68
68
}'
69
69
```
70
70
@@ -104,7 +104,7 @@ client = OpenAI(
104
104
)
105
105
106
106
response = client.chat.completions.create(
107
model="gpt-3.5-turbo",
107
model="gpt-4o-mini",
108
108
messages=[{"role": "user", "content": "Write a poem about a tree"}],
109
109
stream=True,
110
110
)
@@ -131,7 +131,7 @@ import requests
131
131
url = "http://localhost:1337/v1/chat/completions"
132
132
133
133
body = {
134
"model": "gpt-3.5-turbo",
134
"model": "gpt-4o-mini",
135
135
"stream": False,
136
136
"messages": [
137
137
{"role": "assistant", "content": "What can you do?"}
@@ -154,14 +154,29 @@ class AsyncClient(Client):
154
154
stacklevel=2
155
155
)
156
156
super().__init__(*args, **kwargs)
157
self.chat = Chat(self)
158
self._images = Images(self)
159
self.completions = Completions(self)
157
160
158
async def chat_complete(self, *args, **kwargs):
159
"""Legacy method that redirects to async_create"""
160
return await self.chat.completions.async_create(*args, **kwargs)
161
@property
162
def images(self) -> 'Images':
163
return self._images
164
165
async def async_create(self, *args, **kwargs) -> Union['ChatCompletion', AsyncIterator['ChatCompletionChunk']]:
166
response = await super().async_create(*args, **kwargs)
167
async for result in response:
168
return result
161
169
162
async def create_image(self, *args, **kwargs):
163
"""Legacy method that redirects to async_generate"""
164
return await self.images.async_generate(*args, **kwargs)
170
async def async_generate(self, *args, **kwargs) -> 'ImagesResponse':
171
return await super().async_generate(*args, **kwargs)
172
173
async def _fetch_image(self, url: str) -> bytes:
174
async with ClientSession() as session:
175
async with session.get(url) as resp:
176
if resp.status == 200:
177
return await resp.read()
178
else:
179
raise Exception(f"Failed to fetch image from {url}, status code {resp.status}")
165
180
166
181
class Completions:
167
182
def __init__(self, client: Client, provider: ProviderType = None):
@@ -531,4 +546,3 @@ class Images:
531
546
async def create_variation(self, image: Union[str, bytes], model: str = None, response_format: str = "url", **kwargs):
532
547
# Existing implementation, adjust if you want to support b64_json here as well
533
548
pass
534