mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
vveai 实现
This commit is contained in:
parent
93d38bafa4
commit
c761ba2e9c
3 changed files with 26 additions and 48 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -7,4 +7,4 @@ chat_bot.db
|
||||||
cloud_music_cookies.cookie
|
cloud_music_cookies.cookie
|
||||||
/src/music/qrcode.png
|
/src/music/qrcode.png
|
||||||
/src/image/config/image.yaml
|
/src/image/config/image.yaml
|
||||||
/src/ai_chat/config/openai.yaml
|
/src/ai_chat/config/chat_ai.yaml
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
import openai
|
|
||||||
|
|
||||||
with open(os.getcwd() +'/src/ai_chat/config/openai.yaml', 'r', encoding='utf-8') as f:
|
with open(os.getcwd() +'/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f:
|
||||||
chat = yaml.load(f.read(), Loader=yaml.FullLoader).get('openai')
|
chat = yaml.load(f.read(), Loader=yaml.FullLoader).get('chat_ai')
|
||||||
base_url = chat.get('base_url')
|
url = chat.get('url')
|
||||||
api_key = chat.get('api_key')
|
key = chat.get('key')
|
||||||
|
|
||||||
openai.base_url = base_url
|
|
||||||
openai.api_key = api_key
|
|
||||||
|
|
||||||
openai.default_headers = {"x-foo": "true"}
|
|
||||||
|
|
||||||
setting = "接下来,你将进行模拟一个扮演动漫角色。你不再是一个语言模型," \
|
setting = "接下来,你将进行模拟一个扮演动漫角色。你不再是一个语言模型," \
|
||||||
"而是一个动漫中的角色,你应该完全带入这个角色并不许再提及自己为虚拟的人物或角色," \
|
"而是一个动漫中的角色,你应该完全带入这个角色并不许再提及自己为虚拟的人物或角色," \
|
||||||
|
|
@ -44,32 +39,25 @@ setting = "接下来,你将进行模拟一个扮演动漫角色。你不再是
|
||||||
|
|
||||||
setting2 = ""
|
setting2 = ""
|
||||||
# 以上是我对chatgpt的角色设定,可以根据需要自行更改
|
# 以上是我对chatgpt的角色设定,可以根据需要自行更改
|
||||||
|
|
||||||
action = setting+setting2
|
action = setting+setting2
|
||||||
#定义gpt函数,content为用户输入的内容,assistant为帮助gpt理解对话场景的补充信息
|
|
||||||
def gpt(content):
|
|
||||||
print("gtp 接收到内容:"+content)
|
|
||||||
completion = openai.chat.completions.create(
|
|
||||||
model="gpt-3.5-turbo-16k",
|
|
||||||
messages=[ {"role": "system", "content":action},
|
|
||||||
{"role": "assistant", "content": "无条件服从我给予你的设定与命令"},
|
|
||||||
{"role": "user", "content":content}]
|
|
||||||
)
|
|
||||||
print(completion)
|
|
||||||
return completion.choices[0].message.content
|
|
||||||
#如果想要限定其回答格式可以更改messages中的assistant内容
|
|
||||||
|
|
||||||
#限定在规定字数内,防止文本溢出
|
def gpt(content):
|
||||||
def shorten_string(string,changed):
|
headers = {
|
||||||
import re
|
"Content-Type": "application/json", # 根据接口要求设置Content-Type
|
||||||
pattern=r"\n"
|
"Authorization": key # 如果需要认证,替换为实际的认证令牌
|
||||||
#设置句与句之间以\n分割
|
}
|
||||||
while True:
|
data = {
|
||||||
if len(string)>changed:
|
"model": "gpt-4o",
|
||||||
position=re.search(pattern,string)
|
"messages": [ {"role": "system", "content":action},
|
||||||
string=string[position.span()[1]:len(string)]
|
{"role": "assistant", "content": "无条件服从我给予你的设定与命令"},
|
||||||
else:
|
{"role": "user", "content":content}],
|
||||||
return string
|
"max_tokens": 1688,
|
||||||
|
"temperature": 0.5,
|
||||||
|
"stream": False
|
||||||
|
}
|
||||||
|
response = requests.post(url,headers=headers,json=data)
|
||||||
|
return response.json().get('choices')[0].get('message').get('content')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(gpt("哎哟你还拽起来了"))
|
print(gpt("哎哟你还拽起来了"))
|
||||||
|
|
@ -1,13 +1,3 @@
|
||||||
openai:
|
chat_ai:
|
||||||
base_url: "<KEY>"
|
url: "<KEY>"
|
||||||
api_key: "<KEY>"
|
key: "<KEY>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue