Skip to content

Conversation

@Pratham-Mishra04
Copy link
Collaborator

Summary

Refactors audio processing code to reduce duplication and improve maintainability across providers by extracting shared functionality into reusable handler functions.

Changes

  • Consolidated duplicate code in Mistral's transcription functionality by merging createMistralTranscriptionStreamMultipartBody and createMistralTranscriptionMultipartBody into a single function
  • Added a Stream parameter to the Mistral transcription request structure for better control
  • Created reusable handler functions in OpenAI provider for speech, speech streaming, transcription, and transcription streaming operations
  • Fixed raw request handling in OpenAI's speech endpoint to properly return request data when enabled
  • Improved error handling and logging consistency across audio processing functions

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (Next.js)
  • Docs

How to test

Test the audio processing functionality with both OpenAI and Mistral providers:

# Run all tests
go test ./core/providers/mistral/... ./core/providers/openai/...

# Test specific transcription functionality
go test ./core/providers/mistral -run TestCreateMistralTranscriptionMultipartBody

Breaking changes

  • No
  • Yes

Related issues

Improves code maintainability and reduces duplication in audio processing code.

Security considerations

No security implications as this is a refactoring of existing functionality.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Mistral transcription service added support for streaming transcription requests.
  • Refactor

    • OpenAI provider implementation restructured with unified request handlers for speech synthesis, transcription, and embedding services. New centralized handler functions manage HTTP request construction, response parsing, error handling, post-response transformation converters, and structured logging across all service endpoints.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Mistral transcription gained an optional Stream flag and unified multipart form construction for streaming and non-streaming requests. OpenAI provider logic was refactored to extract centralized handlers for Speech, Transcription, and Embedding (including streaming variants) with shared parameters and optional converter hooks.

Changes

Cohort / File(s) Summary
Mistral streaming & parsing consolidation
core/providers/mistral/types.go, core/providers/mistral/mistral.go, core/providers/mistral/transcription.go, core/providers/mistral/transcription_test.go
Added Stream *bool to MistralTranscriptionRequest. TranscriptionStream now sets Stream = true and uses the unified createMistralTranscriptionMultipartBody. Consolidated parsing into parseTranscriptionFormDataBodyFromRequest which conditionally writes the stream field; updated tests to call the unified body builder.
OpenAI centralized handlers & refactor
core/providers/openai/openai.go
Extracted centralized handlers: HandleOpenAISpeechRequest, HandleOpenAISpeechStreamRequest, HandleOpenAITranscriptionRequest, HandleOpenAITranscriptionStreamRequest, HandleOpenAIEmbeddingRequest. Refactored provider methods to delegate to these handlers, threading client, headers, auth, logger, and optional post-request/response converters. Removed or replaced several in-file helper/parsing duplications.
OpenAI transcription multipart helper
core/providers/openai/transcription.go
Added internal parseTranscriptionFormDataBodyFromRequest to build multipart form bodies (file field with filename, model, optional language, prompt, response_format, and conditional stream), included multipart imports and provider error handling.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review centralized OpenAI handler signatures and ensure all call sites pass correct clients, headers, auth, and converter hooks.
  • Verify streaming behavior and conditional stream field handling in Mistral multipart construction and tests.
  • Inspect error propagation and logging changes in streaming paths.

Possibly related PRs

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐰 I hopped in code, ears all a-twitch,
Stream flags set, multipart stitch by stitch.
OpenAI handlers lined in a row,
Converters twirl, streams start to flow —
A tiny rabbit cheers: nice and slick! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'refactor: openai and mistral audio refactored' is partially related to the changeset—it identifies the providers and general area (audio), but is somewhat vague and redundant ('refactored' appears twice). Revise to be more specific about the main change, e.g., 'refactor: consolidate audio handler functions across openai and mistral' or 'refactor: extract shared audio processing logic into reusable handlers'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The PR description covers all key template sections with sufficient detail: clear summary, specific changes listed, type marked, affected areas checked, testing instructions provided, no breaking changes noted, and checklist items completed.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7fd3bf and e8b50ea.

📒 Files selected for processing (6)
  • core/providers/mistral/mistral.go (1 hunks)
  • core/providers/mistral/transcription.go (2 hunks)
  • core/providers/mistral/transcription_test.go (2 hunks)
  • core/providers/mistral/types.go (3 hunks)
  • core/providers/openai/openai.go (20 hunks)
  • core/providers/openai/transcription.go (2 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator Author

Pratham-Mishra04 commented Dec 17, 2025

@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-16-feat_http_response_parsing_support_added branch from eeb6bc7 to d6c142a Compare December 17, 2025 15:42
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-16-refactor_openai_and_mistral_audio_refactor branch from f7fd3bf to 464bc24 Compare December 17, 2025 15:42
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-16-feat_http_response_parsing_support_added branch from d6c142a to f109532 Compare December 17, 2025 15:48
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-16-refactor_openai_and_mistral_audio_refactor branch from 464bc24 to e8b50ea Compare December 17, 2025 15:48
Copy link
Contributor

akshaydeo commented Dec 17, 2025

Merge activity

  • Dec 17, 3:51 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Dec 17, 3:53 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo akshaydeo changed the base branch from 12-16-feat_http_response_parsing_support_added to graphite-base/1112 December 17, 2025 15:51
@akshaydeo akshaydeo changed the base branch from graphite-base/1112 to main December 17, 2025 15:51
@akshaydeo akshaydeo merged commit c7dc0d7 into main Dec 17, 2025
2 checks passed
@akshaydeo akshaydeo deleted the 12-16-refactor_openai_and_mistral_audio_refactor branch December 17, 2025 15:53
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.

3 participants