Class: Tep::Llm::OpenAI::ModelsHandler

Inherits:
Handler
  • Object
show all
Defined in:
lib/tep/openai_server.rb

Overview

GET /v1/models – the standard OpenAI list envelope, built from backend.list_models. Dispatches through APP.openai_backend so the app’s subclass override is what answers.

Instance Method Summary collapse

Methods inherited from Handler

#is_regex?, #re_capture, #re_match?

Instance Method Details

#handle(req, res) ⇒ Object



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/tep/openai_server.rb', line 475

def handle(req, res)
  res.headers["Content-Type"] = "application/json"
  models = Tep::APP.openai_backend.list_models
  out = "{\"object\":\"list\",\"data\":["
  i = 0
  while i < models.length
    if i > 0
      out = out + ","
    end
    out = out + "{" +
      Tep::Json.encode_pair_str("id", models[i]) + "," +
      Tep::Json.encode_pair_str("object", "model") + "," +
      Tep::Json.encode_pair_str("owned_by", "tep") +
    "}"
    i += 1
  end
  out = out + "]}"
  out
end