Add support for audio content in prompts and tool results (#73)
This commit is contained in:
parent
82f4fd29b3
commit
c748bc1549
2 changed files with 57 additions and 4 deletions
|
|
@ -63,6 +63,18 @@ struct PromptTests {
|
|||
#expect(Bool(false), "Expected text content")
|
||||
}
|
||||
|
||||
// Test audio content
|
||||
let audioContent = Prompt.Message.Content.audio(
|
||||
data: "base64audiodata", mimeType: "audio/wav")
|
||||
let audioData = try encoder.encode(audioContent)
|
||||
let decodedAudio = try decoder.decode(Prompt.Message.Content.self, from: audioData)
|
||||
if case .audio(let data, let mimeType) = decodedAudio {
|
||||
#expect(data == "base64audiodata")
|
||||
#expect(mimeType == "audio/wav")
|
||||
} else {
|
||||
#expect(Bool(false), "Expected audio content")
|
||||
}
|
||||
|
||||
// Test image content
|
||||
let imageContent = Prompt.Message.Content.image(data: "base64data", mimeType: "image/png")
|
||||
let imageData = try encoder.encode(imageContent)
|
||||
|
|
@ -142,7 +154,7 @@ struct PromptTests {
|
|||
let emptyParams = ListPrompts.Parameters()
|
||||
#expect(emptyParams.cursor == nil)
|
||||
}
|
||||
|
||||
|
||||
@Test("ListPrompts request decoding with omitted params")
|
||||
func testListPromptsRequestDecodingWithOmittedParams() throws {
|
||||
// Test decoding when params field is omitted
|
||||
|
|
@ -157,7 +169,7 @@ struct PromptTests {
|
|||
#expect(decoded.id == "test-id")
|
||||
#expect(decoded.method == ListPrompts.name)
|
||||
}
|
||||
|
||||
|
||||
@Test("ListPrompts request decoding with null params")
|
||||
func testListPromptsRequestDecodingWithNullParams() throws {
|
||||
// Test decoding when params field is null
|
||||
|
|
|
|||
|
|
@ -103,6 +103,26 @@ struct ToolTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test("Audio content encoding and decoding")
|
||||
func testToolContentAudioEncoding() throws {
|
||||
let content = Tool.Content.audio(
|
||||
data: "base64audiodata",
|
||||
mimeType: "audio/wav"
|
||||
)
|
||||
let encoder = JSONEncoder()
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let data = try encoder.encode(content)
|
||||
let decoded = try decoder.decode(Tool.Content.self, from: data)
|
||||
|
||||
if case .audio(let data, let mimeType) = decoded {
|
||||
#expect(data == "base64audiodata")
|
||||
#expect(mimeType == "audio/wav")
|
||||
} else {
|
||||
#expect(Bool(false), "Expected audio content")
|
||||
}
|
||||
}
|
||||
|
||||
@Test("ListTools parameters validation")
|
||||
func testListToolsParameters() throws {
|
||||
let params = ListTools.Parameters(cursor: "next_page")
|
||||
|
|
|
|||
Loading…
Reference in a new issue