Map Function strict flag and FunctionParam syntax in ChatReqLLM tools#583
Merged
Conversation
- also implements support for mapping FunctionParam syntax
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.
Problem
ChatReqLLM.function_to_req_llm_tool/1only understood one of the two ways aLangChain.Functioncan declare its parameters. It readfun.parameters_schema(the raw JSONSchema map) directly and ignoredfun.parameters— the validatedLangChain.FunctionParamlist form. Any tool defined withFunctionParamstructs was handed to the LLM with an empty (ornil) schema. It also droppedfun.stricton the floor, so strict structured-output tool calling never reached the provider through the ReqLLM backend.Solution
Introduce a private
get_parameter_schema/1inChatReqLLMthat pattern-matches the three parameter cases and produces a correct JSONSchema map in each, mirroringLangChain.ChatModels.ChatOpenAI.get_parameters/1::parametersandnil:parameters_schema→%{"type" => "object", "properties" => %{}}:parameterswith a raw:parameters_schemamap → passthrough:parameterslist ofFunctionParamstructs →FunctionParam.to_parameters_schema/1The tool builder now calls that helper for
parameter_schemaand also passesstrict: fun.strictthrough toReqLLM.Tool.new!/1, so providers that support it (e.g. OpenAI structured outputs) can enforce the schema. This brings the ReqLLM chat model to parity withChatOpenAIfor tool definitions.Changes
lib/chat_models/chat_req_llm.ex— Addedget_parameter_schema/1supporting both:parameters(FunctionParam list) and:parameters_schema(raw map) forms; passstrict: fun.strictthrough to the ReqLLM tool; aliasLangChain.FunctionParamlib/chat_models/chat_req_llm.ex(@doc) — Documented the strict passthrough and dual parameter-form support onfunction_to_req_llm_tool/1test/chat_models/chat_req_llm_test.exs— Added coverage: strict defaults to false, strict: true passes through, strict serializes in OpenAI schema format, FunctionParam list maps to a schema, and no-params maps to an empty object schemaTesting
Five new unit tests in
test/chat_models/chat_req_llm_test.exscover the strict passthrough (includingReqLLM.Tool.to_schema(:openai)serialization) and both parameter-declaration forms. No live API calls required.