summaryrefslogtreecommitdiffstats
path: root/etc/examples/openaichat.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-20 20:12:36 +0200
committerGitHub <noreply@github.com>2024-04-20 20:12:36 +0200
commitda81d1e51aa5c625e4107bf8148cdb3c778f4001 (patch)
tree01b7677bfd51667e6b8bebe0ac72921aa48cba58 /etc/examples/openaichat.py
parentMerge pull request #1862 from hlohaus/nem (diff)
parentDisable Bing integration test (diff)
downloadgpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.gz
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.bz2
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.lz
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.xz
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.tar.zst
gpt4free-da81d1e51aa5c625e4107bf8148cdb3c778f4001.zip
Diffstat (limited to 'etc/examples/openaichat.py')
-rw-r--r--etc/examples/openaichat.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/etc/examples/openaichat.py b/etc/examples/openaichat.py
new file mode 100644
index 00000000..291daa2c
--- /dev/null
+++ b/etc/examples/openaichat.py
@@ -0,0 +1,23 @@
+from g4f.client import Client
+from g4f.Provider import OpenaiChat, RetryProvider
+
+# compatible countries: https://pastebin.com/UK0gT9cn
+client = Client(
+ proxies = {
+ 'http': 'http://username:password@host:port', # MUST BE WORKING OPENAI COUNTRY PROXY ex: USA
+ 'https': 'http://username:password@host:port' # MUST BE WORKING OPENAI COUNTRY PROXY ex: USA
+ },
+ provider = RetryProvider([OpenaiChat],
+ single_provider_retry=True, max_retries=5)
+)
+
+messages = [
+ {'role': 'user', 'content': 'Hello'}
+]
+
+response = client.chat.completions.create(model='gpt-3.5-turbo',
+ messages=messages,
+ stream=True)
+
+for message in response:
+ print(message.choices[0].delta.content or "") \ No newline at end of file