ask-llm-providers 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0b23746b8ee8cc98e50c44f9e88df977ea81d9214bbda9a25be770021234cc2
4
- data.tar.gz: 2a2e628b12eb8e731ea9d46ae0f4076dd42591f03db0cf50759d77d6485e748e
3
+ metadata.gz: 22c3960f084ce514405b73a25093a058458f9f71ec5d3bf076a62ad312c74b94
4
+ data.tar.gz: eaf4407367c1adc93c55c35762772d599d774c8a856967c74ae9da73870243c6
5
5
  SHA512:
6
- metadata.gz: 4e31b5f82ae3aaab7a7bf337df1ebd5afc20b272efc2b630523145bbf82ebbd12faddcaacdb30e531df3cd3a379a82d9d2e96b97d9ff33877eff6eb0c638d320
7
- data.tar.gz: 2db527541cb1a8934c6f5ff2e62fbb8ebddf633600e332b040231461eaf9c9b5cb37ec3a70f0079a85404cf8b5fb3751c4f9b88ef075366681044d046ebfdd6b
6
+ metadata.gz: 9c5fc807124321bde12f4b239c0c5d32ff278edf9a446949346237cd24bd562582c9b6f0acecd27dc64be27adb2d8250eee34a4b4b64ae779c413da0e15f34d1
7
+ data.tar.gz: 2691464aefbae83c68ddf63c3a278e5f459d7fc222adb320d96d2c57a4cf2702ed50da1a056f8a83b22b64d7dbf804261371b7ceff7b8569799096d6b590b65f
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module LLM
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Providers
5
+ # Mimo API — an OpenAI-compatible provider
6
+ class Mimo < OpenAI
7
+ def api_base
8
+ @config.base_url || ENV["MIMO_API_BASE"] || "https://token-plan-sgp.xiaomimimo.com/v1"
9
+ end
10
+
11
+ def headers
12
+ key = @config.api_key || ENV["MIMO_API_KEY"]
13
+ h = { "Content-Type" => "application/json" }
14
+ h["Authorization"] = "Bearer #{key}" if key
15
+ h
16
+ end
17
+
18
+ class << self
19
+ def slug; "mimo"; end
20
+ def configuration_options; %i[api_key base_url]; end
21
+ def configuration_requirements; %i[api_key]; end
22
+ def configured?(config)
23
+ key = config.respond_to?(:api_key) ? config.api_key : nil
24
+ key ||= ENV["MIMO_API_KEY"]
25
+ key.to_s.length > 0
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -173,3 +173,23 @@ module Ask
173
173
  end
174
174
  end
175
175
  end
176
+
177
+ # When the OpenAI provider is subclassed (e.g. OpenCode), normalize_config
178
+ # should also check for env vars matching the subclass slug.
179
+ def normalize_config(config)
180
+ return config if !config.is_a?(Hash)
181
+
182
+ slug = self.class.slug
183
+ env_key = ENV["#{slug.upcase}_API_KEY"]
184
+ env_base = ENV["#{slug.upcase}_API_BASE"]
185
+
186
+ merged = {
187
+ api_key: config[:api_key] || config["api_key"] || config[:"#{slug}_api_key"] || config[:"#{slug}_api_key"] || config[:openai_api_key] || env_key,
188
+ base_url: config[:base_url] || config["base_url"] || env_base,
189
+ organization_id: config[:organization_id] || config["organization_id"],
190
+ project_id: config[:project_id] || config["project_id"]
191
+ }.merge(config.reject { |k, _| %i[api_key base_url organization_id project_id openai_api_key].include?(k.to_sym) })
192
+
193
+ # Also preserve original config for subclass-specific key access
194
+ Ask::LLM::Config.new(merged)
195
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Providers
5
+ # OpenCode API — an OpenAI-compatible provider at opencode.ai
6
+ class OpenCode < OpenAI
7
+ def api_base
8
+ @config.base_url || ENV["OPENCODE_API_BASE"] || "https://opencode.ai/zen/v1"
9
+ end
10
+
11
+ def headers
12
+ key = @config.api_key || ENV["OPENCODE_API_KEY"]
13
+ h = { "Content-Type" => "application/json" }
14
+ h["Authorization"] = "Bearer #{key}" if key
15
+ h
16
+ end
17
+
18
+ class << self
19
+ def slug; "opencode"; end
20
+ def configuration_options; %i[api_key base_url]; end
21
+ def configuration_requirements; %i[api_key]; end
22
+ def configured?(config)
23
+ key = config.respond_to?(:api_key) ? config.api_key : nil
24
+ key ||= ENV["OPENCODE_API_KEY"]
25
+ key.to_s.length > 0
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Providers
5
+ # OpenCode Go API — an OpenAI-compatible provider at opencode.ai/zen/go
6
+ class OpenCodeGo < OpenAI
7
+ def api_base
8
+ @config.base_url || ENV["OPENCODE_GO_API_BASE"] || "https://opencode.ai/zen/go/v1"
9
+ end
10
+
11
+ def headers
12
+ key = @config.api_key || ENV["OPENCODE_API_KEY"] || ENV["OPENCODE_GO_API_KEY"]
13
+ h = { "Content-Type" => "application/json" }
14
+ h["Authorization"] = "Bearer #{key}" if key
15
+ h
16
+ end
17
+
18
+ class << self
19
+ def slug; "opencode_go"; end
20
+ def configuration_options; %i[api_key base_url]; end
21
+ def configuration_requirements; %i[api_key]; end
22
+ def configured?(config)
23
+ key = config.respond_to?(:api_key) ? config.api_key : nil
24
+ key ||= ENV["OPENCODE_API_KEY"] || ENV["OPENCODE_GO_API_KEY"]
25
+ key.to_s.length > 0
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -20,6 +20,9 @@ require_relative "ask/provider/bedrock"
20
20
  require_relative "ask/provider/ollama"
21
21
  require_relative "ask/provider/mistral"
22
22
  require_relative "ask/provider/cloudflare"
23
+ require_relative "ask/provider/opencode"
24
+ require_relative "ask/provider/opencode_go"
25
+ require_relative "ask/provider/mimo"
23
26
 
24
27
  # Register providers with the Ask::Provider registry
25
28
  Ask::Provider.register(:openai, Ask::Providers::OpenAI)
@@ -47,3 +50,6 @@ Ask::Provider.register(:cloudflare, Ask::Providers::Cloudflare)
47
50
  ))
48
51
  end
49
52
  end
53
+
54
+ # configured via environment variables:
55
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-llm-providers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto
@@ -183,9 +183,12 @@ files:
183
183
  - lib/ask/provider/bedrock.rb
184
184
  - lib/ask/provider/cloudflare.rb
185
185
  - lib/ask/provider/google.rb
186
+ - lib/ask/provider/mimo.rb
186
187
  - lib/ask/provider/mistral.rb
187
188
  - lib/ask/provider/ollama.rb
188
189
  - lib/ask/provider/openai.rb
190
+ - lib/ask/provider/opencode.rb
191
+ - lib/ask/provider/opencode_go.rb
189
192
  homepage: https://github.com/ask-rb/ask-llm-providers
190
193
  licenses:
191
194
  - MIT