Class: CompletionKit::ProviderCredential
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CompletionKit::ProviderCredential
- Includes:
- Turbo::Broadcastable
- Defined in:
- app/models/completion_kit/provider_credential.rb
Constant Summary collapse
- PROVIDERS =
%w[openai anthropic ollama openrouter].freeze
- PROVIDER_LABELS =
{ "openai" => "OpenAI", "anthropic" => "Anthropic", "ollama" => "Ollama / local endpoint", "openrouter" => "OpenRouter" }.freeze
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #available_models ⇒ Object
- #broadcast_discovery_complete ⇒ Object
- #broadcast_discovery_progress ⇒ Object
- #config_hash ⇒ Object
- #configured? ⇒ Boolean
- #display_provider ⇒ Object
- #judge_count ⇒ Object
- #last_used_at ⇒ Object
- #prompt_count ⇒ Object
Instance Method Details
#as_json(options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'app/models/completion_kit/provider_credential.rb', line 14 def as_json( = {}) { id: id, provider: provider, api_endpoint: api_endpoint, created_at: created_at, updated_at: updated_at } end |
#available_models ⇒ Object
37 38 39 40 41 |
# File 'app/models/completion_kit/provider_credential.rb', line 37 def available_models LlmClient.for_provider(provider, config_hash).available_models rescue StandardError [] end |
#broadcast_discovery_complete ⇒ Object
79 80 81 82 |
# File 'app/models/completion_kit/provider_credential.rb', line 79 def broadcast_discovery_complete broadcast_discovery_progress broadcast_model_dropdowns end |
#broadcast_discovery_progress ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/models/completion_kit/provider_credential.rb', line 71 def broadcast_discovery_progress broadcast_replace_to( "completion_kit_provider_#{id}", target: "discovery_status_#{id}", html: render_partial("completion_kit/provider_credentials/discovery_status", provider_credential: self) ) end |
#config_hash ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/models/completion_kit/provider_credential.rb', line 29 def config_hash { provider: provider, api_key: api_key, api_endpoint: api_endpoint }.compact end |
#configured? ⇒ Boolean
43 44 45 46 47 |
# File 'app/models/completion_kit/provider_credential.rb', line 43 def configured? LlmClient.for_provider(provider, config_hash).configured? rescue StandardError false end |
#display_provider ⇒ Object
21 22 23 |
# File 'app/models/completion_kit/provider_credential.rb', line 21 def display_provider PROVIDER_LABELS[provider] || provider.titleize end |
#judge_count ⇒ Object
55 56 57 58 59 |
# File 'app/models/completion_kit/provider_credential.rb', line 55 def judge_count model_ids = Model.where(provider: provider).pluck(:model_id) return 0 if model_ids.empty? Run.where(judge_model: model_ids).count end |
#last_used_at ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'app/models/completion_kit/provider_credential.rb', line 61 def last_used_at model_ids = Model.where(provider: provider).pluck(:model_id) return nil if model_ids.empty? prompt_scope = Prompt.where(llm_model: model_ids).select(:id) Run.where("prompt_id IN (:prompts) OR judge_model IN (:models)", prompts: prompt_scope, models: model_ids) .where.not(status: "pending") .maximum(:created_at) end |