Module: Legion::LLM::API::Namespaces::OpenAI::VectorStores

Extended by:
Legion::Logging::Helper, Sinatra::Extension
Defined in:
lib/legion/llm/api/namespaces/openai/vector_stores.rb,
lib/legion/llm/api/namespaces/openai/vector_stores/files.rb,
lib/legion/llm/api/namespaces/openai/vector_stores/file_batches.rb

Defined Under Namespace

Modules: FileBatches, Files

Instance Method Summary collapse

Instance Method Details

#build_file_counts(vector_store_id) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/legion/llm/api/namespaces/openai/vector_stores.rb', line 256

def build_file_counts(vector_store_id)
  return { in_progress: 0, completed: 0, failed: 0, cancelled: 0, total: 0 } \
    unless Legion::LLM::VectorStore::Storage.data_available?

  ds = Legion::LLM::VectorStore::Storage.db[:llm_vector_store_files].where(vector_store_id: vector_store_id)
  in_progress = ds.where(status: 'in_progress').count
  completed   = ds.where(status: 'completed').count
  failed      = ds.where(status: 'failed').count
  cancelled   = ds.where(status: 'cancelled').count
  {
    in_progress: in_progress,
    completed:   completed,
    failed:      failed,
    cancelled:   cancelled,
    total:       in_progress + completed + failed + cancelled
  }
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: 'llm.api.vector_stores.file_counts')
  { in_progress: 0, completed: 0, failed: 0, cancelled: 0, total: 0 }
end

#format_store(row) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/legion/llm/api/namespaces/openai/vector_stores.rb', line 237

def format_store(row)
  return nil unless row

  meta = Legion::JSON.load(row[:metadata_json] || '{}')
  {
    id:             row[:id],
    object:         'vector_store',
    name:           row[:name].to_s,
    status:         row[:status].to_s,
    file_counts:    build_file_counts(row[:id]),
    usage_bytes:    row[:usage_bytes].to_i,
    created_at:     row[:created_at].to_i,
    last_active_at: row[:last_active_at].to_i,
    expires_at:     row[:expires_at],
    expires_after:  nil,
    metadata:       meta
  }
end