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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ verbatim as the body of the matching GitHub release.

| Version | Date | Notes |
|---|---|---|
| v0.2.10 | 2026-11-24 | [changelog/v0.2.10.md](changelog/v0.2.10.md) |
| v0.2.9 | 2026-11-24 | [changelog/v0.2.9.md](changelog/v0.2.9.md) |
| v0.2.8 | 2026-11-24 | [changelog/v0.2.8.md](changelog/v0.2.8.md) |
| v0.2.7 | 2026-11-23 | [changelog/v0.2.7.md](changelog/v0.2.7.md) |
Expand Down
13 changes: 13 additions & 0 deletions changelog/v0.2.10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# v0.2.10

Gemini streaming now supports tool calls.

## Fixed

- **Gemini SSE streaming translates `functionCall` parts into OpenAI `tool_calls` deltas.**
Agent clients such as Pi can execute tools instead of receiving an empty assistant
message and stopping.
- **Final text is no longer dropped when a Gemini event carries both text and
`finishReason`.** The text chunk is emitted before the finish chunk.

The non-streaming path already translated tool calls; this brings streaming to parity.
2 changes: 1 addition & 1 deletion deploy/dokploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ database. The console is always a plain Application.
3. Compose path: `deploy/dokploy/compose.yml`.
4. **Trigger Type: On Tag**, with auto-deploy enabled. The gateway is a production
service; a pull request or a push to `Develop` must not restart it. A release tag
(`v0.2.9`) is the only thing that deploys — see "When it deploys" below.
(`v0.2.10`) is the only thing that deploys — see "When it deploys" below.
5. **Environment** (the compose file references all of these):

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/SPRING-AI.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on Spring AI; the gateway never depends on it.
<dependency>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-spring-ai</artifactId>
<version>0.2.9</version>
<version>0.2.10</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion path-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.9</version>
<version>0.2.10</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ private final class Translator implements StreamTranslator {
private TokenUsage usage = TokenUsage.EMPTY;
private boolean done;
private boolean finishSent;
private boolean sawToolCall;
private int toolCallIndex;

private Translator(ChatRequestSpec spec) {
this.spec = spec;
Expand Down Expand Up @@ -504,24 +506,53 @@ public List<JsonNode> translate(String line) {
return List.of();
}
StringBuilder text = new StringBuilder();
List<JsonNode> toolChunks = new ArrayList<>();
for (JsonNode part : candidate.path("content").path("parts")) {
if (part.hasNonNull("text") && !part.path("thought").asBoolean(false)) {
text.append(part.get("text").asText());
}
if (part.has("functionCall")) {
sawToolCall = true;
toolChunks.add(toolCallChunk(part.get("functionCall"), toolCallIndex++));
}
}
String finish = candidate.hasNonNull("finishReason")
? mapFinish(candidate.get("finishReason").asText()) : null;
List<JsonNode> out = new ArrayList<>(1);
List<JsonNode> out = new ArrayList<>(1 + toolChunks.size());
if (!text.isEmpty()) {
out.add(chunk(text.toString(), null));
}
out.addAll(toolChunks);
if (finish != null) {
out.add(chunk("", finish));
out.add(chunk("", sawToolCall ? "tool_calls" : finish));
done = true;
finishSent = true;
} else if (!text.isEmpty()) {
out.add(chunk(text.toString(), null));
}
return out;
}

private ObjectNode toolCallChunk(JsonNode call, int index) {
ObjectNode chunk = mapper.createObjectNode();
chunk.put("id", "chatcmpl-gemini");
chunk.put("object", "chat.completion.chunk");
chunk.put("created", created);
chunk.put("model", spec.publicModel());
ObjectNode choice = chunk.putArray("choices").addObject();
choice.put("index", 0);
ObjectNode delta = choice.putObject("delta");
delta.put("role", "assistant");
ArrayNode calls = delta.putArray("tool_calls");
ObjectNode callNode = calls.addObject();
callNode.put("index", index);
callNode.put("id", "call_" + UUID.randomUUID().toString().replace("-", "").substring(0, 12));
callNode.put("type", "function");
ObjectNode function = callNode.putObject("function");
function.put("name", call.path("name").asText());
function.put("arguments", call.path("args").toString());
choice.putNull("finish_reason");
return chunk;
}

private ObjectNode chunk(String content, String finishReason) {
ObjectNode chunk = mapper.createObjectNode();
chunk.put("id", "chatcmpl-gemini");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,41 @@ void streamsContentAndKeepsTheUsage() throws Exception {
assertThat(first).hasSize(1);
assertThat(first.get(0).path("choices").get(0).path("delta").path("content").asText())
.isEqualTo("Hel");
assertThat(second.get(0).path("choices").get(0).path("finish_reason").asText()).isEqualTo("stop");
assertThat(second).hasSize(2);
assertThat(second.get(0).path("choices").get(0).path("delta").path("content").asText())
.isEqualTo("lo");
assertThat(second.get(1).path("choices").get(0).path("finish_reason").asText()).isEqualTo("stop");
assertThat(translator.done()).isTrue();
assertThat(translator.usage().completion()).isEqualTo(3);
assertThat(translator.usage().reasoning()).isEqualTo(1);
}

@Test
void streamsToolCallsAsOpenAiDeltas() throws Exception {
ChatRequestSpec spec = ChatRequestSpec.parse((ObjectNode) mapper.readTree("""
{"model":"gemini-2.5-pro","messages":[{"role":"user","content":"list files"}],
"tools":[{"type":"function","function":{"name":"bash","parameters":
{"type":"object","properties":{"command":{"type":"string"}}}}}]}
"""));
StreamTranslator translator = adapter.newStreamTranslator(spec, route("gemini-2.5-pro"));

List<JsonNode> call = translator.translate(
"data: {\"candidates\":[{\"content\":{\"parts\":[{\"functionCall\":"
+ "{\"name\":\"bash\",\"args\":{\"command\":\"ls\"}}}]}}]}");
List<JsonNode> finish = translator.translate(
"data: {\"candidates\":[{\"finishReason\":\"STOP\"}],"
+ "\"usageMetadata\":{\"promptTokenCount\":5,\"candidatesTokenCount\":4,"
+ "\"totalTokenCount\":9}}");

assertThat(call).hasSize(1);
JsonNode delta = call.get(0).path("choices").get(0).path("delta");
assertThat(delta.path("tool_calls").get(0).path("function").path("name").asText())
.isEqualTo("bash");
assertThat(delta.path("tool_calls").get(0).path("function").path("arguments").asText())
.contains("\"command\":\"ls\"");
assertThat(finish.get(0).path("choices").get(0).path("finish_reason").asText())
.isEqualTo("tool_calls");
assertThat(translator.done()).isTrue();
assertThat(translator.usage().completion()).isEqualTo(4);
}
}
2 changes: 1 addition & 1 deletion path-spring-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.9</version>
<version>0.2.10</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.9</version>
<version>0.2.10</version>
<packaging>pom</packaging>
<name>path-parent</name>
<description>Build parent for Path, the provider-agnostic LLM gateway, and its Spring AI adapter</description>
Expand Down
Loading