Skip to content

Commit

Permalink
Fix empty tool and Test current data
Browse files Browse the repository at this point in the history
  • Loading branch information
marcnnn committed Jan 19, 2025
1 parent af43234 commit 17a5eb2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/utils/chat_templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ end
def llama_3_1_custom_tool_calling_parameter_conversion(tools) do
tools
|> Enum.map(fn %LangChain.Function{name: name, description: description, parameters_schema: schema} ->
props = schema[:properties]
props = schema[:properties] || schema["properties"] || []
parameters =
props
|> Enum.map(fn {param_name, param_config} ->
Expand Down
4 changes: 2 additions & 2 deletions test/utils/chat_templates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ defmodule LangChain.Utils.ChatTemplatesTest do
date = Calendar.strftime(DateTime.utc_now(), "%d %B %Y")

expected =
"<|begin_of_text|>\n<|start_header_id|>system<|end_header_id|>\n\nEnvironment: ipython\nTools:\nCutting Knowledge Date: December 2023\nToday Date: 09 January 2025\n\n# Tool Instructions\n- Always execute python code in messages that you share.\n- When looking for real time information use relevant functions if available\n\nYou have access to the following functions:\n\n\nUse the function 'say_hi' to: Provide a friendly greeting.\n{\n \"n\": {\n \"description\": \"\",\n \"param_type\": \"int\",\n \"required\": false\n }\n}\n\n\n\n\nIf a you choose to call a function ONLY reply in the following format:\n<{start_tag}={function_name}>{parameters}{end_tag}\nwhere\n\nstart_tag => `<function`\nparameters => a JSON dict with the function argument name as key and function argument value as value.\nend_tag => `</function>`\n\nHere is an example,\n<function=example_function_name>{\"example_name\": \"example_value\"}</function>\n\nReminder:\n- Function calls MUST follow the specified format\n- Required parameters MUST be specified\n- Only call one function at a time\n- Put the entire function call reply on one line\n- Always add your sources when using search results to answer the user query\n\nYou are a helpful assistant.system_message<|eot_id|>\n<|start_header_id|>user<|end_header_id|>\n\nuser_prompt<|eot_id|>\n\n\n<|start_header_id|>assistant<|end_header_id|>\n\n"
"<|begin_of_text|>\n<|start_header_id|>system<|end_header_id|>\n\nEnvironment: ipython\nTools:\nCutting Knowledge Date: December 2023\nToday Date: #{date}\n\n# Tool Instructions\n- Always execute python code in messages that you share.\n- When looking for real time information use relevant functions if available\n\nYou have access to the following functions:\n\n\nUse the function 'say_hi' to: Provide a friendly greeting.\n{\n \"n\": {\n \"description\": \"\",\n \"param_type\": \"int\",\n \"required\": false\n }\n}\n\n\n\n\nIf a you choose to call a function ONLY reply in the following format:\n<{start_tag}={function_name}>{parameters}{end_tag}\nwhere\n\nstart_tag => `<function`\nparameters => a JSON dict with the function argument name as key and function argument value as value.\nend_tag => `</function>`\n\nHere is an example,\n<function=example_function_name>{\"example_name\": \"example_value\"}</function>\n\nReminder:\n- Function calls MUST follow the specified format\n- Required parameters MUST be specified\n- Only call one function at a time\n- Put the entire function call reply on one line\n- Always add your sources when using search results to answer the user query\n\nYou are a helpful assistant.system_message<|eot_id|>\n<|start_header_id|>user<|end_header_id|>\n\nuser_prompt<|eot_id|>\n\n\n<|start_header_id|>assistant<|end_header_id|>\n\n"

result =
ChatTemplates.apply_chat_template_with_tools!(
Expand Down Expand Up @@ -898,7 +898,7 @@ defmodule LangChain.Utils.ChatTemplatesTest do
date = Calendar.strftime(DateTime.utc_now(), "%d %B %Y")

expected =
"<|begin_of_text|>\n<|start_header_id|>system<|end_header_id|>\nYou are an expert in composing functions. You are given a question and a set of possible functions.\nBased on the question, you will need to make one or more function/tool calls to achieve the purpose.\nIf none of the functions can be used, point it out. If the given question lacks the parameters required by the function,also point it out. You should only return the function call in tools call sections.\nIf you decide to invoke any of the function(s), you MUST put it in the format of [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]\nYou SHOULD NOT include any other text in the response.\nHere is a list of functions in JSON format that you can invoke.[\n {\n \"description\": \"Provide a friendly greeting.\",\n \"name\": \"say_hi\",\n \"parameters\": {\n \"n\": {\n \"description\": \"\",\n \"param_type\": \"int\",\n \"required\": false\n }\n }\n }\n]system_message<|eot_id|>\n<|start_header_id|>user<|end_header_id|>\n\nuser_prompt<|eot_id|>\n\n\n<|start_header_id|>assistant<|end_header_id|>\n\n"
"<|start_header_id|>system<|end_header_id|>\nYou are an expert in composing functions. You are given a question and a set of possible functions.\nBased on the question, you will need to make one or more function/tool calls to achieve the purpose.\nIf none of the functions can be used, point it out. If the given question lacks the parameters required by the function,also point it out. You should only return the function call in tools call sections.\nIf you decide to invoke any of the function(s), you MUST put it in the format of [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]\nYou SHOULD NOT include any other text in the response.\nHere is a list of functions in JSON format that you can invoke.[\n {\n \"description\": \"Provide a friendly greeting.\",\n \"name\": \"say_hi\",\n \"parameters\": {\n \"n\": {\n \"description\": \"\",\n \"param_type\": \"int\",\n \"required\": false\n }\n }\n }\n]system_message\n<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nuser_prompt<|eot_id|>\n<|start_header_id|>assistant<|end_header_id|>\n\n"

result =
ChatTemplates.apply_chat_template_with_tools!(
Expand Down

0 comments on commit 17a5eb2

Please sign in to comment.