GianJSX's picture
Duplicate from zej97/AI-Research-Assistant
cc93c47
raw
history blame
599 Bytes
import openai
openai.api_key = "sk-DQ1nFYzAVzGMznofdi0nig7MebfA9PWrTxCHlLIZIqc4X8xu"
openai.api_base = "https://api.chatanywhere.cn/v1"
def generator():
messages = [{
"role": "user",
"content": "What is the meaning of life?",
}]
response = ""
for chunk in openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0.9,
stream=True,
):
content = chunk["choices"][0].get("delta", {}).get("content")
if content:
response += content
yield response