Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion Sources/AnyLanguageModel/Models/GeminiLanguageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,14 @@ public struct GeminiLanguageModel: LanguageModel, ProfileRequestIdentifiedLangua
switch resolution {
case .stop:
state.entries.append(.toolCalls(callsEntry))
continuation.yield(try state.stoppedSnapshot(provider: "Gemini"))
continuation.yield(
try state.stoppedSnapshot(
provider: "Gemini",
providerMetadata: state.responseText.isEmpty
? stoppedResponseContentMetadata
: nil
)
)
continuation.finish()
return
case .invocations(let invocations):
Expand Down
39 changes: 39 additions & 0 deletions Tests/AnyLanguageModelTests/GeminiAssistantHistoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,45 @@ struct GeminiAssistantHistoryTests {
)
}

@Test(arguments: [false, true])
func aStoppedToolRoundWithoutTextOmitsEmptyModelMessage(streaming: Bool) async throws {
let transport = FakeTransport(replies: [
try Self.reply(parts: [Self.call], streaming: streaming),
try Self.reply(parts: [Self.text("Bye.")], streaming: streaming),
])
let session = LanguageModelSession(model: Self.model(transport), tools: [WeatherTool()])
session.toolExecutionDelegate = StoppingGeminiDelegate()
_ = try await Self.ask(session, "Weather?", streaming: streaming)
_ = try await Self.ask(session, "Thanks", streaming: streaming)

#expect(
try Self.labels(transport.bodies[1]) == [
"user: Weather?", "call #call-signature", "output", "user: Thanks",
]
)
}

@Test(arguments: [false, true])
func aStoppedToolRoundWithSignedThoughtOmitsEmptyModelMessage(streaming: Bool) async throws {
let transport = FakeTransport(replies: [
try Self.reply(
parts: [Self.thought("THOUGHT", signature: "thought-signature"), Self.call],
streaming: streaming
),
try Self.reply(parts: [Self.text("Bye.")], streaming: streaming),
])
let session = LanguageModelSession(model: Self.model(transport), tools: [WeatherTool()])
session.toolExecutionDelegate = StoppingGeminiDelegate()
_ = try await Self.ask(session, "Weather?", streaming: streaming)
_ = try await Self.ask(session, "Thanks", streaming: streaming)

#expect(
try Self.labels(transport.bodies[1]) == [
"user: Weather?", "model: #thought-signature", "call #call-signature", "output", "user: Thanks",
]
)
}

/// A stopped stream's response is the round's text. The other builders can't read Gemini's
/// text parts, so they send that response, once.
@Test
Expand Down
Loading