Class: Ask::Providers::OpenCode

Inherits:
OpenAI
  • Object
show all
Defined in:
lib/ask/provider/opencode.rb

Overview

OpenCode API — an OpenAI-compatible provider at opencode.ai

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenAI

assume_models_exist?, capabilities, #chat, #embed, #initialize, #list_models, #parse_error

Constructor Details

This class inherits a constructor from Ask::Providers::OpenAI

Class Method Details

.configuration_optionsObject



20
# File 'lib/ask/provider/opencode.rb', line 20

def configuration_options; %i[api_key base_url]; end

.configuration_requirementsObject



21
# File 'lib/ask/provider/opencode.rb', line 21

def configuration_requirements; %i[api_key]; end

.configured?(config) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/ask/provider/opencode.rb', line 22

def configured?(config)
  key = config.respond_to?(:api_key) ? config.api_key : nil
  key ||= ENV["OPENCODE_API_KEY"]
  key.to_s.length > 0
end

.slugObject



19
# File 'lib/ask/provider/opencode.rb', line 19

def slug; "opencode"; end

Instance Method Details

#api_baseObject



7
8
9
# File 'lib/ask/provider/opencode.rb', line 7

def api_base
  @config.base_url || ENV["OPENCODE_API_BASE"] || "https://opencode.ai/zen/v1"
end

#headersObject



11
12
13
14
15
16
# File 'lib/ask/provider/opencode.rb', line 11

def headers
  key = @config.api_key || ENV["OPENCODE_API_KEY"]
  h = { "Content-Type" => "application/json" }
  h["Authorization"] = "Bearer #{key}" if key
  h
end