chat-robot 取消性别传入,从用户输入中提取性别

This commit is contained in:
2025-04-23 11:51:53 +08:00
parent f68b5a9f04
commit b8fe29e735
4 changed files with 41 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ from app.core.config import *
from app.service.chat_robot.script.callbacks.qwen_callback_handler import QWenCallbackHandler
from app.service.chat_robot.script.database import CustomDatabase
from app.service.chat_robot.script.prompt import FASHION_CHAT_BOT_PREFIX, TOOLS_FUNCTIONS_SUFFIX, TUTORIAL_TOOL_RETURN, \
GET_LANGUAGE_PREFIX
GET_LANGUAGE_PREFIX, FASHION_CHAT_BOT_PREFIX_TEMP
from app.service.search_image_with_text.service import query
get_database_table_description = "Input is an empty string, output is a comma separated list of tables in the database."
@@ -212,14 +212,15 @@ def get_assistant_response(messages):
return response
def call_with_messages(message, gender):
def call_with_messages(message):
global tool_info
user_input = message
print('\n')
messages = [
{
"content": FASHION_CHAT_BOT_PREFIX, # 系统message
# "content": FASHION_CHAT_BOT_PREFIX, # 系统message
"content": FASHION_CHAT_BOT_PREFIX_TEMP, # 修改后的系统message
"role": "system"
},
{
@@ -255,7 +256,7 @@ def call_with_messages(message, gender):
tool_info = {"name": "search_from_internet", "role": "tool"}
content = json.loads(assistant_output.tool_calls[0]['function']['arguments'])
message = [
{'role': 'assistant', 'content': content['query']}
{'role': 'assistant', 'content': content['query'] if "query" in content.keys() else user_input}
]
tool_info['content'] = search_from_internet(message)
flag = False
@@ -282,6 +283,8 @@ def call_with_messages(message, gender):
result_content = tool_info['content']
elif assistant_output.tool_calls[0]['function']['name'] == 'get_image_from_vector_db':
content = json.loads(assistant_output.tool_calls[0]['function']['arguments'])
# todo 从历史对话中获取性别目前无法获得性别时默认使用female
gender = content['gender'] if "gender" in content.keys() and content['gender'] != 'unisex' else 'female'
tool_info = {"name": "get_image_from_vector_db", "role": "tool",
'content': get_image_from_vector_db(gender, content['parameters']['content'] if "parameters" in content.keys() else content['content'])}
flag = False