Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9157354
initial week 14 commit
monadierickx Mar 28, 2025
9e4ddd8
backend: converse image
monadierickx Mar 31, 2025
beee69b
frontend: converse vision + backend: modality changes
monadierickx Mar 31, 2025
bebf86a
backend: converse modalitity added to all supported models
monadierickx Mar 31, 2025
3e1d724
Mistral support only for converse added
monadierickx Mar 31, 2025
7145629
converse image input
monadierickx Mar 31, 2025
f5e8bae
backend: converse refactor using Blocks
monadierickx Mar 31, 2025
94bf47e
DocumentFormat
monadierickx Mar 31, 2025
d5b0575
DocumentFormat
monadierickx Mar 31, 2025
193896d
DocumentBlock
monadierickx Mar 31, 2025
ac5cb6c
DocumentBlock
monadierickx Mar 31, 2025
fec96e2
S3Location
monadierickx Mar 31, 2025
3fef779
VideoSource
monadierickx Mar 31, 2025
da385b2
VideoFormat
monadierickx Mar 31, 2025
00faaf4
VideoBlock
monadierickx Mar 31, 2025
1e8f0be
ToolStatus
monadierickx Mar 31, 2025
8ac47e1
ToolResultContent
monadierickx Mar 31, 2025
3b1fd1a
ToolResultBlock
monadierickx Mar 31, 2025
b8c20a2
Content
monadierickx Mar 31, 2025
8b9a7b9
base for toolconfig
monadierickx Mar 31, 2025
226ab12
nested types for Blocks
monadierickx Apr 1, 2025
8201a9e
backend: converse systemprompts
monadierickx Apr 1, 2025
74d8c57
JSON for tools
monadierickx Apr 2, 2025
5376807
backend: tools
monadierickx Apr 2, 2025
b527ae3
tool use
monadierickx Apr 2, 2025
c5ba8cb
Tool result
monadierickx Apr 2, 2025
1b2cf7c
Tool result
monadierickx Apr 2, 2025
97a7bea
Deleted Converse only modality for Nova
monadierickx Apr 2, 2025
ed42213
refactor: moved converse transforamtions to BedrockTypes
monadierickx Apr 3, 2025
60305fe
convenience methods for Message
monadierickx Apr 3, 2025
600b591
converse function in BedrockService split up into two
monadierickx Apr 3, 2025
3f51bbc
refactor ToolResultBlock added nested types
monadierickx Apr 3, 2025
c710e50
docstrings
monadierickx Apr 3, 2025
35f097b
README updated
monadierickx Apr 3, 2025
d7aa092
README + StanderdConverse
monadierickx Apr 3, 2025
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
365 changes: 286 additions & 79 deletions README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions backend/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ let package = Package(
),
.target(
name: "BedrockTypes",
dependencies: [
.product(name: "AWSBedrockRuntime", package: "aws-sdk-swift"),
.product(name: "Smithy", package: "smithy-swift"),
],
path: "Sources/BedrockTypes"
),
.testTarget(
Expand Down
18 changes: 12 additions & 6 deletions backend/Sources/App/Application+build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
//
//===----------------------------------------------------------------------===//

import Hummingbird
import Logging
import BedrockService
import BedrockTypes
import Hummingbird
import Logging
import Foundation

/// Application arguments protocol. We use a protocol so we can call
/// `buildApplication` inside Tests as well as in the App executable.
Expand Down Expand Up @@ -168,18 +169,23 @@ func buildRouter(useSSO: Bool, logger: Logger) async throws -> Router<AppRequest
guard let model = BedrockModel(rawValue: modelId) else {
throw HTTPError(.badRequest, message: "Invalid modelId: \(modelId).")
}
guard model.hasTextModality() else {
throw HTTPError(.badRequest, message: "Model \(modelId) does not support text output.")
guard model.hasConverseModality() else {
throw HTTPError(.badRequest, message: "Model \(modelId) does not support converse.")
}
let input = try await request.decode(as: ChatInput.self, context: context)
let (reply, history) = try await bedrock.converse(
with: model,
prompt: input.prompt,
history: input.history,
imageFormat: input.imageFormat ?? .jpeg, // default to simplify frontend
imageBytes: input.imageBytes,
history: input.history ?? [],
maxTokens: input.maxTokens,
temperature: input.temperature,
topP: input.topP,
stopSequences: input.stopSequences
stopSequences: input.stopSequences,
systemPrompts: input.systemPrompts,
tools: input.tools,
toolResult: input.toolResult
)
return ChatOutput(reply: reply, history: history)
} catch {
Expand Down
9 changes: 7 additions & 2 deletions backend/Sources/App/Types/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ import BedrockTypes
extension Message: ResponseCodable {}

struct ChatInput: Codable {
let prompt: String
let history: [Message]
let prompt: String?
let history: [Message]?
let imageFormat: ImageBlock.Format?
let imageBytes: String?
let maxTokens: Int?
let temperature: Double?
let topP: Double?
let stopSequences: [String]?
let systemPrompts: [String]?
let tools: [Tool]?
let toolResult: ToolResultBlock?
}

struct ChatOutput: ResponseCodable {
Expand Down
52 changes: 52 additions & 0 deletions backend/Sources/App/Types/Cohere/CohereBedrockModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Foundation Models Playground open source project
//
// Copyright (c) 2025 Amazon.com, Inc. or its affiliates
// and the Swift Foundation Models Playground project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Foundation Models Playground project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import BedrockTypes
import Foundation

// https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-cohere-command-r-plus.html
typealias CohereConverse = StandardConverse

extension BedrockModel {
public static let cohere_command_R_plus = BedrockModel(
id: "cohere.command-r-plus-v1:0",
name: "Cohere Command R+",
modality: CohereConverse(
parameters: ConverseParameters(
temperature: Parameter(.temperature, minValue: 0, maxValue: 1, defaultValue: 0.3),
maxTokens: Parameter(.maxTokens, minValue: 1, maxValue: nil, defaultValue: nil),
topP: Parameter(.topP, minValue: 0.01, maxValue: 0.99, defaultValue: 0.75),
stopSequences: StopSequenceParams(maxSequences: nil, defaultValue: []),
maxPromptSize: nil
),
features: [.textGeneration, .systemPrompts, .document, .toolUse]
)
)

public static let cohere_command_R = BedrockModel(
id: "cohere.command-r-v1:0",
name: "Cohere Command R",
modality: CohereConverse(
parameters: ConverseParameters(
temperature: Parameter(.temperature, minValue: 0, maxValue: 1, defaultValue: 0.3),
maxTokens: Parameter(.maxTokens, minValue: 1, maxValue: nil, defaultValue: nil),
topP: Parameter(.topP, minValue: 0.01, maxValue: 0.99, defaultValue: 0.75),
stopSequences: StopSequenceParams(maxSequences: nil, defaultValue: []),
maxPromptSize: nil
),
features: [.textGeneration, .systemPrompts, .document, .toolUse]
)
)
}
2 changes: 1 addition & 1 deletion backend/Sources/App/Types/ListModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

import Foundation
import Hummingbird
import BedrockService
import BedrockTypes

extension ModelSummary: ResponseEncodable {}
Loading
Loading