import os from langchain.chat_models import ChatOpenAI from langchain.schema import ( AIMessage, HumanMessage, SystemMessage )
# 公司的key
os.environ["OPENAI_API_KEY"] = '70846324f01c4e5cb3cc11da28a1e091' os.environ["OPENAI_API_BASE"] = 'https://opencatgpt.openai.azure.com/' os.environ["OPENAI_API_TYPE"] = 'azure' os.environ["OPENAI_API_VERSION"] = '2023-05-15' chat = ChatOpenAI(model_name="gpt-35-turbo", engine="gpt-35-turbo") history = [SystemMessage(content="你是一个聊天机器人,请回答下列问题。\n")] while True: question = input("请输入问题:\n") history.append(HumanMessage(content=question)) res = chat(history) print(res.content) history.append(res)