Skip to content

Commit c6f9299

Browse files
committed
ConverseReply (backend + frontend)
1 parent 6a191e3 commit c6f9299

File tree

6 files changed

+8
-12
lines changed

6 files changed

+8
-12
lines changed

backend/Sources/PlaygroundAPI/Application+build.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func buildRouter(useSSO: Bool, logger: Logger) async throws -> Router<AppRequest
161161
}
162162

163163
// POST /foundation-models/chat/{modelId}
164-
router.post("/foundation-models/chat/:modelId") { request, context -> ChatOutput in
164+
router.post("/foundation-models/chat/:modelId") { request, context -> ConverseReply in
165165
do {
166166
guard let modelId = context.parameters.get("modelId") else {
167167
throw HTTPError(.badRequest, message: "No modelId was given.")
@@ -173,7 +173,7 @@ func buildRouter(useSSO: Bool, logger: Logger) async throws -> Router<AppRequest
173173
throw HTTPError(.badRequest, message: "Model \(modelId) does not support converse.")
174174
}
175175
let input = try await request.decode(as: ChatInput.self, context: context)
176-
let (reply, history) = try await bedrock.converse(
176+
return try await bedrock.converse(
177177
with: model,
178178
prompt: input.prompt,
179179
imageFormat: input.imageFormat ?? .jpeg, // default to simplify frontend
@@ -187,7 +187,6 @@ func buildRouter(useSSO: Bool, logger: Logger) async throws -> Router<AppRequest
187187
tools: input.tools,
188188
toolResult: input.toolResult
189189
)
190-
return ChatOutput(reply: reply, history: history)
191190
} catch {
192191
logger.info(
193192
"An error occured while generating chat",

backend/Sources/PlaygroundAPI/Types/Chat.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import BedrockTypes
1717
import Foundation
1818
import Hummingbird
1919

20-
extension Message: ResponseCodable {}
20+
extension Message: @retroactive ResponseCodable {}
2121

2222
struct ChatInput: Codable {
2323
let prompt: String?
@@ -33,7 +33,4 @@ struct ChatInput: Codable {
3333
let toolResult: ToolResultBlock?
3434
}
3535

36-
struct ChatOutput: ResponseCodable {
37-
let reply: String
38-
let history: [Message]
39-
}
36+
extension ConverseReply: @retroactive ResponseCodable {}

backend/Sources/PlaygroundAPI/Types/ImageGeneration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import BedrockTypes
1717
import Foundation
1818
import Hummingbird
1919

20-
extension ImageGenerationOutput: ResponseCodable {}
20+
extension ImageGenerationOutput: @retroactive ResponseCodable {}
2121

2222
struct ImageGenerationInput: Codable {
2323
let prompt: String

backend/Sources/PlaygroundAPI/Types/ListModels.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ import BedrockTypes
1717
import Foundation
1818
import Hummingbird
1919

20-
extension ModelSummary: ResponseEncodable {}
20+
extension ModelSummary: @retroactive ResponseEncodable {}

backend/Sources/PlaygroundAPI/Types/TextGeneration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import BedrockTypes
1717
import Foundation
1818
import Hummingbird
1919

20-
extension TextCompletion: ResponseCodable {}
20+
extension TextCompletion: @retroactive ResponseCodable {}
2121

2222
struct TextCompletionInput: Codable {
2323
let prompt: String

frontend/components/chatPlayground/ChatComponent.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default function ChatContainer() {
154154
await response.json().then(data => {
155155
setConversation(prevConversation => [...prevConversation, {
156156
sender: "Assistant",
157-
message: data.reply
157+
message: data.textReply
158158
}]);
159159
setHistory(data.history);
160160
});

0 commit comments

Comments
 (0)