16
17
18
19
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
48
49
50
51
|
# File 'lib/legion/llm/api/namespaces/native/offerings.rb', line 16
def self.registered(ns_context)
log.debug('[llm][api][namespaces][offerings] registering routes')
ns_context.get '' do
log.debug('[llm][api][namespaces][offerings] action=list_offerings')
require_llm!
filters = Legion::LLM::API::Native::Offerings.request_filters(params)
raw_offerings = Legion::LLM::Inventory.offerings(filters)
grouped = Legion::LLM::API::Native::Offerings.group_offerings(raw_offerings)
json_response({
offerings: grouped,
summary: Legion::LLM::API::Native::Offerings.summary(raw_offerings)
})
rescue StandardError => e
handle_exception(e, level: :error, handled: true, operation: 'llm.api.offerings.list')
json_error('offering_inventory_error', e.message, status_code: 500)
end
ns_context.get '/:id' do
offering_id = params[:id]
log.debug("[llm][api][namespaces][offerings] action=get_offering id=#{offering_id}")
require_llm!
offering = Legion::LLM::Inventory.offerings(offering_id: offering_id).first
halt json_error('offering_not_found', "Offering '#{offering_id}' not found", status_code: 404) unless offering
json_response({ offering: offering })
rescue StandardError => e
handle_exception(e, level: :error, handled: true, operation: 'llm.api.offerings.get')
json_error('offering_inventory_error', e.message, status_code: 500)
end
log.debug('[llm][api][namespaces][offerings] routes registered')
end
|