Merge pull request #75 from aditheking/main

Fix Gemini API streaming implementation
This commit is contained in:
sanio 2025-07-07 19:46:49 +09:00 committed by GitHub
commit 0f17a06c3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -262,7 +262,27 @@ function createStreamingLLM({ apiKey, model = 'gemini-2.5-flash', temperature =
let chunkCount = 0;
let totalContent = '';
for await (const chunk of chat.sendMessageStream(geminiContent)) {
const contentParts = geminiContent.map(part => {
if (typeof part === 'string') {
return { text: part };
} else if (part.inlineData) {
return { inlineData: part.inlineData };
}
return part;
});
const result = await geminiModel.generateContentStream({
contents: [{
role: 'user',
parts: contentParts
}],
generationConfig: {
temperature,
maxOutputTokens: maxTokens || 8192,
}
});
for await (const chunk of result.stream) {
chunkCount++;
const chunkText = chunk.text() || '';
totalContent += chunkText;
@ -307,4 +327,4 @@ module.exports = {
createSTT,
createLLM,
createStreamingLLM
};
};