Skip to content

Commit

Permalink
add examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
xtekky committed Apr 16, 2024
1 parent fdbb474 commit fb4ef40
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/openaichat.py
Original file line number Diff line number Diff line change
@@ -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 "")

0 comments on commit fb4ef40

Please sign in to comment.