feat: support Vertex Lyria 3 interactions relay()#4934
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
WalkthroughAdds support for native Vertex/Gemini interaction payloads: a new ChangesGemini Interaction Flow
Sequence DiagramsequenceDiagram
participant Client
participant RequestValidator
participant GeminiHandler
participant Adaptor
participant VertexAPI
participant QuotaService
Client->>RequestValidator: POST interactions with native payload
RequestValidator->>RequestValidator: Detect interactions path and unmarshal payload
RequestValidator-->>GeminiHandler: Validated GeminiInteractionRequest
GeminiHandler->>GeminiHandler: Validate lyria-3 model prefix and apply mapping
GeminiHandler->>Adaptor: Initialize by ApiType and DoRequest
Adaptor->>VertexAPI: POST interactions endpoint
VertexAPI-->>Adaptor: 2xx and native response bytes
Adaptor->>Adaptor: Validate status and read raw bytes
Adaptor-->>Client: Write raw bytes to response
Adaptor-->>GeminiHandler: Return usage
GeminiHandler->>QuotaService: Consume usage
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dto/gemini.go`:
- Around line 27-30: Change the GeminiInteractionRequest.Model field from string
to *string (keeping `json:"model,omitempty"`) so omitted vs explicit-empty is
preserved when parsing and re-marshaling; update any constructors, accessors and
JSON helpers that reference GeminiInteractionRequest.Model (and the similar
optional scalar fields noted around lines 73-82) to handle a nil pointer (e.g.,
use string dereference checks, helper getters that return empty string when nil,
and when setting the field allocate a new string), and ensure any relay/convert
code that builds or forwards the DTO treats Model as optional by checking for
nil before including it.
In `@relay/channel/vertex/adaptor.go`:
- Around line 178-184: The service-account branch currently returns a base
interactions URL without the model path; change the returned URL in adaptor.go
so it appends the model-specific endpoint "models/{model}:interactions" instead
of just "/interactions". Use the decoded credentials (adc or
a.AccountCredentials) to fetch the model identifier (e.g., adc.Model or
a.AccountCredentials.Model) and return fmt.Sprintf("%s/models/%s:interactions",
BuildAPIBaseURL(info.ChannelBaseUrl, OpenSourceAPIVersion, adc.ProjectID,
"global"), <model>) so Vertex calls hit the correct models/{model}:interactions
endpoint.
In `@relay/gemini_handler.go`:
- Around line 244-256: The code currently type-asserts resp with
resp.(*http.Response) without guarding for nil or wrong type, which can panic;
update the logic around statusCodeMappingStr/httpResp and the call to
adaptor.DoResponse: first check that resp is non-nil and of type *http.Response
(e.g., via httpResp, ok := resp.(*http.Response)); if not, construct and return
a structured relay error via service.RelayErrorHandler (using
c.Request.Context()) and call service.ResetStatusCode before returning; only
call adaptor.DoResponse(httpResp, info) when the assert succeeded and httpResp
is non-nil.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f14591b5-1221-435f-87fa-5a7d34a09ea2
📒 Files selected for processing (5)
dto/gemini.gorelay/channel/vertex/adaptor.gorelay/gemini_handler.gorelay/helper/valid_request.gosetting/ratio_setting/model_ratio.go
b577512 to
37492d1
Compare
37492d1 to
425d605
Compare
Important
支持 lyria-3-pro-preview 与 lyria-3-clip-preview 通过Vertex 原生路径 /v1beta/models/{model}:interactions 调用。
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit
New Features
Behavior & Validation
Usage