tools library

Custom function calling, emulated on a backend that has none.

Import this only if you want it: it is a separate library from package:chatgpt_free/chatgpt_free.dart, so a consumer who just wants the chat client never sees any of it.

Start at ToolExtractor.

Classes

AnyToolChoice
ToolChoice.any.
AutoToolChoice
ToolChoice.auto.
EnvelopeCalls
The reply carried calls (possibly zero, for an explicit "no tool").
EnvelopeNeedInfo
The model reported a required parameter the request never stated.
EnvelopeUnreadable
The reply was not a well-formed envelope at all.
FunctionTool
One function the caller can execute, declared to the extractor.
NamedToolChoice
ToolChoice.function.
NoToolCall
No declared function fits — answer the user the ordinary way.
ToolCall
One function call the model produced.
ToolCallsExtracted
The model chose one or more functions.
ToolChoice
What the extractor is allowed to answer.
ToolEnvelope
What one raw extractor reply turned out to be.
ToolExtraction
What one extraction produced.
ToolExtractor
Custom function calling, emulated on a backend that has none.
ToolInfoNeeded
A required parameter was never stated in the request.

Constants

kNeedInfoMarker → const String
The marker for "a required parameter was never stated".
kNoToolMarker → const String
The marker for "no declared function fits this request".
kToolCallMarker → const String
The marker a call is wrapped in.

Functions

allowedNames(List<FunctionTool> functions, ToolChoice choice) Set<String>
The names detection may produce once choice has had its say.
applySchemas(List<ToolCall>? calls, List<FunctionTool> functions) List<ToolCall>?
Repairs argument types against each function's declared schema.
buildExtractorPrompt(List<FunctionTool> functions, String request, {ToolChoice choice = ToolChoice.auto}) String
Builds the extractor prompt.
buildRepairPrompt(String original, String previous, List<String> errors) String
Builds the repair prompt: the original ask plus what was wrong with the answer to it.
buildVerifyPrompt(List<FunctionTool> functions, String request, List<ToolCall> calls) String
Builds the audit prompt for the opt-in second pass.
coerceValue(Object? value, Object? schema, [int depth = 0]) Object?
Repairs one value against its schema: losslessly, or not at all.
detectToolCalls(String text, Set<String> validNames, {List<FunctionTool> functions = const []}) List<ToolCall>?
Reads model output as tool calls, accepting only validNames.
loadsTolerant(String text) Object?
Reads JSON, falling back to the Python-literal dialect weaker models emit.
parseToolEnvelope(String text, Set<String> validNames, {List<FunctionTool> functions = const []}) ToolEnvelope
Reads the extractor's reply, in two layers.
validateToolCalls(List<ToolCall> calls, List<FunctionTool> functions) List<String>
Checks each call's arguments against its function's JSON Schema.