You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Token usage information for a prompt or transcript.
2782
+
/// Returns the token count for the specified prompt.
2672
2783
///
2673
-
/// Provides the total number of tokens used.
2784
+
/// - Parameter prompt: The prompt to calculate the token count for.
2785
+
/// - Returns: The token count for the prompt.
2674
2786
@available(iOS 26.4, macOS 26.4, *)
2675
2787
@available(tvOS, unavailable)
2676
2788
@available(watchOS, unavailable)
2677
-
public struct TokenUsage {
2789
+
nonisolated(nonsending) final public func tokenCount(for prompt: some PromptRepresentable) async throws -> Int
2678
2790
2679
-
/// The total token count.
2680
-
public var tokenCount: Int
2681
-
}
2682
-
2683
-
/// Returns token usage information for the specified instructions and tools.
2791
+
/// Returns the token count for the specified instructions.
2684
2792
///
2685
-
/// This method calculates the token count for a set of instructions and
2686
-
/// tool definitions. The token count includes both the instructions and the
2687
-
/// tool hints that would be included in the model's context.
2793
+
/// - Parameter instructions: The instructions to calculate the token count for.
2794
+
/// - Returns: The token count for the instructions.
2795
+
@available(iOS 26.4, macOS 26.4, *)
2796
+
@available(tvOS, unavailable)
2797
+
@available(watchOS, unavailable)
2798
+
nonisolated(nonsending) final public func tokenCount(for instructions: Instructions) async throws -> Int
2799
+
2800
+
/// Returns the token count for the specified tools.
2688
2801
///
2689
-
/// - Parameters:
2690
-
/// - instructions: Instructions to calculate token usage for.
2691
-
/// - tools: An array of tools that will be available to the model. Defaults to an empty array if not specified.
2692
-
/// - Returns: A summary of token usage for the instructions and tools.
2802
+
/// - Parameter tools: An array of tools to calculate the token count for.
2803
+
/// - Returns: The token count for the tools.
2693
2804
@available(iOS 26.4, macOS 26.4, *)
2694
2805
@available(tvOS, unavailable)
2695
2806
@available(watchOS, unavailable)
2696
-
nonisolated(nonsending) final public func tokenUsage(for instructions: Instructions, tools: [any Tool] = []) async throws -> SystemLanguageModel.TokenUsage
2807
+
nonisolated(nonsending) final public func tokenCount(for tools: [any Tool]) async throws -> Int
2697
2808
2698
-
/// Returns token usage information for the specified prompt.
2809
+
/// Returns the token count for the specified schema.
2699
2810
///
2700
-
/// - Parameter prompt: A prompt to calculate token usage for.
2701
-
/// - Returns: A summary of token usage for the prompt.
2811
+
/// - Parameter schema: The schema to calculate the token count for.
2812
+
/// - Returns: The token count for the schema.
2702
2813
@available(iOS 26.4, macOS 26.4, *)
2703
2814
@available(tvOS, unavailable)
2704
2815
@available(watchOS, unavailable)
2705
-
nonisolated(nonsending) final public func tokenUsage(for prompt: some PromptRepresentable) async throws -> SystemLanguageModel.TokenUsage
2816
+
nonisolated(nonsending) final public func tokenCount(for schema: GenerationSchema) async throws -> Int
2706
2817
2707
-
/// Returns token usage information for the specified collection of transcript entries.
2818
+
/// Returns the token count for the specified collection of transcript entries.
2708
2819
///
2709
-
/// - Parameter transcriptEntries: A collection of transcript entries to calculate token usage for.
2710
-
/// - Returns: A summary of token usage for the transcript.
2820
+
/// - Parameter transcriptEntries: A collection of transcript entries to calculate the token count for.
2821
+
/// - Returns: The token count for the transcript.
2711
2822
@available(iOS 26.4, macOS 26.4, *)
2712
2823
@available(tvOS, unavailable)
2713
2824
@available(watchOS, unavailable)
2714
-
nonisolated(nonsending) final public func tokenUsage(for transcriptEntries: some Collection<Transcript.Entry>) async throws -> SystemLanguageModel.TokenUsage
2825
+
nonisolated(nonsending) final public func tokenCount(for transcriptEntries: some Collection<Transcript.Entry>) async throws -> Int
0 commit comments