chat_bot_opencat.py 723 字节
Newer Older
1 2 3 4 5 6 7 8
import os
from langchain.chat_models import ChatOpenAI
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)

9
# 公司的key
10 11 12 13 14 15 16 17 18 19 20 21 22 23
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)