From 17a5eb2f2e8b222782b8076212bb917a197710b5 Mon Sep 17 00:00:00 2001 From: Marc Nickert Date: Sun, 19 Jan 2025 16:27:59 +0100 Subject: [PATCH] Fix empty tool and Test current data --- lib/utils/chat_templates.ex | 2 +- test/utils/chat_templates_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils/chat_templates.ex b/lib/utils/chat_templates.ex index 97bbbef5..5595a83f 100644 --- a/lib/utils/chat_templates.ex +++ b/lib/utils/chat_templates.ex @@ -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} -> diff --git a/test/utils/chat_templates_test.exs b/test/utils/chat_templates_test.exs index 5943d5bd..52aa0461 100644 --- a/test/utils/chat_templates_test.exs +++ b/test/utils/chat_templates_test.exs @@ -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 => ` a JSON dict with the function argument name as key and function argument value as value.\nend_tag => ``\n\nHere is an example,\n{\"example_name\": \"example_value\"}\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 => ` a JSON dict with the function argument name as key and function argument value as value.\nend_tag => ``\n\nHere is an example,\n{\"example_name\": \"example_value\"}\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!( @@ -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!(