Class: LanguageOperator::CLI::Commands::Model::Base
Overview
Model management commands
Constant Summary
LanguageOperator::Constants::ALL_MODE_ALIASES, LanguageOperator::Constants::EXECUTION_MODES, LanguageOperator::Constants::PRIMARY_MODES, LanguageOperator::Constants::RESOURCE_AGENT, LanguageOperator::Constants::RESOURCE_AGENT_VERSION, LanguageOperator::Constants::RESOURCE_MODEL, LanguageOperator::Constants::RESOURCE_PERSONA, LanguageOperator::Constants::RESOURCE_TOOL
Instance Method Summary
collapse
Methods included from Test
included
current_cluster, current_cluster_config, ensure_cluster_selected!, get_cluster, get_cluster_config, kubernetes_client, validate_cluster_exists!, validate_kubeconfig!
normalize_mode, valid_mode?
#box, #highlight_ruby_code, #logo, #pastel, #prompt, #spinner, #table
Instance Method Details
#create(name = nil) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/language_operator/cli/commands/model/base.rb', line 66
def create(name = nil)
handle_command_error('create model') do
if name.nil? && options[:provider].nil? && options[:model].nil?
wizard = Wizards::ModelWizard.new(ctx)
wizard.run
return
end
if options[:provider].nil? || options[:model].nil?
Formatters::ProgressFormatter.error(
'Must provide both --provider and --model, or use interactive mode (run without arguments)'
)
exit 1
end
resource = Kubernetes::ResourceBuilder.language_model(
name,
provider: options[:provider],
model: options[:model],
endpoint: options[:endpoint],
cluster: ctx.namespace,
cluster_ref: ctx.name,
k8s_client: ctx.client
)
if options[:dry_run]
puts resource.to_yaml
return
end
begin
ctx.client.get_resource(RESOURCE_MODEL, name, ctx.namespace)
Formatters::ProgressFormatter.error("Model '#{name}' already exists in cluster '#{ctx.name}'")
exit 1
rescue K8s::Error::NotFound
end
Formatters::ProgressFormatter.with_spinner("Creating model '#{name}'") do
ctx.client.apply_resource(resource)
end
Formatters::ProgressFormatter.success("Model '#{name}' created successfully")
puts
format_model_details(
name: name,
namespace: ctx.namespace,
cluster: ctx.name,
status: 'Ready',
provider: options[:provider],
model: options[:model],
endpoint: options[:endpoint],
created: Time.now.strftime('%Y-%m-%dT%H:%M:%SZ')
)
end
end
|
#delete(name) ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/language_operator/cli/commands/model/base.rb', line 172
def delete(name)
handle_command_error('delete model') do
get_resource_or_exit(RESOURCE_MODEL, name)
return unless check_dependencies_and_confirm('model', name, force: options[:force])
return unless confirm_deletion_with_force('model', name, ctx.name, force: options[:force])
Formatters::ProgressFormatter.with_spinner("Deleting model '#{name}'") do
ctx.client.delete_resource(RESOURCE_MODEL, name, ctx.namespace)
end
end
end
|
#edit(name) ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/language_operator/cli/commands/model/base.rb', line 191
def edit(name)
handle_command_error('edit model') do
model = get_resource_or_exit(RESOURCE_MODEL, name)
edited_yaml = Helpers::EditorHelper.edit_content(
model.to_yaml,
'model-',
'.yaml',
default_editor: 'vim'
)
edited_model = YAML.safe_load(edited_yaml)
Formatters::ProgressFormatter.with_spinner("Updating model '#{name}'") do
ctx.client.apply_resource(edited_model)
end
Formatters::ProgressFormatter.success("Model '#{name}' updated successfully")
end
end
|
#inspect(name) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/language_operator/cli/commands/model/base.rb', line 131
def inspect(name)
handle_command_error('inspect model') do
model = get_resource_or_exit(RESOURCE_MODEL, name)
puts
format_model_details(
name: name,
namespace: ctx.namespace,
cluster: ctx.name,
status: model.dig('status', 'phase') || 'Unknown',
provider: model.dig('spec', 'provider'),
model: model.dig('spec', 'modelName'),
endpoint: model.dig('spec', 'endpoint'),
created: model.dig('metadata', 'creationTimestamp')
)
puts
agents = ctx.client.list_resources(RESOURCE_AGENT, namespace: ctx.namespace)
agents_using = Helpers::ResourceDependencyChecker.agents_using_model(agents, name)
agent_names = agents_using.map { |agent| agent.dig('metadata', 'name') }
list_box(
title: 'Agents using this model',
items: agent_names,
empty_message: 'No agents using this model'
)
puts
labels = model.dig('metadata', 'labels') || {}
list_box(
title: 'Labels',
items: labels,
style: :key_value
)
end
end
|
#list ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/language_operator/cli/commands/model/base.rb', line 20
def list
handle_command_error('list models') do
models = list_resources_or_empty(RESOURCE_MODEL, resource_name: 'models') do
puts
puts 'Create a model with:'
puts ' langop model create <name> --provider <provider> --model <model>'
end
return if models.empty?
table_data = models.map do |model|
name = model.dig('metadata', 'name')
provider = model.dig('spec', 'provider') || 'unknown'
model_name = model.dig('spec', 'modelName') || 'unknown'
status = model.dig('status', 'phase') || 'Unknown'
{
name: name,
namespace: model.dig('metadata', 'namespace') || ctx.namespace,
provider: provider,
model: model_name,
status: status
}
end
Formatters::TableFormatter.models(table_data)
end
end
|