Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions Sources/AnyLanguageModel/DynamicProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ extension LanguageModelSession {
/// options, and callbacks, which the session resolves before each model request.
///
/// Create a session with a profile with ``LanguageModelSession/init(profile:history:)``.
/// The session evaluates ``body`` again before every model request,
/// including the requests that continue a response after a tool call,
/// The session evaluates ``body`` again before each model request,
/// so the body can choose a different model, instructions, or tools
/// from the session's properties and history.
/// OpenAI, Open Responses, Anthropic, Gemini, and Ollama also evaluate it again
/// before each request that continues a response after a tool call.
/// MLX and llama.cpp evaluate it once for each response,
/// so their tool rounds use the same instructions, tools, and options.
/// The system model and Private Cloud Compute evaluate it again
/// before the continuation after a tool round,
/// but a continuation that selects another model stays on the native session's model,
/// and changed options don't apply to it.
///
/// Build a profile from a ``Profile`` and modifiers such as `model(_:)`,
/// ``temperature(_:)``, and `onResponse(perform:)`.
Expand Down Expand Up @@ -611,8 +618,9 @@ extension LanguageModelSession.DynamicProfile {
/// - Parameter action: The action to run, which receives the tool call.
/// - Returns: A profile with the action.
///
/// - Important: At this time, none of the language models in AnyLanguageModel
/// run this action when they call a tool.
/// - Important: OpenAI, Open Responses, Anthropic, Gemini, and Ollama run this action
/// when they call a tool. MLX, llama.cpp, Core ML, Private Cloud Compute,
/// and the system model don't run it yet.
public func onToolCall(
@_inheritActorContext perform action:
nonisolated(nonsending) sending @escaping (
Expand All @@ -630,8 +638,9 @@ extension LanguageModelSession.DynamicProfile {
/// - Parameter action: The action to run.
/// - Returns: A profile with the action.
///
/// - Important: At this time, none of the language models in AnyLanguageModel
/// run this action when they call a tool.
/// - Important: OpenAI, Open Responses, Anthropic, Gemini, and Ollama run this action
/// when they call a tool. MLX, llama.cpp, Core ML, Private Cloud Compute,
/// and the system model don't run it yet.
public func onToolCall(
@_inheritActorContext perform action: nonisolated(nonsending) sending @escaping () async throws -> Void
) -> some LanguageModelSession.DynamicProfile {
Expand All @@ -645,8 +654,9 @@ extension LanguageModelSession.DynamicProfile {
/// - Parameter action: The action to run, which receives the tool call and its output.
/// - Returns: A profile with the action.
///
/// - Important: At this time, none of the language models in AnyLanguageModel
/// run this action when they call a tool.
/// - Important: OpenAI, Open Responses, Anthropic, Gemini, and Ollama run this action
/// when they call a tool. MLX, llama.cpp, Core ML, Private Cloud Compute,
/// and the system model don't run it yet.
public func onToolOutput(
@_inheritActorContext perform action:
nonisolated(nonsending) sending @escaping (
Expand All @@ -665,8 +675,9 @@ extension LanguageModelSession.DynamicProfile {
/// - Parameter action: The action to run.
/// - Returns: A profile with the action.
///
/// - Important: At this time, none of the language models in AnyLanguageModel
/// run this action when they call a tool.
/// - Important: OpenAI, Open Responses, Anthropic, Gemini, and Ollama run this action
/// when they call a tool. MLX, llama.cpp, Core ML, Private Cloud Compute,
/// and the system model don't run it yet.
public func onToolOutput(
@_inheritActorContext perform action: nonisolated(nonsending) sending @escaping () async throws -> Void
) -> some LanguageModelSession.DynamicProfile {
Expand Down
4 changes: 0 additions & 4 deletions Sources/AnyLanguageModel/GenerationOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ public struct GenerationOptions: Sendable, Equatable {
///
/// ``SystemLanguageModel`` and ``PrivateCloudComputeLanguageModel`` ignore it:
/// Foundation Models runs tool calls itself.
/// In a response that isn't streamed,
/// ``AnthropicLanguageModel`` and ``OllamaLanguageModel`` run one round of tool calls
/// and return without sending the tools' output back to the model,
/// so the limit applies only to their streamed responses.
///
/// - Note: This API is exclusive to AnyLanguageModel
/// and using it means your code is no longer drop-in compatible
Expand Down
Loading