Good to know: depending on the product you're building, it can be useful to explicitly document use cases. Got a product that can be used by a bunch of people in different ways? Maybe consider splitting it out!
Python example:
import openai # openai==0.28
openai.api_key = "sk_xxx" # Your API token
openai.api_base = "https://neuroapi.host/v1" # Our API Endpoint
def main():
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "write a poem about a tree"}],
stream=True,
)
if isinstance(chat_completion, dict):
# not stream
print(chat_completion.choices[0].message.content)
else:
# stream
for token in chat_completion:
content = token["choices"][0]["delta"].get("content")
if content != None:
print(content, end="", flush=True)
if __name__ == "__main__":
main()