feat(completions): add CompletionPreparationStage for gRPC pipeline - #907
Conversation
Signed-off-by: VS Chandra Mourya <msrinivasa@together.ai>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the gRPC pipeline by introducing a dedicated preparation stage for native completion requests. This change streamlines the processing of Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds Completion API handling to the gRPC pipeline: new Changes
Sequence DiagramsequenceDiagram
participant Client
participant PreparationStage
participant CompletionPreparationStage
participant Tokenizer
participant StopDecoder
participant RequestContext
Client->>PreparationStage: execute(ctx: CompletionRequest)
PreparationStage->>CompletionPreparationStage: execute(ctx)
CompletionPreparationStage->>RequestContext: completion_request_arc()
RequestContext-->>CompletionPreparationStage: CompletionRequest
CompletionPreparationStage->>CompletionPreparationStage: validate prompt (no batches)
CompletionPreparationStage->>Tokenizer: tokenize(prompt_text)
alt tokenization success
Tokenizer-->>CompletionPreparationStage: token_ids
CompletionPreparationStage->>StopDecoder: build(stop, stop_token_ids,...)
StopDecoder-->>CompletionPreparationStage: stop_decoder
CompletionPreparationStage->>RequestContext: store PreparationOutput + stop_decoder
CompletionPreparationStage-->>PreparationStage: Ok(None)
else tokenization failure
Tokenizer-->>CompletionPreparationStage: error
CompletionPreparationStage->>CompletionPreparationStage: emit trace error
CompletionPreparationStage-->>PreparationStage: bad_request(tokenization_failed)
end
PreparationStage-->>Client: final response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Code Review
This pull request introduces the initial CompletionPreparationStage for the /v1/completions gRPC endpoint, integrating it into the existing request processing pipeline. This new stage is responsible for resolving prompts, tokenizing input, and creating a stop decoder for completion requests. The review feedback suggests improving code consistency by removing the new() method from CompletionPreparationStage and instantiating it directly as a struct literal, mirroring the approach used for other similar pipeline stages.
Signed-off-by: VS Chandra Mourya <msrinivasa@together.ai>
…mg-project#907) Signed-off-by: VS Chandra Mourya <msrinivasa@together.ai>
Description
Problem
#840 introduced native
/v1/completionstyping in the gRPC pipeline by addingRequestType::Completion,FinalResponse::Completion,RequestContext::for_completion(), andexecute_completion().What is still missing is the first endpoint-specific stage for completions, so completion requests still do not have a dedicated Stage 1 preparation flow.
Solution
Add
CompletionPreparationStageas the Stage 1 preparation step for native completion requests in the regular gRPC pipeline. This keepsCompletionRequestnative in the pipeline and prepares the request directly from completion fields instead of routing through chat-style message templating or laundering throughGenerateRequest.What changed
New:
regular/stages/completion/model_gateway/src/routers/grpc/regular/stages/completion/mod.rsmodel_gateway/src/routers/grpc/regular/stages/completion/preparation.rsNew:
CompletionPreparationStageCreated as the completion-specific Stage 1 preparation step, parallel in role to
MessagePreparationStagefrom the Messages rollout, but much simpler because/v1/completionsdoes not need message-block conversion or chat-template rendering.It currently:
CompletionRequestnatively fromRequestContextpromptstringPreparationOutputandstop_decoderin context for later stagesModified
model_gateway/src/routers/grpc/regular/stages/mod.rscompletionstages modulemodel_gateway/src/routers/grpc/regular/stages/preparation.rsRequestType::Completion(_)toCompletionPreparationStagemodel_gateway/src/routers/grpc/context.rs#[expect(dead_code)]fromcompletion_request_arc()now that it is used by the new completion preparation stageTest plan
cargo fmt -p smgcargo check -p smgChecklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspassesSummary by CodeRabbit
New Features
Bug Fixes