summaryrefslogtreecommitdiff
path: root/packages/server/src
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-05-11 12:59:44 -0700
committerN. Taylor Mullen <[email protected]>2025-05-11 13:01:54 -0700
commit4d5f0dc0809eacdf7c034302a5e8f36bc75ca4e1 (patch)
tree041d8037b6817eb9fbe78d13a3f04b556a04e796 /packages/server/src
parentcf91f72c5c0079ec4b5db67d0f8fcac043d31088 (diff)
Workaround model bug where it returns invalid history items.
- Currently there's a bug in the API (or SDK?) where the SDK endpoint will commonly fail with: ``` Error: Failed to generate JSON content: got status: 400 Bad Request. {"error":{"code":400,"message":"* GenerateContentRequest.contents[5].parts: contents.parts must not be empty.\n","status":"INVALID_ARGUMENT"}} ``` - At times the model will respond with an empty parts list where if we send that back up to the API endpoint it explodes with the above. Using a curated history seems like a total hack around this prolbem, and even in the SDK (i'm following up on this), BUT helps mitigate this issue.
Diffstat (limited to 'packages/server/src')
-rw-r--r--packages/server/src/utils/nextSpeakerChecker.ts7
1 files changed, 6 insertions, 1 deletions
diff --git a/packages/server/src/utils/nextSpeakerChecker.ts b/packages/server/src/utils/nextSpeakerChecker.ts
index f852879f..a7818713 100644
--- a/packages/server/src/utils/nextSpeakerChecker.ts
+++ b/packages/server/src/utils/nextSpeakerChecker.ts
@@ -60,7 +60,12 @@ export async function checkNextSpeaker(
chat: Chat,
geminiClient: GeminiClient,
): Promise<NextSpeakerResponse | null> {
- const history = await chat.getHistory();
+ // We need to capture the curated history because there are many moments when the model will return invalid turns
+ // that when passed back up to the endpoint will break subsequent calls. An example of this is when the model decides
+ // to respond with an empty part collection if you were to send that message back to the server it will respond with
+ // a 400 indicating that model part collections MUST have content.
+ const history = await chat.getHistory(/* curated */ true);
+
// Ensure there's a model response to analyze
if (history.length === 0 || history[history.length - 1].role !== 'model') {
// Cannot determine next speaker if the last turn wasn't from the model