summaryrefslogtreecommitdiffstats
path: root/docs/client.md
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-02-12 12:08:26 +0100
committerGitHub <noreply@github.com>2024-02-12 12:08:26 +0100
commitdd5478636460560bd6538c6b08a81c92d61b6595 (patch)
tree128a4681385f6f1adc8bee8cf745affc0103d204 /docs/client.md
parentMerge pull request #1577 from hlohaus/openai (diff)
parentAdd variant example (diff)
downloadgpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.tar
gpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.tar.gz
gpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.tar.bz2
gpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.tar.lz
gpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.tar.xz
gpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.tar.zst
gpt4free-dd5478636460560bd6538c6b08a81c92d61b6595.zip
Diffstat (limited to 'docs/client.md')
-rw-r--r--docs/client.md77
1 files changed, 77 insertions, 0 deletions
diff --git a/docs/client.md b/docs/client.md
new file mode 100644
index 00000000..deb5b0ba
--- /dev/null
+++ b/docs/client.md
@@ -0,0 +1,77 @@
+### Client API
+##### from g4f (beta)
+
+#### Start
+This new client could:
+
+```python
+from g4f.client import Client
+```
+replaces this:
+
+```python
+from openai import OpenAI
+```
+in your Python Code.
+
+New client have the same API as OpenAI.
+
+#### Client
+
+Create the client with custom providers:
+
+```python
+from g4f.client import Client
+from g4f.Provider import BingCreateImages, OpenaiChat, Gemini
+
+client = Client(
+ provider=OpenaiChat,
+ image_provider=Gemini,
+ proxies=None
+)
+```
+
+#### Examples
+
+Use the ChatCompletions:
+
+```python
+stream = client.chat.completions.create(
+ model="gpt-4",
+ messages=[{"role": "user", "content": "Say this is a test"}],
+ stream=True,
+)
+for chunk in stream:
+ if chunk.choices[0].delta.content is not None:
+ print(chunk.choices[0].delta.content, end="")
+```
+
+Or use it for creating a image:
+```python
+response = client.images.generate(
+ model="dall-e-3",
+ prompt="a white siamese cat",
+ ...
+)
+
+image_url = response.data[0].url
+```
+
+Also this works with the client:
+```python
+response = client.images.create_variation(
+ image=open('cat.jpg')
+ model="bing",
+ ...
+)
+
+image_url = response.data[0].url
+```
+
+Orginal:
+[![Image with cat](/docs/cat.jpeg)](/docs/client.md)
+
+Variant:
+[![Image with cat](/docs/cat.webp)](/docs/client.md)
+
+[to Home](/docs/client.md)