无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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ó)家法律
南宁市| 磴口县| 临邑县| 武平县| 兴义市| 太仆寺旗| 广宁县| 罗城| 天台县| 和顺县| 基隆市| 蒙阴县| 芮城县| 云霄县| 白银市| 莲花县| 景东| 左权县| 北川| 庆云县| 五大连池市| 银川市| 藁城市| 繁昌县| 临沂市| 镇赉县| 罗田县| 唐河县| 衡阳县| 陆丰市| 微山县| 中牟县| 鄄城县| 新余市| 宿迁市| 新宾| 嵊泗县| 新绛县| 桑植县| 晋中市| 巨野县|