Skip to content

[WIP] ChatToolTemplate#1

Open
AguirreNicolas wants to merge 8 commits intotools_guidedfrom
chat_request_templates
Open

[WIP] ChatToolTemplate#1
AguirreNicolas wants to merge 8 commits intotools_guidedfrom
chat_request_templates

Conversation

@AguirreNicolas
Copy link
Copy Markdown
Collaborator

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

  • [New] Added ChatToolTemplate into ChatCompletionRequest. ChatToolTemplate is formed by function_list, force_call and position.

Tools

  • [Change] Methods inject_prompt and render_toolslist from ToolsCallsTemplate to handler ChatToolTemplate request.
  • [Change] Example file tool_template.jinja mas modified render prefix and suffix for both function_list and `force_call

Details

Currently the way the inject_prompt is defined is monolithic and happens only based on the server's configuration. The server renders its tool_templates.jinja file based on the first message of the request. The rendering of the injected text occurs in two ways.

  • A list of functions to choose from is passed, and tool_choise is auto or not defined --> hereafter function_list.
  • The choice of a function is biased/forced by passing to tool_choise the function name function ---> hereafter force_call.

In order to consider also the dynamic definition of the template according to the request, a new class ChatToolTemplate has been added to ChatCompletionRequest. The latter is composed of the position of the injected text, function_list and forced call templates, indicating the ways to inject the tool prompt.
Both templates in turn are of a new class, ToolTemplates, composed by prefix and suffix.

With all the above components the inject_prompt and render_toolslist from ToolsCallsTemplate methods are modified.

inject_prompt

Modification so that inject_prompt considers the position of the text to inject. Default is top, according to Florian's implementation.

render_toolslist

In this function lies the main change. The logic is the same whether the branch is function_list or force_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/prefix variables.

Note: The suffix/prefix variables can render the func_call_token when passed using "{{func_call_token}}" inside the tool templates in the request.

Example:

Considering the example in examples/openai_tools_calls.py, the client request creation can me modified as:

    response = client.chat.completions.create(
        model="model_name",
        messages=messages,
        tools=tools,
        tool_choice="auto",  # auto is default, but we'll be explicit
        extra_body={
            "tool_templates":{
                "function_list":{
                "prefix":"testing_list_prefix",
                "suffix":f"This is the end of the suffix, this is how to call the function call token: {{{{func_call_token}}}}"
                },
                "force_call":{
                "prefix":"testing_force_prefix",
                "suffix":"testing_force_suffix"
                },
                "position": "bottom" # or "top" as default
            },
            "top_k":20,
        }
    )

ChatToolTemplate

@AguirreNicolas AguirreNicolas changed the title ChatToolTemplate ]ChatToolTemplate Jan 24, 2024
@AguirreNicolas AguirreNicolas changed the title ]ChatToolTemplate [WIP] ChatToolTemplate Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant