Class: RubyLLM::Providers::OpenAI

Inherits:
RubyLLM::Provider show all
Includes:
Chat, Embeddings, Images, Media, Models, Moderation, Streaming, Tools, Transcription
Defined in:
lib/ruby_llm/providers/openai.rb,
lib/ruby_llm/providers/openai/chat.rb,
lib/ruby_llm/providers/openai/media.rb,
lib/ruby_llm/providers/openai/tools.rb,
lib/ruby_llm/providers/openai/images.rb,
lib/ruby_llm/providers/openai/models.rb,
lib/ruby_llm/providers/openai/streaming.rb,
lib/ruby_llm/providers/openai/embeddings.rb,
lib/ruby_llm/providers/openai/moderation.rb,
lib/ruby_llm/providers/openai/capabilities.rb,
lib/ruby_llm/providers/openai/transcription.rb

Overview

OpenAI API integration.

Direct Known Subclasses

DeepSeek, GPUStack, Mistral, Ollama, OpenRouter, Perplexity

Defined Under Namespace

Modules: Capabilities, Chat, Embeddings, Images, Media, Models, Moderation, Streaming, Tools, Transcription

Constant Summary

Constants included from Tools

Tools::EMPTY_PARAMETERS_SCHEMA

Instance Attribute Summary

Attributes inherited from RubyLLM::Provider

#config, #connection

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Transcription

encode_speaker_references, parse_transcription_response, render_transcription_payload, response_format_for, supports_chunking_strategy?, transcription_url

Methods included from Media

format_audio, format_content, format_image, format_pdf, format_text, format_text_file

Methods included from Images

images_url, parse_image_response, render_image_payload

Methods included from Tools

format_tool_calls, param_schema, parameters_schema_for, parse_tool_call_arguments, parse_tool_calls, schema_from_parameters, tool_for

Methods included from Streaming

build_chunk, parse_streaming_error, stream_url

Methods included from Moderation

moderation_url, parse_moderation_response, render_moderation_payload

Methods included from Models

models_url, parse_list_models_response

Methods included from Embeddings

embedding_url, parse_embedding_response, render_embedding_payload

Methods included from Chat

#completion_url, format_messages, format_role, parse_completion_response, render_payload

Methods inherited from RubyLLM::Provider

#capabilities, #complete, #configuration_requirements, configured?, #configured?, configured_providers, configured_remote_providers, #embed, for, #format_messages, #format_tool_calls, #initialize, #list_models, #local?, local?, local_providers, #moderate, #name, name, #paint, #parse_error, #parse_tool_calls, providers, register, remote?, #remote?, remote_providers, resolve, slug, #slug, #transcribe

Methods included from Streaming

handle_stream, stream_response

Constructor Details

This class inherits a constructor from RubyLLM::Provider

Class Method Details

.capabilitiesObject



34
35
36
# File 'lib/ruby_llm/providers/openai.rb', line 34

def capabilities
  OpenAI::Capabilities
end

.configuration_requirementsObject



38
39
40
# File 'lib/ruby_llm/providers/openai.rb', line 38

def configuration_requirements
  i[openai_api_key]
end

Instance Method Details

#api_baseObject



17
18
19
# File 'lib/ruby_llm/providers/openai.rb', line 17

def api_base
  @config.openai_api_base || 'https://api.openai.com/v1'
end

#headersObject



21
22
23
24
25
26
27
# File 'lib/ruby_llm/providers/openai.rb', line 21

def headers
  {
    'Authorization' => "Bearer #{@config.openai_api_key}",
    'OpenAI-Organization' => @config.openai_organization_id,
    'OpenAI-Project' => @config.openai_project_id
  }.compact
end

#maybe_normalize_temperature(temperature, model) ⇒ Object



29
30
31
# File 'lib/ruby_llm/providers/openai.rb', line 29

def maybe_normalize_temperature(temperature, model)
  OpenAI::Capabilities.normalize_temperature(temperature, model.id)
end