history_openai_format = []
for human, assistant in history[:-1]:
history_openai_format.append({"role": "user", "content": human})
history_openai_format.append({"role": "assistant", "content": assistant})
history_openai_format.append({"role": "user", "content": history[-1][0]})
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
completion = client.chat.completions.create(
messages=history_openai_format,
for chunk in completion:
history[-1][1] += chunk.choices[0].delta.content