Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary Change:
The objective of this PR is to allow the definition of the tooling templates by the client at the time of the
request.Prototype
ChatToolTemplateintoChatCompletionRequest.ChatToolTemplateis formed byfunction_list,force_callandposition.Tools
inject_promptandrender_toolslistfromToolsCallsTemplateto handlerChatToolTemplaterequest.tool_template.jinjamas modified renderprefixandsuffixfor bothfunction_listand `force_callDetails
Currently the way the
inject_promptis defined is monolithic and happens only based on the server's configuration. The server renders itstool_templates.jinjafile based on the first message of therequest. The rendering of the injected text occurs in two ways.tool_choiseisautoor not defined --> hereafterfunction_list.tool_choisethe function name function ---> hereafterforce_call.In order to consider also the dynamic definition of the template according to the
request, a new classChatToolTemplatehas been added toChatCompletionRequest. The latter is composed of thepositionof the injected text,function_listandforced calltemplates, indicating the ways to inject the tool prompt.Both templates in turn are of a new class,
ToolTemplates, composed byprefixandsuffix.With all the above components the
inject_promptandrender_toolslistfromToolsCallsTemplatemethods are modified.inject_promptModification so that
inject_promptconsiders thepositionof the text to inject. Default istop, according to Florian's implementation.render_toolslistIn this function lies the main change. The logic is the same whether the branch is
function_listorforce_call.If any suffix or prefix is defined in the request, it is passed to the template when rendering the
tool_template.jinja.Also, tool_template.jinja was modified as follows.
Each of the prompts defined by Florian are used as default when the renderer does not send
suffix/prefixvariables.Note: The
suffix/prefixvariables can render thefunc_call_tokenwhen passed using"{{func_call_token}}"inside the tool templates in therequest.Example:
Considering the example in
examples/openai_tools_calls.py, the client request creation can me modified as: