最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

python代碼

2023-06-13 13:45 作者:岑今6666  | 我要投稿

#.env內(nèi)容為API_KEY=sk-寫(xiě)自己的

import openai

from dotenv import dotenv_values


class ChatBox:

? ? def __init__(self):

? ? ? ? config = dotenv_values(".env")

? ? ? ? openai.api_key = config["API_KEY"]

? ? ? ? self.model = "text-davinci-003"

? ? ? ? self.chat_history = []


? ? def add_chat(self, message):

? ? ? ? response = openai.Completion.create(

? ? ? ? ? ? model=self.model,

? ? ? ? ? ? prompt=message,

? ? ? ? ? ? max_tokens=200

? ? ? ? )

? ? ? ? answer = response.choices[0].text.strip()

? ? ? ? self.chat_history.append((message, answer))

? ? ? ? return answer


? ? def get_chat_history(self):

? ? ? ? return self.chat_history


? ? def clear_chat_history(self):

? ? ? ? self.chat_history = []

chatbox = ChatBox()


while True:

? ? user_input = input("User: ")

? ? if user_input.lower() == "exit":

? ? ? ? break

? ? answer = chatbox.add_chat(user_input)

? ? print("ChatGPT:", answer)


python代碼的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
金山区| 巴里| 英吉沙县| 侯马市| 望江县| 图们市| 宝清县| 万荣县| 石首市| 阜南县| 天津市| 苍梧县| 乐陵市| 任丘市| 华宁县| 开封市| 徐汇区| 三穗县| 肥东县| 阿拉尔市| 竹溪县| 仪陇县| 呼伦贝尔市| 江门市| 武强县| 湘阴县| 吉木萨尔县| 绥宁县| 哈巴河县| 崇义县| 会泽县| 介休市| 武陟县| 五家渠市| 齐河县| 靖安县| 海南省| 西和县| 平山县| 五大连池市| 遂溪县|