fix: parse thoughtSignature correctly to support reasoning-to-text promotion
This commit is contained in:
@@ -151,10 +151,13 @@ export async function callGeminiChat(opts: {
|
|||||||
const toolCalls: ToolCall[] = [];
|
const toolCalls: ToolCall[] = [];
|
||||||
|
|
||||||
const parts = response.candidates?.[0]?.content?.parts ?? [];
|
const parts = response.candidates?.[0]?.content?.parts ?? [];
|
||||||
|
const isPartThought = (p: Record<string, unknown>) =>
|
||||||
|
Boolean(p.thought || p.thoughtSignature);
|
||||||
|
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (part.text) {
|
if (part.text) {
|
||||||
if ((part as { thought?: unknown }).thought) thoughts += part.text;
|
if (isPartThought(part as Record<string, unknown>))
|
||||||
|
thoughts += part.text;
|
||||||
else text += part.text;
|
else text += part.text;
|
||||||
}
|
}
|
||||||
if (part.functionCall) {
|
if (part.functionCall) {
|
||||||
@@ -219,12 +222,14 @@ export async function* streamGeminiChat(opts: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log("[GeminiChat] Stream request initiated");
|
console.log("[GeminiChat] Stream request initiated");
|
||||||
|
const isPartThought = (p: Record<string, unknown>) =>
|
||||||
|
Boolean(p.thought || p.thoughtSignature);
|
||||||
|
|
||||||
for await (const chunk of streamResult) {
|
for await (const chunk of streamResult) {
|
||||||
const parts = chunk.candidates?.[0]?.content?.parts ?? [];
|
const parts = chunk.candidates?.[0]?.content?.parts ?? [];
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (part.text) {
|
if (part.text) {
|
||||||
yield (part as { thought?: unknown }).thought
|
yield isPartThought(part as Record<string, unknown>)
|
||||||
? { type: "thinking", text: part.text }
|
? { type: "thinking", text: part.text }
|
||||||
: { type: "text", text: part.text };
|
: { type: "text", text: part.text };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user