feat(sdk/go): add audio and file multimodal helpers#520
feat(sdk/go): add audio and file multimodal helpers#520AbirAbbas merged 6 commits intoAgent-Field:mainfrom
Conversation
|
Thanks for the PR @Sadit007, if you could sign the CLA, I can get started on reviewing this! |
@AbirAbbas Thanks for the heads up! I've just signed the CLA. Let me know if you need anything else from me during the review process. |
Performance
✓ No regressions detected |
📊 Coverage gateThresholds from
✅ Gate passedNo surface regressed past the allowed threshold and the aggregate stayed above the floor. |
📐 Patch coverage gateThreshold: 80% on lines this PR touches vs
✅ Patch gate passedEvery surface whose lines were touched by this PR has patch coverage at or above the threshold. |
Replace bare http.Get with a client that has a 30s timeout, and cap the response body at 50 MiB via io.LimitReader so a slow or oversized URL can't hang the caller or exhaust memory. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The auto-generated stub had no test cases (the loop body never ran) and silently passed. detectMIMEType is already covered by TestDetectMIMEType in multimodal_additional_test.go. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds tests for the read-error, fetch-error, HTTP-error, and size-cap branches so patch coverage stays above the 80% gate. Switches maxAudioURLBytes from const to var so the cap test can shrink it instead of streaming 50 MiB. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
AbirAbbas
left a comment
There was a problem hiding this comment.
Reviewed locally — looks good. Pushed three small follow-ups directly to the branch:
- bound
WithAudioURLwith a 30s client timeout and a 50 MiBio.LimitReadercap so a slow or oversized URL can't hang the caller or exhaust memory - dropped the empty
Test_detectMIMETypestub (detectMIMETypeis already covered byTestDetectMIMETypeinmultimodal_additional_test.go) - added error-path tests for
WithAudioFile/WithAudioURL/WithFile(read error, fetch error, HTTP non-200, size cap, file read error) so patch coverage stays above the gate — local coverage is now 100% onWithAudioFile/WithFileand 94.7% onWithAudioURL
Nice contribution, thanks for the parity work.
|
Thanks for the review and the final polish! Glad to contribute. |
Summary
Implements
WithAudioFile,WithAudioURL, andWithFilemultimodal helper functions for the Go SDK to achieve feature parity with the Python SDK. These functions enable Go agents to work with audio-capable and document-processing AI models from OpenAI, Anthropic, and Gemini without manually constructing content parts. All three functions properly base64-encode content, attach media type metadata, and produce valid provider-specific JSON compatible with LiteLLM.Type of change
Test plan
cd sdk/go && go test ./...— all Go SDK tests pass, including multimodalTestWithAudioFile— tests local audio file reading with base64 encoding (mp3 format)TestWithAudioURL— tests HTTP download and base64 encoding with mock server (wav format)TestWithFile— parameterized test for generic file types: PDF, Word (.docx), CSV, JSON, TXT, HTMLTest coverage
cd sdk/go && go test ./...✅WithAudioFile: reads file, base64 encodes, creates input_audio content partWithAudioURL: downloads file via HTTP, base64 encodes, creates input_audio content partWithFile: reads file, base64 encodes with data URL format, creates file content partChecklist
Related issues / PRs
Fixes #440