ask-llm-providers 0.1.2 → 0.1.4

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: cb5569df9c7ea68cc553e0c62ca2ca270740dbe6cc43e3a602f39a5fb0baa9e2
4
+ data.tar.gz: 7ca2de33ac8cb1838eea3cb2c5dcd0110b7e9cd7d072491923a5ef844959f0db
5
5
  SHA512:
6
- metadata.gz: 4e31b5f82ae3aaab7a7bf337df1ebd5afc20b272efc2b630523145bbf82ebbd12faddcaacdb30e531df3cd3a379a82d9d2e96b97d9ff33877eff6eb0c638d320
7
- data.tar.gz: 2db527541cb1a8934c6f5ff2e62fbb8ebddf633600e332b040231461eaf9c9b5cb37ec3a70f0079a85404cf8b5fb3751c4f9b88ef075366681044d046ebfdd6b
6
+ metadata.gz: 17690cddc635910662b5396b4ccdac5cddf3923647c264d39daf2cfa187b35d6b0740d7bba60f3e1d5adb18dcdbde59a8fdf265b8e1a5d10bd98fe5408768184
7
+ data.tar.gz: 745aefc2b358c85093d499de0535ae0339664c395bf311b2d58e840cb88da3ed7c1532a95040139e27cf86d0ade1899c6d865218b910938b53bb801b6637495e
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module LLM
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
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
@@ -142,6 +142,13 @@ module Ask
142
142
  stream
143
143
  end
144
144
 
145
+ def extract_thinking(parsed, delta)
146
+ delta["reasoning_content"] || delta["thinking"] ||
147
+ parsed.dig("choices", 0, "delta", "reasoning_content") ||
148
+ parsed.dig("choices", 0, "delta", "thinking") ||
149
+ parsed.dig("choices", 0, "reasoning_content")
150
+ end
151
+
145
152
  def process_chunk(raw, stream, model)
146
153
  raw.each_line do |line|
147
154
  line = line.strip
@@ -173,3 +180,23 @@ module Ask
173
180
  end
174
181
  end
175
182
  end
183
+
184
+ # When the OpenAI provider is subclassed (e.g. OpenCode), normalize_config
185
+ # should also check for env vars matching the subclass slug.
186
+ def normalize_config(config)
187
+ return config if !config.is_a?(Hash)
188
+
189
+ slug = self.class.slug
190
+ env_key = ENV["#{slug.upcase}_API_KEY"]
191
+ env_base = ENV["#{slug.upcase}_API_BASE"]
192
+
193
+ merged = {
194
+ api_key: config[:api_key] || config["api_key"] || config[:"#{slug}_api_key"] || config[:"#{slug}_api_key"] || config[:openai_api_key] || env_key,
195
+ base_url: config[:base_url] || config["base_url"] || env_base,
196
+ organization_id: config[:organization_id] || config["organization_id"],
197
+ project_id: config[:project_id] || config["project_id"]
198
+ }.merge(config.reject { |k, _| %i[api_key base_url organization_id project_id openai_api_key].include?(k.to_sym) })
199
+
200
+ # Also preserve original config for subclass-specific key access
201
+ Ask::LLM::Config.new(merged)
202
+ 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)
@@ -29,7 +32,9 @@ Ask::Provider.register(:bedrock, Ask::Providers::Bedrock)
29
32
  Ask::Provider.register(:ollama, Ask::Providers::Ollama)
30
33
  Ask::Provider.register(:mistral, Ask::Providers::Mistral)
31
34
  Ask::Provider.register(:cloudflare, Ask::Providers::Cloudflare)
32
-
35
+ Ask::Provider.register(:opencode, Ask::Providers::OpenCode)
36
+ Ask::Provider.register(:opencode_go, Ask::Providers::OpenCodeGo)
37
+ Ask::Provider.register(:mimo, Ask::Providers::Mimo)
33
38
 
34
39
  # Register known models for each provider in the catalog
35
40
  [
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.4
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