15
15
16
16
@preconcurrency import AWSBedrockRuntime
17
17
import Foundation
18
+ import Logging
18
19
19
20
public struct InvokeModelResponse {
20
21
let model : BedrockModel
@@ -50,9 +51,10 @@ public struct InvokeModelResponse {
50
51
/// - model: The Bedrock model that generated the response
51
52
/// - Throws: BedrockLibraryError.invalidModel if the model is not supported
52
53
/// BedrockLibraryError.invalidResponseBody if the response cannot be decoded
53
- static func createTextResponse( body data: Data , model: BedrockModel ) throws -> Self {
54
+ static func createTextResponse( body data: Data , model: BedrockModel , logger : Logger ) throws -> Self {
54
55
do {
55
56
let textModality = try model. getTextModality ( )
57
+ logger. trace ( " Raw response data: \n \( String ( data: data, encoding: . utf8) ?? " " ) \n " )
56
58
return self . init ( model: model, textCompletionBody: try textModality. getTextResponseBody ( from: data) )
57
59
} catch {
58
60
throw BedrockLibraryError . invalidSDKResponseBody ( data)
@@ -65,9 +67,10 @@ public struct InvokeModelResponse {
65
67
/// - model: The Bedrock model that generated the response
66
68
/// - Throws: BedrockLibraryError.invalidModel if the model is not supported
67
69
/// BedrockLibraryError.invalidResponseBody if the response cannot be decoded
68
- static func createImageResponse( body data: Data , model: BedrockModel ) throws -> Self {
70
+ static func createImageResponse( body data: Data , model: BedrockModel , logger : Logger ) throws -> Self {
69
71
do {
70
72
let imageModality = try model. getImageModality ( )
73
+ logger. trace ( " Raw response " , metadata: [ " Data " : " \( String ( data: data, encoding: . utf8) ?? " " ) " ] )
71
74
return self . init ( model: model, imageGenerationBody: try imageModality. getImageResponseBody ( from: data) )
72
75
} catch {
73
76
throw BedrockLibraryError . invalidSDKResponseBody ( data)
0 commit comments