Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
35 changes: 34 additions & 1 deletion Sources/Converse/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@
import Foundation

public struct Message: Codable, CustomStringConvertible, Sendable {

// https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_MessageStopEvent.html
// end_turn | tool_use | max_tokens | stop_sequence | guardrail_intervened | content_filtered
public enum StopReason: Codable, Sendable {
case endTurn
case toolUse
case maxTokens
case stopSequence
case guardrailIntervened
case contentFiltered
}
public let role: Role
public let content: [Content]
public let stopReason: StopReason?

// MARK - initializers

public init(from role: Role, content: [Content]) {
public init(from role: Role, content: [Content], stopReason: StopReason? = nil) {
self.role = role
self.content = content
self.stopReason = stopReason
}

/// convenience initializer for message with only a user prompt
Expand Down Expand Up @@ -137,4 +150,24 @@ public struct Message: Codable, CustomStringConvertible, Sendable {
role: role.getSDKConversationRole()
)
}

public static func stopReason(fromSDK sdkStopReason: BedrockRuntimeClientTypes.StopReason?) -> StopReason? {
switch sdkStopReason {
case .endTurn:
return .endTurn
case .toolUse:
return .toolUse
case .maxTokens:
return .maxTokens
case .stopSequence:
return .stopSequence
case .guardrailIntervened:
return .guardrailIntervened
case .contentFiltered:
return .contentFiltered
default:
return nil
}
}

}
94 changes: 0 additions & 94 deletions Sources/Converse/Streaming/Content+getFromSegements.swift

This file was deleted.

142 changes: 0 additions & 142 deletions Sources/Converse/Streaming/ContentSegment.swift

This file was deleted.

Loading