gpt4free/example_server.py

18 行
547 B
Python
Raw 通常表示 履歴

2023-06-06 17:46:22 +09:00
import openai
import sys
2023-06-06 18:16:23 +09:00
openai.api_key = ""
openai.api_base = "http://127.0.0.1:1337"
2023-06-06 17:46:22 +09:00
chat_completion = openai.ChatCompletion.create(stream=True,
2023-06-06 18:16:23 +09:00
model="gpt-3.5-turbo",
messages=[{"role": "user",
"content": "Write a poem about a tree."}])
2023-06-06 17:46:22 +09:00
for token in chat_completion:
2023-06-06 18:16:23 +09:00
content = token["choices"][0]["delta"].get("content")
2023-06-06 17:46:22 +09:00
if content is not None:
print(content, end="")
sys.stdout.flush()