Skip to content

feat: Google live audio output - #4280

Merged
adelmuursepp merged 27 commits into
mainfrom
feat/google-live-audio-output
Jun 10, 2025
Merged

adelmuursepp merged 27 commits into
mainfrom
feat/google-live-audio-output

Conversation

@adelmuursepp

@adelmuursepp adelmuursepp commented Jun 2, 2025 •

Copy link
Copy Markdown
Contributor

Overview

Implemented audio output support for Google's Live API, enabling audio generation, transcription, and advanced features like affective dialog and voice customization. Yet to cover coercing the model to speak in specific language, turn coverage, proactive audio and features involving audio as input.

Key Features Added

  1. Audio Output Support in Google Live Provider

  2. New Audio Examples (examples/google-live-audio/)
    Created three examples demonstrating audio capabilities:

    a) Simple Audio Generation (promptfooconfig.yaml)
    b) Affective Dialog (promptfooconfig.audio-affective.yaml)
    c) Voice Customization (promptfooconfig.audio-voices.yaml)

  3. UI Enhancements for Audio Display

  • Modified EvalOutputCell.tsx to properly display audio outputs. Added download audio button (decided not to generate files in the folder)

Testing

  • Added unit tests in test/providers/google/live.test.ts
  • Tested end to end manually and cross checked with AI studio
  • Tests cover audio output, transcription, and error handling

image

Amazon Bedrock Nova speech to speech:
image

OpenAI audio:
image

@adelmuursepp adelmuursepp changed the title feat: google live audio output feat: Google live audio output Jun 2, 2025
@adelmuursepp
adelmuursepp marked this pull request as ready for review June 4, 2025 21:07
@gru-agent

This comment was marked as resolved.

greptile-apps[bot]

This comment was marked as resolved.

sourcery-ai[bot]

This comment was marked as resolved.

Comment thread src/providers/google/live.ts Resolved
Comment thread src/providers/google/live.ts Resolved
Comment thread src/providers/google/live.ts Resolved
mldangelo

This comment was marked as resolved.

@adelmuursepp

This comment was marked as resolved.

@adelmuursepp

Copy link
Copy Markdown
Contributor Author

You put so much work into this. Thank you. It looks great. A few nits about documentation but overall it is really good.
Question for the future: How do you want to grade audio content with llm-as-a-judge?

Let me address the suggestions, thanks!

There is another interesting aspect to think about. I see in your OpenAI audio example that the transcript is moved in the text field which allows to run llm rubric on it. Transcript is for me in context.providerResponse.audio.transcript.

a) Transcript could be copied over to text. Which makes sense
b) For now for Google Live audio audio thinking models the text is filled with the model's thinking process, which is very interesting to read. I agree it doesn't belong there. But disregard thinking process or copy it somewhere else?

@mldangelo

Copy link
Copy Markdown
Member

Good points @adelmuursepp!. We should use the model graded metrics just like how the openai models work. Re thinking processes - how about putting them in metadata instead (feel free to disagree). Thank you so much!

adelmuursepp and others added 2 commits June 7, 2025 22:30
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@coderabbitai

This comment was marked as duplicate.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (10)
examples/google-live-audio/promptfooconfig.yaml (1)

30-36: 🧹 Nitpick (assertive)

Consider using optional chaining for cleaner code.

The null checks can be simplified using the optional chaining operator (?.) as suggested in past reviews. While verbose examples are educational, modern JavaScript syntax would also be a good learning example.

-          if (context.providerResponse && context.providerResponse.audio && context.providerResponse.audio.transcript) {
-            return context.providerResponse.audio && 
-                  context.providerResponse.audio.data && 
-                  context.providerResponse.audio.transcript && 
-                  context.providerResponse.audio.transcript.length > 0;
-          }
+          return context.providerResponse?.audio?.transcript?.length > 0 &&
+                 context.providerResponse?.audio?.data;
examples/google-live-audio/promptfooconfig.audio-affective.yaml (1)

7-14: 🧹 Nitpick (assertive)

Consider using variables for prompts to improve reusability.

As suggested in past reviews, using variables instead of hardcoded prompts would make the configuration more flexible and demonstrate better practices.

 prompts:
-  - label: 'Positive input'
-    raw: It's a new dawn, it's a new day, and I'm feeling good.
-
-  - label: 'Negative Input'
-    raw: |
-      I looked in the fridge and I found nothing. 
-      I think someone ate my sandwich
+  - label: 'Positive input'
+    raw: '{{positive_statement}}'
+  - label: 'Negative Input'
+    raw: '{{negative_statement}}'

Then add test cases with the variables defined:

tests:
  - vars:
      positive_statement: "It's a new dawn, it's a new day, and I'm feeling good."
      negative_statement: |
        I looked in the fridge and I found nothing. 
        I think someone ate my sandwich
    assert:
      # existing assertions
examples/google-live-audio/promptfooconfig.audio-voices.yaml (1)

7-8: 🧹 Nitpick (assertive)

Consider using a variable for the prompt to improve flexibility.

As suggested in past reviews, using a variable instead of a hardcoded prompt would make the configuration more flexible and reusable.

 prompts:
-  - 'Why was Gemini model by Google named Gemini?'
+  - '{{question}}'

Then define the variable in test cases:

tests:
  - vars:
      question: 'Why was Gemini model by Google named Gemini?'
    assert:
      # existing assertions
examples/google-live-audio/README.md (3)

16-22: 🛠️ Refactor suggestion

Add the standard initialization command.

As discussed in past reviews, the standard npx promptfoo@latest init --example google-live-audio command should be added now that it will work after merging to main.

 ## Running the Examples
 
+First, initialize the example:
+
+```bash
+npx promptfoo@latest init --example google-live-audio
+```
+
 After running any evaluation, you can view the results by running:

73-73: ⚠️ Potential issue

Fix the relative link to use absolute URL.

The relative link may not resolve correctly as noted in past reviews. Use an absolute URL to the documentation.

-For more information about the Google Live API and audio capabilities, see the [Google AI documentation](/docs/providers/google).
+For more information about the Google Live API and audio capabilities, see the [Google AI documentation](https://promptfoo.dev/docs/providers/google).

12-12: 🧹 Nitpick (assertive)

Clarify environment variable specification.

As suggested in past reviews, specify 'environment variable' for clarity.

-- Google AI Studio API key set as the environment variable `GOOGLE_API_KEY`
+- Google AI Studio API key set as the environment variable `GOOGLE_API_KEY`
src/providers/google/live.ts (4)

57-86: Manual WAV header creation remains fragile.

The manual construction of WAV headers could lead to subtle bugs. Consider using a dedicated audio library for more robust WAV encoding.


134-136: Fixed startup delay for Python API remains fragile.

Using a fixed 1-second delay could cause race conditions or unnecessary waiting. Implement a health check endpoint as previously suggested.


485-487: Warning suggests incomplete implementation.

The warning message indicates that HTTP client functionality was removed but the configuration option remains.


600-613: Promise may remain unresolved on unexpected close.

The close handler should resolve or reject the promise if finalizeResponse hasn't executed to prevent hanging promises.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1f20ac and f3dd1c5.

📒 Files selected for processing (7)
  • examples/google-live-audio/README.md (1 hunks)
  • examples/google-live-audio/promptfooconfig.audio-affective.yaml (1 hunks)
  • examples/google-live-audio/promptfooconfig.audio-voices.yaml (1 hunks)
  • examples/google-live-audio/promptfooconfig.yaml (1 hunks)
  • src/providers/google/live.ts (5 hunks)
  • src/providers/google/types.ts (2 hunks)
  • test/providers/google/live.test.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
test/providers/google/live.test.ts (1)
src/providers/google/live.ts (1)
  • GoogleLiveProvider (40-616)
src/providers/google/live.ts (4)
src/logger.ts (1)
  • logger (191-203)
examples/google-live/promptfooconfig.callback.js (1)
  • JSON (33-33)
src/providers/google/types.ts (1)
  • FunctionCall (8-11)
src/providers/google/util.ts (1)
  • loadFile (370-397)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test on Node 18.x and windows-latest
🔇 Additional comments (4)
src/providers/google/types.ts (2)

135-155: LGTM! Comprehensive audio configuration types added.

The new type definitions for speech configuration, transcription, affective dialog, and proactive audio features are well-structured and comprehensive. They properly support the new Google Live Audio API capabilities demonstrated in the example configurations.


99-99: Good clarification on apiVersion values.

The updated comment clearly specifies the accepted values and default, which helps developers understand the API versioning for Live API features.

test/providers/google/live.test.ts (2)

620-620: Good addition to verify the final state retrieval endpoint.

This assertion ensures that the last GET request is made to the correct endpoint for retrieving the final state of the stateful API, which aligns with the implementation in src/providers/google/live.ts lines 195-196.


859-1047: Well-structured and comprehensive test suite for audio configurations.

The tests thoroughly cover all audio-related configuration options including proactivity, affective dialog, and transcription settings. The test cases properly verify:

  • Correct transformation of configuration property names (camelCase to snake_case)
  • Proper placement of configurations (generation_config vs setup level)
  • Behavior when configurations are present vs absent
  • All configurations working together

Comment thread test/providers/google/live.test.ts Resolved
Comment thread src/providers/google/live.ts Resolved
@adelmuursepp

adelmuursepp commented Jun 7, 2025 •

Copy link
Copy Markdown
Contributor Author

Good points @adelmuursepp!. We should use the model graded metrics just like how the openai models work. Re thinking processes - how about putting them in metadata instead (feel free to disagree). Thank you so much!

I like how Bedrock shows extra fields in the metadata, it is cleaner. But the other providers generally show fields like function and tool calls in the output directly. I think it is better to be consistent in showing extra fields. I am not going to change how other Live provider examples work, so I would rather place it in the output for now. And refactor all into text and metadata in Live provider later.

{
    output: {
      text: "transcript text",
      toolCall: { functionCalls: [...] }, // Always showing, even when empty
      statefulApiState: ..., // Different example, only when present
      thinking: "thinking process text"  // Only when present
    },
    audio: { ... }
  }

image

For quick reference, metadata:

image

@mldangelo you will know how to be consistent and organize thinking better in the other providers too going forward probably?

@mldangelo mldangelo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @adelmuursepp!

@@ -0,0 +1,2 @@
- role: user

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, for a simple prompt, consider defining it inline in examples/google-live-audio/promptfooconfig.yaml instead of a different file

@adelmuursepp
adelmuursepp merged commit 8dd32a6 into main Jun 10, 2025
@adelmuursepp
adelmuursepp deleted the feat/google-live-audio-output branch June 10, 2025 03:06
mldangelo pushed a commit that referenced this pull request Jun 12, 2025
meSingh pushed a commit to meSingh/promptfoo that referenced this pull request Sep 6, 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.

3 participants