Skip to content

feat: add URL-safe base64 decoding for Google GenAI and improve parameter handling#89

Merged
akshaydeo merged 1 commit intomainfrom
06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration
Jun 16, 2025
Merged

feat: add URL-safe base64 decoding for Google GenAI and improve parameter handling#89
akshaydeo merged 1 commit intomainfrom
06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration

Conversation

@Pratham-Mishra04
Copy link
Copy Markdown
Collaborator

Add support for URL-safe base64 decoding in Google GenAI requests

This PR adds custom types to handle URL-safe base64 encoding in Google GenAI requests. When clients send base64-encoded image data using URL-safe encoding (replacing '/' with '_' and '+' with '-'), the standard decoder fails.

The changes include:

  • Added CustomBlob type with custom JSON unmarshalling to handle URL-safe base64 decoding
  • Created CustomPart and CustomContent types that wrap the GenAI SDK types
  • Added conversion methods to transform the custom types back to standard GenAI SDK types
  • Updated the OpenAI parameter handling to use the proper parameter fields instead of storing values in ExtraParams

This ensures proper handling of image data in multimodal requests while maintaining compatibility with the existing API.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 16, 2025

Caution

Review failed

The pull request is closed.

Summary by CodeRabbit

  • New Features
    • Improved handling of Google GenAI request payloads with support for URL-safe base64 encoded blobs.
  • Bug Fixes
    • Enhanced conversion of OpenAI chat parameters to ensure model parameters are assigned directly, improving reliability.
  • Chores
    • Updated .gitignore to better exclude Python __pycache__ directories and their contents.

Summary by CodeRabbit

  • New Features
    • Improved handling of Google GenAI request payloads with support for URL-safe base64 encoded blobs in chat requests.
  • Refactor
    • Streamlined conversion of OpenAI chat request parameters by assigning key values directly to model parameter fields, removing unnecessary mapping and response format handling.

Walkthrough

Custom types and unmarshalling logic were introduced in the GenAI integration to handle URL-safe base64 blobs and adapt request payloads. The OpenAI integration was updated to assign model parameters directly to struct fields instead of using a generic map, and the response format handling was removed. The .gitignore was extended to recursively ignore all contents inside any __pycache__ directories.

Changes

File(s) Change Summary
transports/bifrost-http/integrations/genai/types.go Added CustomBlob, CustomPart, and CustomContent types with custom unmarshalling and conversion methods. Modified GeminiChatRequest to use these types.
transports/bifrost-http/integrations/openai/types.go Changed parameter mapping to assign values directly to struct fields; removed response format handling from extra parameters.
.gitignore Added pattern **/__pycache__/** to recursively ignore all files inside any __pycache__ directories.

Suggested reviewers

  • danpiths

Poem

In the code fields where base64 hops,
New blobs and parts make data drops.
Parameters now take their rightful place,
No more maps, just fields with grace.
The rabbit twitches with delight,
For cleaner code and types done right! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0263e2c and 92a8099.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • transports/bifrost-http/integrations/genai/types.go (3 hunks)
  • transports/bifrost-http/integrations/openai/types.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch 06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration
  • Post Copyable Unit Tests in Comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Collaborator Author

Pratham-Mishra04 commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
transports/bifrost-http/integrations/openai/types.go (1)

60-63: Avoid emitting an unnecessary empty extra_params object

ExtraParams is pre-allocated even when no extra parameters will ultimately be inserted.
Serialising an empty map produces "extra_params":{} in downstream payloads, which is semantically useless and adds bytes on the wire.

-	params := &schemas.ModelParameters{
-		ExtraParams: make(map[string]interface{}),
-	}
+	params := &schemas.ModelParameters{}

Only allocate the map lazily in the few branches that still rely on it (n, logprobs, …).
This keeps the JSON lean while preserving behaviour.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63ba08e and 0263e2c.

📒 Files selected for processing (2)
  • transports/bifrost-http/integrations/genai/types.go (3 hunks)
  • transports/bifrost-http/integrations/openai/types.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
transports/bifrost-http/integrations/genai/types.go (1)
core/schemas/bifrost.go (1)
  • FunctionCall (365-368)
🔇 Additional comments (2)
transports/bifrost-http/integrations/openai/types.go (1)

68-82: Double-check that the Bifrost schema exposes the direct fields you’re populating

The code now writes directly to MaxTokens, Temperature, TopP, PresencePenalty, and FrequencyPenalty.
If the schemas.ModelParameters struct in core/schemas has not yet been augmented with matching pointer fields, these assignments will silently do nothing and the values will be lost.

Please verify the struct definition; if the fields do not exist, either add them or fall back to ExtraParams for the time being.

transports/bifrost-http/integrations/genai/types.go (1)

58-69: Potential (de)serialisation mismatch for embedded GenAI SDK structs

genai_sdk.VideoMetadata, ExecutableCode, etc. do not carry json tags.
When the server receives raw JSON, encoding/json will attempt to match on exported field names of those embedded structs, which may not align with the wire protocol and can easily break with upstream SDK changes.

Consider wrapping only the minimal fields you actually need in your own DTOs or implement json.Unmarshaler/Marshaler on CustomPart to take full control of the layout.

Comment thread transports/bifrost-http/integrations/genai/types.go
Comment thread transports/bifrost-http/integrations/genai/types.go
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration branch from 0263e2c to 003df5d Compare June 16, 2025 14:51
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-14-feat_http-transports_integration_tests_added branch from 63ba08e to 8a16392 Compare June 16, 2025 15:00
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration branch from 003df5d to 418d7ae Compare June 16, 2025 15:00
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-14-feat_http-transports_integration_tests_added branch from 8a16392 to 6b47876 Compare June 16, 2025 15:01
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration branch from 418d7ae to c80be38 Compare June 16, 2025 15:01
Copy link
Copy Markdown
Contributor

akshaydeo commented Jun 16, 2025

Merge activity

  • Jun 16, 3:18 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 16, 3:22 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 16, 3:24 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo akshaydeo changed the base branch from 06-14-feat_http-transports_integration_tests_added to graphite-base/89 June 16, 2025 15:19
@akshaydeo akshaydeo changed the base branch from graphite-base/89 to main June 16, 2025 15:21
@akshaydeo akshaydeo force-pushed the 06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration branch from c80be38 to 92a8099 Compare June 16, 2025 15:22
@akshaydeo akshaydeo merged commit f271a8c into main Jun 16, 2025
1 of 2 checks passed
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: OpenAI Request Format Ignored

The ResponseFormat parameter is no longer processed in the convertParameters method. It was previously stored in params.ExtraParams["response_format"] but is now entirely ignored, causing OpenAI requests to lose this specification and resulting in a loss of functionality.

transports/bifrost-http/integrations/openai/types.go#L102-L106

params.ExtraParams["stream"] = *r.Stream
}
if r.Seed != nil {
params.ExtraParams["seed"] = *r.Seed
}

Fix in Cursor


BugBot free trial expires on June 17, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@akshaydeo akshaydeo deleted the 06-16-enhancement_added_custom_genai_part_type_for_better_handling_in_genai_integration branch August 31, 2025 17:29
akshaydeo added a commit that referenced this pull request Nov 17, 2025
…eter handling (#89)

# Add support for URL-safe base64 decoding in Google GenAI requests

This PR adds custom types to handle URL-safe base64 encoding in Google GenAI requests. When clients send base64-encoded image data using URL-safe encoding (replacing '/' with '_' and '+' with '-'), the standard decoder fails. 

The changes include:
- Added `CustomBlob` type with custom JSON unmarshalling to handle URL-safe base64 decoding
- Created `CustomPart` and `CustomContent` types that wrap the GenAI SDK types
- Added conversion methods to transform the custom types back to standard GenAI SDK types
- Updated the OpenAI parameter handling to use the proper parameter fields instead of storing values in ExtraParams

This ensures proper handling of image data in multimodal requests while maintaining compatibility with the existing API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants