Class: CompletionKit::ProviderCredential
- Inherits:
-
ApplicationRecord
show all
- 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
ApplicationRecord::TenantScopedUniquenessValidator
Instance Method Summary
collapse
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(options = {})
{
id: id, provider: provider, api_endpoint: api_endpoint,
created_at: created_at, updated_at: updated_at
}
end
|
#available_models ⇒ Object
38
39
40
41
42
|
# File 'app/models/completion_kit/provider_credential.rb', line 38
def available_models
LlmClient.for_provider(provider, config_hash).available_models
rescue StandardError
[]
end
|
#broadcast_discovery_complete ⇒ Object
80
81
82
83
|
# File 'app/models/completion_kit/provider_credential.rb', line 80
def broadcast_discovery_complete
broadcast_discovery_progress
broadcast_model_dropdowns
end
|
#broadcast_discovery_progress ⇒ Object
72
73
74
75
76
77
78
|
# File 'app/models/completion_kit/provider_credential.rb', line 72
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
30
31
32
33
34
35
36
|
# File 'app/models/completion_kit/provider_credential.rb', line 30
def config_hash
{
provider: provider,
api_key: api_key,
api_endpoint: api_endpoint
}.compact
end
|
44
45
46
47
48
|
# File 'app/models/completion_kit/provider_credential.rb', line 44
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
56
57
58
59
60
|
# File 'app/models/completion_kit/provider_credential.rb', line 56
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
62
63
64
65
66
67
68
69
70
|
# File 'app/models/completion_kit/provider_credential.rb', line 62
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
|
#prompt_count ⇒ Object
50
51
52
53
54
|
# File 'app/models/completion_kit/provider_credential.rb', line 50
def prompt_count
model_ids = Model.where(provider: provider).pluck(:model_id)
return 0 if model_ids.empty?
Prompt.where(llm_model: model_ids, current: true).count
end
|