修复composite_demo中的openai client 缺失system_prompt的问题
This commit is contained in:
parent
6c6d4637fb
commit
bee81e673c
|
@ -37,10 +37,10 @@ class Client(Protocol):
|
||||||
|
|
||||||
def process_input(history: list[dict], tools: list[dict], role_name_replace:dict=None) -> list[dict]:
|
def process_input(history: list[dict], tools: list[dict], role_name_replace:dict=None) -> list[dict]:
|
||||||
chat_history = []
|
chat_history = []
|
||||||
if len(tools) > 0:
|
#if len(tools) > 0:
|
||||||
chat_history.append(
|
chat_history.append(
|
||||||
{"role": "system", "content": build_system_prompt(list(ALL_TOOLS), tools)}
|
{"role": "system", "content": build_system_prompt(list(ALL_TOOLS), tools)}
|
||||||
)
|
)
|
||||||
|
|
||||||
for conversation in history:
|
for conversation in history:
|
||||||
role = str(conversation.role).removeprefix("<|").removesuffix("|>")
|
role = str(conversation.role).removeprefix("<|").removesuffix("|>")
|
||||||
|
|
|
@ -43,12 +43,12 @@ class APIClient(Client):
|
||||||
history: list[Conversation],
|
history: list[Conversation],
|
||||||
**parameters,
|
**parameters,
|
||||||
) -> Generator[tuple[str | dict, list[dict]]]:
|
) -> Generator[tuple[str | dict, list[dict]]]:
|
||||||
chat_history = process_input(history, tools)
|
chat_history = process_input(history, '', role_name_replace=self.role_name_replace)
|
||||||
messages = process_input(history, '', role_name_replace=self.role_name_replace)
|
#messages = process_input(history, '', role_name_replace=self.role_name_replace)
|
||||||
openai_tools = format_openai_tool(tools)
|
openai_tools = format_openai_tool(tools)
|
||||||
response = self.client.chat.completions.create(
|
response = self.client.chat.completions.create(
|
||||||
model="glm-4",
|
model="glm-4",
|
||||||
messages=messages,
|
messages=chat_history,
|
||||||
tools=openai_tools,
|
tools=openai_tools,
|
||||||
stream=self.use_stream,
|
stream=self.use_stream,
|
||||||
max_tokens=parameters["max_new_tokens"],
|
max_tokens=parameters["max_new_tokens"],
|
||||||
|
|
|
@ -30,7 +30,8 @@ def build_system_prompt(
|
||||||
):
|
):
|
||||||
value = SELFCOG_PROMPT
|
value = SELFCOG_PROMPT
|
||||||
value += "\n\n" + datetime.now().strftime(DATE_PROMPT)
|
value += "\n\n" + datetime.now().strftime(DATE_PROMPT)
|
||||||
value += "\n\n# 可用工具"
|
if enabled_tools or functions:
|
||||||
|
value += "\n\n# 可用工具"
|
||||||
contents = []
|
contents = []
|
||||||
for tool in enabled_tools:
|
for tool in enabled_tools:
|
||||||
contents.append(f"\n\n## {tool}\n\n{TOOL_SYSTEM_PROMPTS[tool]}")
|
contents.append(f"\n\n## {tool}\n\n{TOOL_SYSTEM_PROMPTS[tool]}")
|
||||||
|
|
Loading…
Reference in New Issue