Tools support for OpenAI compatible API (#6827)

This commit is contained in:
Jonas 2025-05-08 17:30:27 +02:00 committed by GitHub
parent ed6e16191d
commit fa960496d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 209 additions and 17 deletions

View file

@ -145,7 +145,7 @@ def generate_chat_prompt(user_input, state, **kwargs):
instruct_renderer = partial(
instruction_template.render,
builtin_tools=None,
tools=None,
tools=state['tools'] if 'tools' in state else None,
tools_in_user_message=False,
add_generation_prompt=False
)
@ -171,9 +171,13 @@ def generate_chat_prompt(user_input, state, **kwargs):
messages.append({"role": "system", "content": context})
insert_pos = len(messages)
for user_msg, assistant_msg in reversed(history):
user_msg = user_msg.strip()
assistant_msg = assistant_msg.strip()
for entry in reversed(history):
user_msg = entry[0].strip()
assistant_msg = entry[1].strip()
tool_msg = entry[2].strip() if len(entry) > 2 else ''
if tool_msg:
messages.insert(insert_pos, {"role": "tool", "content": tool_msg})
if assistant_msg:
messages.insert(insert_pos, {"role": "assistant", "content": assistant_msg})