OAI: Add models support

The models endpoint fetches all the models that OAI has to offer.
However, since this is an OAI clone, just list the models inside
the user's configured model directory instead.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-11-13 21:38:34 -05:00
parent eee8b642bd
commit 47343e2f1a
4 changed files with 47 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
import pathlib
from OAI.models.completions import CompletionResponse, CompletionRespChoice
from OAI.models.common import UsageStats
from OAI.models.models import ModelList, ModelCard
from typing import Optional
def create_completion_response(text: str, index: int, model_name: Optional[str]):
@@ -17,3 +19,12 @@ def create_completion_response(text: str, index: int, model_name: Optional[str])
)
return response
def get_model_list(model_path: pathlib.Path):
model_card_list = ModelList()
for path in model_path.parent.iterdir():
if path.is_dir():
model_card = ModelCard(id = path.name)
model_card_list.data.append(model_card)
return model_card_list