class
AI::OpenAI::OpenAIProvider
- AI::OpenAI::OpenAIProvider
- Reference
- Object
Overview
OpenAI provider.
Provides factory methods for creating OpenAI models:
#chat- Chat completion models (gpt-4o, gpt-4, gpt-3.5-turbo, etc.)#embedding- Embedding models (text-embedding-3-small/large)#image- Image generation models (dall-e-2, dall-e-3, gpt-image-1)#speech- Text-to-speech models (tts-1, tts-1-hd, gpt-4o-mini-tts)#transcription- Speech-to-text models (whisper-1, gpt-4o-transcribe)
Example:
provider = AI::OpenAI.create_openai(api_key: "sk-...")
model = provider.chat("gpt-4o")
result = model.do_generate(options)
Included Modules
Defined in:
ai/openai/openai_provider.crConstructors
Instance Method Summary
-
#chat(model_id : String) : OpenAIChatLanguageModel
Creates a chat model for text generation.
-
#embedding(model_id : String) : OpenAIEmbeddingModel
Alias for embedding_model.
-
#embedding_model(model_id : String) : OpenAIEmbeddingModel
Creates an embedding model.
-
#image(model_id : String) : OpenAIImageModel
Alias for image_model.
-
#image_model(model_id : String) : OpenAIImageModel
Creates an image model.
-
#language_model(model_id : String) : OpenAIChatLanguageModel
Alias for chat - creates a language model.
-
#provider_name : String
Provider name.
-
#responses(model_id : String) : Responses::OpenAIResponsesLanguageModel
Creates a responses model for GPT-5, o3, o4-mini, etc.
-
#specification_version : String
The specification version.
-
#speech(model_id : String) : OpenAISpeechModel
Alias for speech_model.
-
#speech_model(model_id : String) : OpenAISpeechModel
Creates a speech model for text-to-speech synthesis.
-
#text_embedding(model_id : String) : OpenAIEmbeddingModel
Deprecated: Use embedding instead.
-
#text_embedding_model(model_id : String) : OpenAIEmbeddingModel
Deprecated: Use embedding_model instead.
-
#tools : Tools.class
Access to OpenAI-specific tools.
-
#transcription(model_id : String) : OpenAITranscriptionModel
Alias for transcription_model.
-
#transcription_model(model_id : String) : OpenAITranscriptionModel
Creates a transcription model for speech-to-text.
Instance methods inherited from module AI::Provider::Provider::V3
embedding_model(model_id : String) : EmbeddingModel::V3
embedding_model,
image_model(model_id : String) : ImageModel::V3
image_model,
language_model(model_id : String) : LanguageModel::V3
language_model,
reranking_model(model_id : String) : RerankingModel::V3
reranking_model,
specification_version : String
specification_version,
speech_model(model_id : String) : SpeechModel::V3
speech_model,
text_embedding_model(model_id : String) : EmbeddingModel::V3
text_embedding_model,
transcription_model(model_id : String) : TranscriptionModel::V3
transcription_model
Constructor Detail
Instance Method Detail
Creates a chat model for text generation.
Supports all OpenAI chat models including:
- gpt-4o, gpt-4o-mini
- gpt-4-turbo, gpt-4
- gpt-3.5-turbo
- o1, o1-mini, o1-preview
- o3, o3-mini
- o4-mini
- gpt-5, gpt-5-mini
Creates an embedding model.
Supports:
- text-embedding-3-small
- text-embedding-3-large
- text-embedding-ada-002
Creates an image model.
Supports:
- dall-e-2
- dall-e-3
- gpt-image-1
Alias for chat - creates a language model.
By default, returns a chat model. Use the #chat method
explicitly for chat completion models.
Creates a responses model for GPT-5, o3, o4-mini, etc.
The Responses API provides advanced features like:
- MCP (Model Context Protocol) integration
- Shell/LocalShell execution
- ApplyPatch for code editing
- Image generation tool
- File search with vector stores
- Code interpreter
- Web search with citations
Supports:
- gpt-5, gpt-5-mini, gpt-5-nano, gpt-5-pro
- gpt-5.1, gpt-5.2
- o3, o3-mini, o4-mini
- gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
- gpt-4o, gpt-4o-mini
Creates a speech model for text-to-speech synthesis.
Supports:
- tts-1 - Fast text-to-speech model
- tts-1-hd - High-definition text-to-speech model
- gpt-4o-mini-tts - GPT-4o mini text-to-speech model
Example:
speech_model = provider.speech("tts-1")
result = speech_model.do_generate(
AI::Provider::SpeechModel::CallOptions.new(
text: "Hello, world!",
voice: "alloy"
)
)
File.write("output.mp3", result.audio)
Deprecated: Use embedding_model instead.
Access to OpenAI-specific tools.
Returns the Tools module containing provider-defined tools like:
- WebSearch
- CodeInterpreter
- FileSearch
- ImageGeneration
- Shell
- LocalShell
- ApplyPatch
- Mcp
Creates a transcription model for speech-to-text.
Supports:
- whisper-1 - Whisper transcription model
- gpt-4o-mini-transcribe - GPT-4o mini transcription model
- gpt-4o-transcribe - GPT-4o transcription model
Example:
transcription_model = provider.transcription("whisper-1")
result = transcription_model.do_generate(
AI::Provider::TranscriptionModel::CallOptions.new(
audio: File.read("audio.mp3").to_slice,
media_type: "audio/mp3"
)
)
puts result.text