diff options
author | abc <98614666+xtekky@users.noreply.github.com> | 2024-04-16 09:58:49 +0200 |
---|---|---|
committer | abc <98614666+xtekky@users.noreply.github.com> | 2024-04-16 09:58:49 +0200 |
commit | fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf (patch) | |
tree | baef9c109958576e4db792b74dc8373c24bf0a32 /examples/openaichat.py | |
parent | some more logging (diff) | |
download | gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.tar gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.tar.gz gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.tar.bz2 gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.tar.lz gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.tar.xz gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.tar.zst gpt4free-fb4ef40a233ee4621fc45dc94e0f14f96a00a7cf.zip |
Diffstat (limited to 'examples/openaichat.py')
-rw-r--r-- | examples/openaichat.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/openaichat.py b/examples/openaichat.py new file mode 100644 index 00000000..291daa2c --- /dev/null +++ b/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 |