Skip to content

Conversation

@mediix
Copy link

@mediix mediix commented Nov 29, 2025

resolve #9086

Summary

This PR adds comprehensive Google-style docstrings to the Audio class in dspy/adapters/types/audio.py, covering 6 public APIs.

Changes

  • Added class docstring for Audio with description, attributes, and usage examples
  • Added method docstrings for:
    • format() - Formats audio data for LM consumption
    • from_url() - Creates Audio from URL
    • from_file() - Creates Audio from file path
    • from_array() - Creates Audio from numpy array
  • Added function docstring for:
    • encode_audio() - Encodes audio from various sources
  • Included usage examples in all docstrings
  • All docstrings follow Google Python Style Guide

Checklist

  • All public classes have docstrings
  • All public methods/functions have docstrings
  • Docstrings follow Google style format
  • Included Args:, Returns:, Raises: sections where applicable
  • Added Examples: showing typical usage
  • Docstrings are technically accurate
  • Pre-commit hooks pass (ruff check + format)

Testing

# Validated with ruff
uv tool run ruff check dspy/adapters/types/audio.py
# All checks passed!

uv tool run ruff format dspy/adapters/types/audio.py
# 1 file reformatted

@chenmoneygithub - Ready for review!

Copy link
Collaborator

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This looks pretty good, dropped some comments.

"""A type for representing audio data in DSPy.
The Audio class provides a standardized way to handle audio inputs for language models
that support audio processing. Audio data is stored as base64-encoded strings along
Copy link
Collaborator

Choose a reason for hiding this comment

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

"stored" reads a bit strange, do you mean represented?

data: Base64-encoded audio data.
audio_format: The audio format (e.g., "wav", "mp3", "flac").
Example:
Copy link
Collaborator

Choose a reason for hiding this comment

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

For multiple examples, use one-line format like "Example: Basic usage with a local file"

audio-enabled language models.
Raises:
ValueError: If the audio data cannot be formatted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove this Raises part. Actually the code is strange, which raises exception when self.data is empty.

"""Format the audio data for consumption by language models.
Returns:
A list containing the audio block in the format expected by
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is vague, we can write the format explicitly.

Args:
audio: The audio input. Supported types include:
- ``str``: Local file path, HTTP(S) URL, or data URI
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: use single backtick

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.

[docs] Add Google-style docstrings for dspy/adapters/types/audio.py Audio class

2 participants