Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate new method into OpenAIModel for transcription #1009

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

rroblf01
Copy link

@rroblf01 rroblf01 commented Feb 27, 2025

Since OpenAI supports transcribing audios, it would be interesting to integrate this method into OpenAIModel

Example of Audio Transcription with OpenAIModel

This example shows how to use the OpenAIModel class from the pydantic_ai.models.openai module to transcribe an audio file using the OpenAI API.

Example Code

import asyncio

from pydantic_ai.models.openai import OpenAIModel

# Initialize the OpenAI model with the desired model name
openai_model = OpenAIModel(model_name='whisper-1')


# Asynchronous function to get the transcription of the audio file
async def get_transcription():
    # Open the audio file in binary mode
    with open('/path/to/audio.mp3', 'rb') as audio_file:
        # Call the transcription method of the model
        transcription_text = await openai_model.transcription(audio_file)

    return transcription_text


if __name__ == '__main__':
    # Run the asynchronous function
    asyncio.run(get_transcription())

An example of a response could be

Lorem ipsum dolor sit amet consectetur adipiscing elit congue, ridiculus dapibus porttitor suspendisse torquent netus elementum ornare, eros quisque lacinia taciti imperdiet consequat magna. Lectus ad vel mollis pretium eget commodo donec velit, elementum phasellus libero himenaeos dictumst nascetur nibh penatibus egestas, proin varius condimentum curabitur venenatis ultrices hendrerit. Iaculis etiam fringilla viverra porttitor cras tortor molestie dictum, tristique lacus tincidunt torquent ultrices natoque ad lectus nisl, facilisis phasellus quam nibh consequat quisque pulvinar.

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.

1 participant