Skip to content

Commit d8f12aa

Browse files
committed
swift-format
1 parent 5c59054 commit d8f12aa

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

Sources/InvokeModel/BedrockService+InvokeModelImage.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,31 +160,31 @@ extension BedrockService {
160160

161161
/// Sends the request to invoke the model and returns the generated image(s)
162162
private func sendRequest(request: InvokeModelRequest, model: BedrockModel) async throws -> ImageGenerationOutput {
163-
let input: InvokeModelInput = try request.getInvokeModelInput(forRegion: self.region)
163+
let input: InvokeModelInput = try request.getInvokeModelInput(forRegion: self.region)
164+
logger.trace(
165+
"Sending request to invokeModel",
166+
metadata: [
167+
"model": .string(model.id), "request": .string(String(describing: input)),
168+
]
169+
)
170+
let response = try await self.bedrockRuntimeClient.invokeModel(input: input)
171+
guard let responseBody = response.body else {
164172
logger.trace(
165-
"Sending request to invokeModel",
173+
"Invalid response",
166174
metadata: [
167-
"model": .string(model.id), "request": .string(String(describing: input)),
175+
"response": .string(String(describing: response)),
176+
"hasBody": .stringConvertible(response.body != nil),
168177
]
169178
)
170-
let response = try await self.bedrockRuntimeClient.invokeModel(input: input)
171-
guard let responseBody = response.body else {
172-
logger.trace(
173-
"Invalid response",
174-
metadata: [
175-
"response": .string(String(describing: response)),
176-
"hasBody": .stringConvertible(response.body != nil),
177-
]
178-
)
179-
throw BedrockLibraryError.invalidSDKResponse(
180-
"Something went wrong while extracting body from response."
181-
)
182-
}
183-
let invokemodelResponse: InvokeModelResponse = try InvokeModelResponse.createImageResponse(
184-
body: responseBody,
185-
model: model
179+
throw BedrockLibraryError.invalidSDKResponse(
180+
"Something went wrong while extracting body from response."
186181
)
187-
return try invokemodelResponse.getGeneratedImage()
182+
}
183+
let invokemodelResponse: InvokeModelResponse = try InvokeModelResponse.createImageResponse(
184+
body: responseBody,
185+
model: model
186+
)
187+
return try invokemodelResponse.getGeneratedImage()
188188
}
189189

190190
/// Generates 1 to 5 image variation(s) from reference images and a text prompt using a specific model

Sources/InvokeModel/InvokeModelRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct InvokeModelRequest {
206206
/// - Returns: A configured InvokeModelInput containing the model ID, content type, and encoded request body
207207
/// - Throws: BedrockLibraryError.encodingError if the request body cannot be encoded to JSON
208208
public func getInvokeModelInput(forRegion region: Region) throws -> InvokeModelInput {
209-
do {
209+
do {
210210
let jsonData: Data = try JSONEncoder().encode(self.body)
211211
return InvokeModelInput(
212212
accept: self.accept.headerValue,

Sources/Modalities/CrossRegionInference.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
public protocol CrossRegionInferenceModality: Sendable {}
1717
extension CrossRegionInferenceModality {
18-
public func crossRegionPrefix(forRegion region: Region) -> String {
19-
if region.isEURegion() { return "eu." }
20-
if region.isUSRegion() { return "us." }
21-
if region.isAPRegion() { return "ap." }
22-
return ""
23-
}
18+
public func crossRegionPrefix(forRegion region: Region) -> String {
19+
if region.isEURegion() { return "eu." }
20+
if region.isUSRegion() { return "us." }
21+
if region.isAPRegion() { return "ap." }
22+
return ""
23+
}
2424
}

Sources/Models/Mistral/MistralBedrockModels.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Foundation
2121

2222
typealias MistralConverse = StandardConverse
2323

24-
// TODO: define a new struct to support Pixtral Large 25 + cross region inference
24+
// TODO: define a new struct to support Pixtral Large 25 + cross region inference
2525

2626
extension BedrockModel {
2727
public static let mistral_large_2402 = BedrockModel(

Sources/Region.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ extension Region {
309309
// https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html
310310
extension Region {
311311
public func isUSRegion() -> Bool {
312-
return self.rawValue.hasPrefix("us-")
312+
self.rawValue.hasPrefix("us-")
313313
}
314314
public func isEURegion() -> Bool {
315-
return self.rawValue.hasPrefix("eu-")
315+
self.rawValue.hasPrefix("eu-")
316316
}
317317
public func isAPRegion() -> Bool {
318-
return self.rawValue.hasPrefix("ap-")
318+
self.rawValue.hasPrefix("ap-")
319319
}
320-
}
320+
}

Tests/Mock/MockBedrockRuntimeClient.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
@preconcurrency import AWSBedrockRuntime
17-
18-
import Testing
19-
2017
import BedrockService
2118
import Foundation
19+
import Testing
2220

2321
public struct MockBedrockRuntimeClient: BedrockRuntimeClientProtocol {
2422
public init() {}

0 commit comments

Comments
 (0)