-
Notifications
You must be signed in to change notification settings - Fork 136
[DO NOT MERGE] gemini-sdk-batch-support #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 11-28-batch-apis
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,17 +463,23 @@ func (provider *GeminiProvider) FileContent(ctx context.Context, key schemas.Key | |
| } | ||
|
|
||
| // ToGeminiFileUploadResponse converts a Bifrost file upload response to Gemini format. | ||
| func ToGeminiFileUploadResponse(resp *schemas.BifrostFileUploadResponse) map[string]interface{} { | ||
| return map[string]interface{}{ | ||
| "file": map[string]interface{}{ | ||
| "name": resp.ID, | ||
| "displayName": resp.Filename, | ||
| "mimeType": "application/octet-stream", | ||
| "sizeBytes": fmt.Sprintf("%d", resp.Bytes), | ||
| "createTime": formatGeminiTimestamp(resp.CreatedAt), | ||
| "state": toGeminiFileState(resp.Status), | ||
| "uri": resp.StorageURI, | ||
| "expirationTime": formatGeminiTimestamp(safeDerefInt64(resp.ExpiresAt)), | ||
| // Uses snake_case field names to match Google's API format. | ||
| // GeminiFileUploadResponseWrapper is a wrapper that contains the file response for the upload API. | ||
| type GeminiFileUploadResponseWrapper struct { | ||
| File GeminiFileResponse `json:"file"` | ||
| } | ||
|
|
||
| func ToGeminiFileUploadResponse(resp *schemas.BifrostFileUploadResponse) *GeminiFileUploadResponseWrapper { | ||
| return &GeminiFileUploadResponseWrapper{ | ||
| File: GeminiFileResponse{ | ||
| Name: resp.ID, | ||
| DisplayName: resp.Filename, | ||
| MimeType: "application/octet-stream", | ||
| SizeBytes: fmt.Sprintf("%d", resp.Bytes), | ||
| CreateTime: formatGeminiTimestamp(resp.CreatedAt), | ||
| State: toGeminiFileState(resp.Status), | ||
| URI: resp.StorageURI, | ||
| ExpirationTime: formatGeminiTimestamp(safeDerefInt64(resp.ExpiresAt)), | ||
| }, | ||
| } | ||
| } | ||
|
Comment on lines
+466
to
485
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gemini file upload wrapper matches expected SDK shape (minor doc nit) The new 🤖 Prompt for AI Agents |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix BatchStats computation to avoid negative pending counts
The SDK converters generally look good, but there’s a corner case in the stats math:
BatchRetrieve,BifrostBatchRetrieveResponse.RequestCountsis populated withCompletedandFailed, whileTotalis left at its zero value.ToGeminiBatchRetrieveResponseandToGeminiBatchListResponsecurrently useresp.RequestCounts.Totaldirectly to deriveRequestCountandPendingRequestCount.When
Total == 0andCompleted > 0,PendingRequestCount = Total - Completedbecomes negative, which is invalid.Consider defensively deriving totals and pending counts, for example:
and mirror the same pattern inside
ToGeminiBatchListResponsewhen populatingBatchStats, so the invariantsRequestCount ≥ 0,PendingRequestCount ≥ 0, andRequestCount ≈ success + failures + pendingalways hold.Also applies to: 899-919, 941-958
🤖 Prompt for AI Agents