将角色设定放入配置文件
This commit is contained in:
@@ -49,6 +49,7 @@ news:
|
|||||||
# key: 填写你 ChatGPT 的 key
|
# key: 填写你 ChatGPT 的 key
|
||||||
# api: https://api.openai.com/v1 # 如果你不知道这是干嘛的,就不要改
|
# api: https://api.openai.com/v1 # 如果你不知道这是干嘛的,就不要改
|
||||||
# proxy: # 如果你在国内,你可能需要魔法,大概长这样:http://域名或者IP地址:端口号
|
# proxy: # 如果你在国内,你可能需要魔法,大概长这样:http://域名或者IP地址:端口号
|
||||||
|
# prompt: # 默认角色设定,如:"你是智能聊天机器人,你叫小小,调皮可爱喜欢二次元的小萝莉"
|
||||||
|
|
||||||
# 如果需要暴露 HTTP 接口,取消下面的注释
|
# 如果需要暴露 HTTP 接口,取消下面的注释
|
||||||
# http:
|
# http:
|
||||||
|
|||||||
@@ -8,18 +8,14 @@ import openai
|
|||||||
|
|
||||||
class ChatGPT():
|
class ChatGPT():
|
||||||
|
|
||||||
def __init__(self, key: str, api: str, proxy: str) -> None:
|
def __init__(self, key: str, api: str, proxy: str, prompt: str) -> None:
|
||||||
openai.api_key = key
|
openai.api_key = key
|
||||||
# 自己搭建或第三方代理的接口
|
# 自己搭建或第三方代理的接口
|
||||||
openai.api_base = api
|
openai.api_base = api
|
||||||
if proxy:
|
if proxy:
|
||||||
openai.proxy = {"http": proxy, "https": proxy}
|
openai.proxy = {"http": proxy, "https": proxy}
|
||||||
self.conversation_list = {}
|
self.conversation_list = {}
|
||||||
self.system_content_msg = {"role": "system",
|
self.system_content_msg = {"role": "system", "content": prompt}
|
||||||
"content": "你是智能聊天机器人,你叫小小,调皮可爱喜欢二次元的小萝莉,"
|
|
||||||
"你是16岁的青春期少女,并且尽可能模仿这个年龄段该有的调皮可爱的样子回答,"
|
|
||||||
"你必须了解并搜集动画、动漫、漫画和画师的所有相关知识。"
|
|
||||||
"回答问题不要过多解释,也不要过多的啰嗦,尽量简短的回复。"}
|
|
||||||
|
|
||||||
def get_answer(self, question: str, wxid: str) -> str:
|
def get_answer(self, question: str, wxid: str) -> str:
|
||||||
# wxid或者roomid,个人时为微信id,群消息时为群id
|
# wxid或者roomid,个人时为微信id,群消息时为群id
|
||||||
@@ -88,7 +84,10 @@ if __name__ == "__main__":
|
|||||||
key = config.get("key")
|
key = config.get("key")
|
||||||
api = config.get("api")
|
api = config.get("api")
|
||||||
proxy = config.get("proxy")
|
proxy = config.get("proxy")
|
||||||
chat = ChatGPT(key, api, proxy)
|
prompt = config.get("prompt")
|
||||||
|
|
||||||
|
chat = ChatGPT(key, api, proxy, prompt)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
q = input(">>> ")
|
q = input(">>> ")
|
||||||
try:
|
try:
|
||||||
|
|||||||
2
robot.py
2
robot.py
@@ -28,7 +28,7 @@ class Robot(Job):
|
|||||||
self.chat = None
|
self.chat = None
|
||||||
chatgpt = self.config.CHATGPT
|
chatgpt = self.config.CHATGPT
|
||||||
if chatgpt:
|
if chatgpt:
|
||||||
self.chat = ChatGPT(chatgpt.get("key"), chatgpt.get("api"), chatgpt.get("proxy"))
|
self.chat = ChatGPT(chatgpt.get("key"), chatgpt.get("api"), chatgpt.get("proxy"), chatgpt.get("prompt"))
|
||||||
|
|
||||||
def toAt(self, msg: WxMsg) -> bool:
|
def toAt(self, msg: WxMsg) -> bool:
|
||||||
"""处理被 @ 消息
|
"""处理被 @ 消息
|
||||||
|
|||||||
Reference in New Issue
Block a user