Gemini: Thought toggle

Closes #3220
This commit is contained in:
Cohee
2024-12-29 18:23:07 +02:00
parent c3ad87cea1
commit 662f0e9c73
4 changed files with 40 additions and 3 deletions

View File

@@ -144,9 +144,14 @@ async function* parseStreamData(json) {
for (let j = 0; j < json.candidates[i].content.parts.length; j++) {
if (typeof json.candidates[i].content.parts[j].text === 'string') {
for (let k = 0; k < json.candidates[i].content.parts[j].text.length; k++) {
const str = json.candidates[i].content.parts[j].text[k];
const moreThanOnePart = json.candidates[i].content.parts.length > 1;
const isNotLastPart = j !== json.candidates[i].content.parts.length - 1;
const isLastSymbol = k === json.candidates[i].content.parts[j].text.length - 1;
const addNewline = moreThanOnePart && isNotLastPart && isLastSymbol;
const str = json.candidates[i].content.parts[j].text[k] + (addNewline ? '\n\n' : '');
const candidateClone = structuredClone(json.candidates[0]);
candidateClone.content.parts[j].text = str;
candidateClone.content.parts = [candidateClone.content.parts[j]];
const candidates = [candidateClone];
yield {
data: { ...json, candidates },