|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift Bedrock Library open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Amazon.com, Inc. or its affiliates |
| 6 | +// and the Swift Bedrock Library project authors |
| 7 | +// Licensed under Apache License v2.0 |
| 8 | +// |
| 9 | +// See LICENSE.txt for license information |
| 10 | +// See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors |
| 11 | +// |
| 12 | +// SPDX-License-Identifier: Apache-2.0 |
| 13 | +// |
| 14 | +//===----------------------------------------------------------------------===// |
| 15 | + |
| 16 | +#if canImport(FoundationEssentials) |
| 17 | +import FoundationEssentials |
| 18 | +#else |
| 19 | +import Foundation |
| 20 | +#endif |
| 21 | + |
| 22 | +// Wrapper structs for v4.5 models to support GlobalCrossRegionInferenceModality |
| 23 | +struct Claude_Sonnet_v4_5: TextModality, ConverseModality, ConverseStreamingModality, GlobalCrossRegionInferenceModality |
| 24 | +{ |
| 25 | + private let anthropicText: AnthropicText |
| 26 | + |
| 27 | + let converseParameters: ConverseParameters |
| 28 | + let converseFeatures: [ConverseFeature] |
| 29 | + |
| 30 | + init(parameters: TextGenerationParameters, features: [ConverseFeature], maxReasoningTokens: Parameter<Int>) { |
| 31 | + self.anthropicText = AnthropicText( |
| 32 | + parameters: parameters, |
| 33 | + features: features, |
| 34 | + maxReasoningTokens: maxReasoningTokens |
| 35 | + ) |
| 36 | + self.converseParameters = anthropicText.converseParameters |
| 37 | + self.converseFeatures = anthropicText.converseFeatures |
| 38 | + } |
| 39 | + |
| 40 | + func getName() -> String { anthropicText.getName() } |
| 41 | + func getParameters() -> TextGenerationParameters { anthropicText.getParameters() } |
| 42 | + func getConverseParameters() -> ConverseParameters { anthropicText.getConverseParameters() } |
| 43 | + func getConverseFeatures() -> [ConverseFeature] { anthropicText.getConverseFeatures() } |
| 44 | + |
| 45 | + func getTextRequestBody( |
| 46 | + prompt: String, |
| 47 | + maxTokens: Int?, |
| 48 | + temperature: Double?, |
| 49 | + topP: Double?, |
| 50 | + topK: Int?, |
| 51 | + stopSequences: [String]?, |
| 52 | + serviceTier: ServiceTier |
| 53 | + ) throws -> BedrockBodyCodable { |
| 54 | + try anthropicText.getTextRequestBody( |
| 55 | + prompt: prompt, |
| 56 | + maxTokens: maxTokens, |
| 57 | + temperature: temperature, |
| 58 | + topP: topP, |
| 59 | + topK: topK, |
| 60 | + stopSequences: stopSequences, |
| 61 | + serviceTier: serviceTier |
| 62 | + ) |
| 63 | + } |
| 64 | + |
| 65 | + func getTextResponseBody(from data: Data) throws -> ContainsTextCompletion { |
| 66 | + try anthropicText.getTextResponseBody(from: data) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +struct Claude_Opus_v4_5: TextModality, ConverseModality, ConverseStreamingModality, GlobalCrossRegionInferenceModality { |
| 71 | + private let anthropicText: AnthropicText |
| 72 | + |
| 73 | + let converseParameters: ConverseParameters |
| 74 | + let converseFeatures: [ConverseFeature] |
| 75 | + |
| 76 | + init(parameters: TextGenerationParameters, features: [ConverseFeature], maxReasoningTokens: Parameter<Int>) { |
| 77 | + self.anthropicText = AnthropicText( |
| 78 | + parameters: parameters, |
| 79 | + features: features, |
| 80 | + maxReasoningTokens: maxReasoningTokens |
| 81 | + ) |
| 82 | + self.converseParameters = anthropicText.converseParameters |
| 83 | + self.converseFeatures = anthropicText.converseFeatures |
| 84 | + } |
| 85 | + |
| 86 | + func getName() -> String { anthropicText.getName() } |
| 87 | + func getParameters() -> TextGenerationParameters { anthropicText.getParameters() } |
| 88 | + func getConverseParameters() -> ConverseParameters { anthropicText.getConverseParameters() } |
| 89 | + func getConverseFeatures() -> [ConverseFeature] { anthropicText.getConverseFeatures() } |
| 90 | + |
| 91 | + func getTextRequestBody( |
| 92 | + prompt: String, |
| 93 | + maxTokens: Int?, |
| 94 | + temperature: Double?, |
| 95 | + topP: Double?, |
| 96 | + topK: Int?, |
| 97 | + stopSequences: [String]?, |
| 98 | + serviceTier: ServiceTier |
| 99 | + ) throws -> BedrockBodyCodable { |
| 100 | + try anthropicText.getTextRequestBody( |
| 101 | + prompt: prompt, |
| 102 | + maxTokens: maxTokens, |
| 103 | + temperature: temperature, |
| 104 | + topP: topP, |
| 105 | + topK: topK, |
| 106 | + stopSequences: stopSequences, |
| 107 | + serviceTier: serviceTier |
| 108 | + ) |
| 109 | + } |
| 110 | + |
| 111 | + func getTextResponseBody(from data: Data) throws -> ContainsTextCompletion { |
| 112 | + try anthropicText.getTextResponseBody(from: data) |
| 113 | + } |
| 114 | +} |
0 commit comments