XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update client.md

58b8372d
H Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +46 -28
Modified docs/client.md +46 -28
@@ -1,39 +1,48 @@
1 ### Client API
2 ##### from g4f (beta)
1 ```
2 ### G4F Client API Documentation (Beta Version)
3
4 #### Introduction
5
6 The G4F Client API introduces a new way to integrate advanced AI functionalities into your Python applications. This guide will help you transition from using the OpenAI client to the new G4F Client, offering compatibility with the existing OpenAI API alongside additional features.
7
8 #### Getting Started
3 9
4 #### Start
5 This new client could:
10 **Switching to G4F Client:**
6 11
12 Replace the OpenAI client import statement in your Python code as follows:
13
14 Old Import:
7 15 ```python
8 from g4f.client import Client
16 from openai import OpenAI
9 17 ```
10 replaces this:
11 18
19 New Import:
12 20 ```python
13 from openai import OpenAI
21 from g4f.client import Client
14 22 ```
15 in your Python Code.
16 23
17 New client have the same API as OpenAI.
24 The G4F Client maintains the same API interface as OpenAI, ensuring a seamless transition.
18 25
19 #### Client
26 #### Initializing the Client
20 27
21 Create the client with custom providers:
28 To use the G4F Client, create an instance with customized providers:
22 29
23 30 ```python
24 31 from g4f.client import Client
25 from g4f.Provider import BingCreateImages, OpenaiChat, Gemini
32 from g4f.providers import BingCreateImages, OpenaiChat, Gemini
26 33
27 34 client = Client(
28 provider=OpenaiChat,
35 text_provider=OpenaiChat,
29 36 image_provider=Gemini,
30 37 proxies=None
31 38 )
32 39 ```
33 40
34 #### Examples
41 #### Usage Examples
42
43 **Text Completions:**
35 44
36 Use the ChatCompletions:
45 You can use the `ChatCompletions` endpoint to generate text completions as follows:
37 46
38 47 ```python
39 48 stream = client.chat.completions.create(
@@ -42,35 +51,44 @@ stream = client.chat.completions.create(
42 51 stream=True,
43 52 )
44 53 for chunk in stream:
45 if chunk.choices[0].delta.content is not None:
54 if chunk.choices[0].delta.content:
46 55 print(chunk.choices[0].delta.content, end="")
47 56 ```
48 57
49 Or use it for creating a image:
58 **Image Generation:**
59
60 Generate images using a specified prompt:
61
50 62 ```python
51 63 response = client.images.generate(
52 model="dall-e-3",
53 prompt="a white siamese cat",
54 ...
64 model="dall-e-3",
65 prompt="a white siamese cat",
66 ...
55 67 )
56 68
57 69 image_url = response.data[0].url
58 70 ```
59 71
60 Also this works with the client:
72 **Creating Image Variations:**
73
74 Create variations of an existing image:
75
61 76 ```python
62 77 response = client.images.create_variation(
63 image=open("cat.jpg", "rb")
64 model="bing",
65 ...
78 image=open("cat.jpg", "rb"),
79 model="bing",
80 ...
66 81 )
67 82
68 83 image_url = response.data[0].url
69 84 ```
70 85
71 Orginal / Variant:
86 #### Visual Examples
87
88 Original / Variant:
72 89
73 [![Image with cat](/docs/cat.jpeg)](/docs/client.md)
74 [![Image with cat](/docs/cat.webp)](/docs/client.md)
90 [![Original Image](/docs/cat.jpeg)](/docs/client.md)
91 [![Variant Image](/docs/cat.webp)](/docs/client.md)
75 92
76 [to Home](/docs/client.md)
93 [Return to Documentation Home](/)
94 ```