Class: RubyLLM::Providers::Codex

Inherits:
Provider
  • Object
show all
Defined in:
lib/ruby_llm/providers/codex.rb

Overview

A local RubyLLM provider backed by codex exec and ChatGPT authentication.

This provider is deliberately narrow: non-streaming text generation and structured output are supported; RubyLLM tools and attachments are not.

Defined Under Namespace

Classes: Error, TimeoutError, UnsupportedFeatureError

Constant Summary collapse

DEFAULT_SANDBOX =
"read-only"
DEFAULT_TIMEOUT =
300
DEFAULT_SHELL_ENVIRONMENT_INHERIT =
"none"
MINIMUM_CLI_VERSION =
"0.144.5"
RESERVED_CONFIG_KEYS =
%w[
  developer_instructions
  features.shell_snapshot
  model_reasoning_effort
  shell_environment_policy.inherit
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assume_models_exist?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/ruby_llm/providers/codex.rb', line 69

def assume_models_exist?
  true
end

.configuration_optionsObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ruby_llm/providers/codex.rb', line 73

def configuration_options
  %i[
    codex_cli_path
    codex_working_directory
    codex_profile
    codex_home
    codex_ignore_user_config
    codex_ephemeral
    codex_timeout
    codex_shell_environment_inherit
  ]
end

.configuration_requirementsObject



86
87
88
# File 'lib/ruby_llm/providers/codex.rb', line 86

def configuration_requirements
  []
end

.local?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ruby_llm/providers/codex.rb', line 65

def local?
  true
end

Instance Method Details

#api_baseObject



31
32
33
# File 'lib/ruby_llm/providers/codex.rb', line 31

def api_base
  "http://127.0.0.1"
end

#complete(messages, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil, tool_prefs: nil, &stream) ⇒ Object

rubocop:disable Metrics/ParameterLists



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_llm/providers/codex.rb', line 40

def complete(messages, tools:, temperature:, model:, params: {}, headers: {},
  schema: nil, thinking: nil, tool_prefs: nil, &stream)
  validate_request!(tools:, temperature:, headers:, stream:)

  options = codex_options(params)
  developer_instructions, prompt = build_prompt(messages)
  request = {
    model: model.id,
    prompt:,
    developer_instructions:,
    schema:,
    thinking:
  }

  with_working_directory(options) do |working_directory|
    run_codex(request, working_directory:, options:)
  end
end

#headersObject



35
36
37
# File 'lib/ruby_llm/providers/codex.rb', line 35

def headers
  {}
end

#list_modelsObject

rubocop:enable Metrics/ParameterLists



60
61
62
# File 'lib/ruby_llm/providers/codex.rb', line 60

def list_models
  []
end