Skip to content

Conversation

@RumiDaNeko
Copy link

please test this, neko told me that i need to push here

please test this, neko told me that i need to push here
@gemini-code-assist
Copy link

Summary of Changes

Hello @RumiDaNeko, 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 introduces a new backend component to support Text-to-Speech (TTS) services leveraging Cloudflare Workers AI. It establishes the necessary Go code to construct requests, communicate with Cloudflare's TTS models (specifically @cf/myshell-ai/melotts), manage API responses, and stream the generated audio output, thereby expanding the application's speech synthesis capabilities.

Highlights

  • Cloudflare TTS Integration: A new Go file cloudflare.go has been added to integrate Text-to-Speech (TTS) functionality via Cloudflare Workers AI.
  • HandleSpeechCloudflare Function: Introduces a new function HandleSpeechCloudflare responsible for orchestrating the TTS request to Cloudflare, including model selection and payload construction.
  • Cloudflare API Interaction: The implementation includes building the Cloudflare API request, setting necessary headers (like Authorization and Content-Type), and executing the HTTP call.
  • Error Handling & Streaming: Robust error handling is included for upstream Cloudflare API responses (JSON, text, or unknown content types), and successful audio streams are directly proxied back to the client.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new backend for Cloudflare AI Text-to-Speech. The overall structure is a good start, but there are several critical and high-severity issues that need to be addressed before this can be merged. My review focuses on making the implementation robust, configurable, and integrated correctly with the existing application structure. Key issues include a potential panic from unsafe option unwrapping, use of http.DefaultClient without timeouts, improper error handling for response streaming, and problems with configuration handling (accountID) and integration. I've also included a suggestion to make the model selection dynamic as intended.


// HandleSpeechCloudflare processes a TTS request using the Cloudflare Workers AI API.
// It requires the Cloudflare Account ID to be passed in.
func HandleSpeechCloudflare(c echo.Context, accountID string, options mo.Option[types.SpeechRequestOptions]) mo.Result[any] {

Choose a reason for hiding this comment

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

critical

The function signature for HandleSpeechCloudflare takes an accountID parameter, which is inconsistent with other backend handlers and makes it difficult to integrate. Configuration like account IDs should typically be managed via environment variables for better portability and consistency. I'd recommend changing the function signature to remove the accountID parameter.

You can then add the following code at the beginning of the function (you'll need to import os):

accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
if accountID == "" {
    return mo.Err[any](apierrors.NewErrInternal().WithDetail("CLOUDFLARE_ACCOUNT_ID environment variable not set").WithCaller())
}

Also, remember to register this new backend in pkg/backend/backend.go so it can be used.

Suggested change
func HandleSpeechCloudflare(c echo.Context, accountID string, options mo.Option[types.SpeechRequestOptions]) mo.Result[any] {
func HandleSpeechCloudflare(c echo.Context, options mo.Option[types.SpeechRequestOptions]) mo.Result[any] {

// --- 6. Stream Successful Audio Response ---
// On success, Cloudflare returns the raw audio stream directly in the body.
// The Content-Type (e.g., "audio/mpeg") is correctly proxied.
return mo.Ok[any](c.Stream(http.StatusOK, res.Header.Get("Content-Type"), res.Body))

Choose a reason for hiding this comment

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

high

The return value of c.Stream is an error. By wrapping it in mo.Ok[any](...), you are treating a potential error as a success case, which will hide streaming failures. The error should be checked and handled. Since headers will have already been sent at this point, you cannot send a JSON error response, but logging the error is important for debugging.

	if err := c.Stream(http.StatusOK, res.Header.Get("Content-Type"), res.Body); err != nil {
		slog.ErrorContext(c.Request().Context(), "failed to stream response", "err", err)
	}
	return mo.Ok[any](nil)

// - @cf/deepgram/aura-1 (supports 'text' param)
//
// We'll use @cf/myshell-ai/melotts as an example.
const modelName = "@cf/myshell-ai/melotts"

Choose a reason for hiding this comment

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

medium

The modelName is hardcoded, which limits the flexibility of this backend. As the comment on the preceding lines suggests, this should be dynamic. You can use the opt.Model field from the request options and fall back to a default model if it's not provided.

Suggested change
const modelName = "@cf/myshell-ai/melotts"
modelName := opt.Model
if modelName == "" {
modelName = "@cf/myshell-ai/melotts"
}

Copy link
Member

Choose a reason for hiding this comment

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

Let's follow this.

@kwaa kwaa requested a review from nekomeowww October 31, 2025 15:32
@RumiDaNeko
Copy link
Author

appearently, gemini verifying it own code as wrong dang

@nekomeowww nekomeowww changed the title Create cloudflare.go feat: add Cloudflare Jan 2, 2026
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