Support tool calls for FoundationModelsClient #75
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.
#74
This pull request refactors the tool call handling logic for LLM clients by moving the default implementations of
generateToolCallsandresumeStreaminto a protocol extension, and updates theFoundationModelsClientto support tool integration and error handling. The changes reduce code duplication, improve extensibility, and add better error reporting for unavailable models.Key changes:
Refactoring and Code Reuse:
generateToolCallsandresumeStreamfrom individual clients (LlamaClient,MLXClient) into a protocol extension forLLMClient, reducing code duplication and centralizing tool call logic. [1] [2] [3]Tool Integration:
FoundationModelsClientto accept a list of tools via its initializer and static factory, allowing tool support to be configured at client creation. [1] [2]Streaming and Error Handling:
responseStream(from:)method toFoundationModelsClientfor streaming both text and tool call responses, and improved error handling by introducing aFoundationModelsClientErrorfor unavailable models. [1] [2]These changes make the codebase cleaner, easier to extend, and more robust in handling tool-based interactions and model availability.