返回提交历史
Modified
docs/client.md
+28
-2
XFEstudio/gpt4free
docs(docs/client.md): update G4F Client API guide
96e1efee
代码差异
1 个文件
+28
-2
@@ -7,6 +7,7 @@
7
7
- [Getting Started](#getting-started)
8
8
- [Switching to G4F Client](#switching-to-g4f-client)
9
9
- [Initializing the Client](#initializing-the-client)
10
- [Creating Chat Completions](#creating-chat-completions)
10
11
- [Configuration](#configuration)
11
12
- [Usage Examples](#usage-examples)
12
13
- [Text Completions](#text-completions)
@@ -22,7 +23,7 @@
22
23
23
24
24
25
## Introduction
25
Welcome to the G4F Client API, a cutting-edge tool for seamlessly integrating advanced AI capabilities into your Python applications. This guide is designed to facilitate your transition from using the OpenAI client to the G4F Client, offering enhanced features while maintaining compatibility with the existing OpenAI API.
26
Welcome to the G4F Client API, a cutting-edge tool for seamlessly integrating advanced AI capabilities into your Python applications. This guide is designed to facilitate your transition from using the OpenAI or Anthropic client to the G4F Client, offering enhanced features while maintaining compatibility with the existing OpenAI and Anthropic API.
26
27
27
28
## Getting Started
28
29
### Switching to G4F Client
@@ -42,7 +43,7 @@ from g4f.client import Client as OpenAI
42
43
43
44
44
45
45
The G4F Client preserves the same familiar API interface as OpenAI, ensuring a smooth transition process.
46
The G4F Client preserves the same familiar API interface as OpenAI or Anthropic, ensuring a smooth transition process.
46
47
47
48
## Initializing the Client
48
49
To utilize the G4F Client, create a new instance. **Below is an example showcasing custom providers:**
@@ -56,6 +57,30 @@ client = Client(
56
57
# Add any other necessary parameters
57
58
)
58
59
```
60
61
## Creating Chat Completions
62
**Here’s an improved example of creating chat completions:**
63
```python
64
response = client.chat.completions.create(
65
system="You are a helpful assistant.",
66
model="gpt-3.5-turbo",
67
messages=[
68
{
69
"role": "user",
70
"content": "Say this is a test"
71
}
72
]
73
# Add any other necessary parameters
74
)
75
```
76
77
**This example:**
78
- Sets a system message to define the assistant's role
79
- Asks a specific question `Say this is a test`
80
- Configures various parameters like temperature and max_tokens for more control over the output
81
- Disables streaming for a complete response
82
83
You can adjust these parameters based on your specific needs.
59
84
60
85
61
86
## Configuration
@@ -271,6 +296,7 @@ while True:
271
296
try:
272
297
# Get GPT's response
273
298
response = client.chat.completions.create(
299
system="You are a helpful assistant.",
274
300
messages=messages,
275
301
model=g4f.models.default,
276
302
)