mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 03:16:14 +00:00
Merge pull request #599 from RockChinQ/refactor/modern-openai-api-style
Refactor: 修改 情景预设 置入风格
This commit is contained in:
+1
-1
@@ -114,7 +114,7 @@ admin_qq = 0
|
|||||||
#
|
#
|
||||||
# 还可以加载文件中的预设文字,使用方法请查看:https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E9%A2%84%E8%AE%BE%E6%96%87%E5%AD%97
|
# 还可以加载文件中的预设文字,使用方法请查看:https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E9%A2%84%E8%AE%BE%E6%96%87%E5%AD%97
|
||||||
default_prompt = {
|
default_prompt = {
|
||||||
"default": "如果我之后想获取帮助,请你说“输入!help获取帮助”",
|
"default": "如果用户之后想获取帮助,请你说“输入!help获取帮助”。",
|
||||||
}
|
}
|
||||||
|
|
||||||
# 情景预设格式
|
# 情景预设格式
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@
|
|||||||
"switch_strategy": "active",
|
"switch_strategy": "active",
|
||||||
"admin_qq": 0,
|
"admin_qq": 0,
|
||||||
"default_prompt": {
|
"default_prompt": {
|
||||||
"default": "如果我之后想获取帮助,请你说“输入!help获取帮助”"
|
"default": "如果用户之后想获取帮助,请你说“输入!help获取帮助”。"
|
||||||
},
|
},
|
||||||
"preset_mode": "normal",
|
"preset_mode": "normal",
|
||||||
"response_rules": {
|
"response_rules": {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class RequestBase:
|
|||||||
|
|
||||||
def _req(self, **kwargs):
|
def _req(self, **kwargs):
|
||||||
"""处理代理问题"""
|
"""处理代理问题"""
|
||||||
|
logging.debug("请求接口参数: %s", str(kwargs))
|
||||||
import config
|
import config
|
||||||
|
|
||||||
ret = self.req_func(**kwargs)
|
ret = self.req_func(**kwargs)
|
||||||
|
|||||||
+3
-17
@@ -16,10 +16,6 @@ import os
|
|||||||
# __scenario_from_files__ = {}
|
# __scenario_from_files__ = {}
|
||||||
|
|
||||||
|
|
||||||
__universal_first_reply__ = "ok, I'll follow your commands."
|
|
||||||
"""通用首次回复"""
|
|
||||||
|
|
||||||
|
|
||||||
class ScenarioMode:
|
class ScenarioMode:
|
||||||
"""情景预设模式抽象类"""
|
"""情景预设模式抽象类"""
|
||||||
|
|
||||||
@@ -66,17 +62,13 @@ class NormalScenarioMode(ScenarioMode):
|
|||||||
"""普通情景预设模式"""
|
"""普通情景预设模式"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global __universal_first_reply__
|
|
||||||
# 加载config中的default_prompt值
|
# 加载config中的default_prompt值
|
||||||
if type(config.default_prompt) == str:
|
if type(config.default_prompt) == str:
|
||||||
self.using_prompt_name = "default"
|
self.using_prompt_name = "default"
|
||||||
self.prompts = {"default": [
|
self.prompts = {"default": [
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "system",
|
||||||
"content": config.default_prompt
|
"content": config.default_prompt
|
||||||
},{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": __universal_first_reply__
|
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
|
|
||||||
@@ -84,11 +76,8 @@ class NormalScenarioMode(ScenarioMode):
|
|||||||
for key in config.default_prompt:
|
for key in config.default_prompt:
|
||||||
self.prompts[key] = [
|
self.prompts[key] = [
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "system",
|
||||||
"content": config.default_prompt[key]
|
"content": config.default_prompt[key]
|
||||||
},{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": __universal_first_reply__
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -98,11 +87,8 @@ class NormalScenarioMode(ScenarioMode):
|
|||||||
with open(os.path.join("prompts", file), encoding="utf-8") as f:
|
with open(os.path.join("prompts", file), encoding="utf-8") as f:
|
||||||
self.prompts[file] = [
|
self.prompts[file] = [
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "system",
|
||||||
"content": f.read()
|
"content": f.read()
|
||||||
},{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": __universal_first_reply__
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -241,6 +241,7 @@ class Session:
|
|||||||
if event.get_return_value('text_message') is not None:
|
if event.get_return_value('text_message') is not None:
|
||||||
text = event.get_return_value('text_message')
|
text = event.get_return_value('text_message')
|
||||||
|
|
||||||
|
# 裁剪messages到合适长度
|
||||||
prompts, _ = self.cut_out(text, max_length, local_default_prompt, local_prompt)
|
prompts, _ = self.cut_out(text, max_length, local_default_prompt, local_prompt)
|
||||||
|
|
||||||
res_text = ""
|
res_text = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user