Class: Ace::LLM::Providers::CLI::OpenCodeClient
- Inherits:
-
Organisms::BaseClient
- Object
- Organisms::BaseClient
- Ace::LLM::Providers::CLI::OpenCodeClient
- Includes:
- CliArgsSupport
- Defined in:
- lib/ace/llm/providers/cli/open_code_client.rb
Overview
Client for interacting with OpenCode CLI Provides access to multiple AI providers through OpenCode’s unified platform
Constant Summary collapse
- API_BASE_URL =
Not used for CLI interaction but required by BaseClient
"https://models.dev"- DEFAULT_GENERATION_CONFIG =
{}.freeze
- DEFAULT_MODEL =
Default model (can be overridden by config)
"google/gemini-2.5-flash"
Class Method Summary collapse
-
.provider_name ⇒ Object
Provider registration - auto-registers as “opencode”.
Instance Method Summary collapse
-
#generate(messages, **options) ⇒ Hash
Generate a response from the LLM.
-
#initialize(model: nil, **options) ⇒ OpenCodeClient
constructor
A new instance of OpenCodeClient.
-
#list_models ⇒ Object
List available OpenCode models.
-
#needs_credentials? ⇒ Boolean
Override to indicate this client doesn’t need API credentials.
Constructor Details
#initialize(model: nil, **options) ⇒ OpenCodeClient
Returns a new instance of OpenCodeClient.
31 32 33 34 35 36 |
# File 'lib/ace/llm/providers/cli/open_code_client.rb', line 31 def initialize(model: nil, **) @model = model || DEFAULT_MODEL # Skip normal BaseClient initialization that requires API key @options = @generation_config = [:generation_config] || {} end |
Class Method Details
.provider_name ⇒ Object
Provider registration - auto-registers as “opencode”
24 25 26 |
# File 'lib/ace/llm/providers/cli/open_code_client.rb', line 24 def self.provider_name "opencode" end |
Instance Method Details
#generate(messages, **options) ⇒ Hash
Generate a response from the LLM
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ace/llm/providers/cli/open_code_client.rb', line 47 def generate(, **) validate_opencode_availability! # Convert messages to prompt format prompt = () # Build full prompt with system instruction for accurate token accounting full_prompt = build_full_prompt(prompt, ) cmd = build_opencode_command_with_prompt(full_prompt, ) stdout, stderr, status = execute_opencode_command(cmd, options: ) parse_opencode_response(stdout, stderr, status, full_prompt, ) rescue => e handle_opencode_error(e) end |
#list_models ⇒ Object
List available OpenCode models
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ace/llm/providers/cli/open_code_client.rb', line 65 def list_models # Return a standard set of models that OpenCode typically supports # Actual models come from YAML config [ {id: "google/gemini-2.5-flash", name: "Gemini 2.5 Flash", description: "Fast Google model", context_size: 1_000_000}, {id: "google/gemini-2.0-flash-experimental", name: "Gemini 2.0 Flash", description: "Experimental Google model", context_size: 1_000_000}, {id: "google/gemini-1.5-pro", name: "Gemini 1.5 Pro", description: "Advanced Google model", context_size: 2_000_000}, {id: "anthropic/claude-3-5-sonnet", name: "Claude 3.5 Sonnet", description: "Anthropic model", context_size: 200_000}, {id: "anthropic/claude-3-5-haiku", name: "Claude 3.5 Haiku", description: "Fast Anthropic model", context_size: 200_000}, {id: "openai/gpt-4o", name: "GPT-4 Omni", description: "OpenAI model", context_size: 128_000}, {id: "openai/gpt-4o-mini", name: "GPT-4 Omni Mini", description: "Small OpenAI model", context_size: 128_000} ] end |
#needs_credentials? ⇒ Boolean
Override to indicate this client doesn’t need API credentials
39 40 41 |
# File 'lib/ace/llm/providers/cli/open_code_client.rb', line 39 def needs_credentials? false end |