# | |
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org> | |
# SPDX-License-Identifier: Apache-2.0 | |
# | |
# Import APIRouter class from fastapi module to create a router instance for grouping related API routes | |
from fastapi import APIRouter | |
# Import JSONResponse to send JSON formatted HTTP responses from endpoint functions | |
from fastapi.responses import JSONResponse | |
# Import MODEL constant from config module, which specifies the default model identifier | |
from config import MODEL | |
# Create an APIRouter instance to collect and organize routes related to model operations | |
router = APIRouter() | |
# Define an asynchronous GET endpoint at path "/models" on this router | |
async def list_models(): | |
""" | |
OpenAI-compatible endpoint to list available models. | |
Returns a fixed list containing our default model. | |
This endpoint is required by many OpenAI-compatible clients to discover available models. | |
""" | |
# Return a JSON response with a list object containing one model dictionary | |
# The model dictionary includes id from config, a static object type, a placeholder created timestamp | |
return JSONResponse({ | |
"object": "list", | |
"data": [ | |
{ | |
"id": MODEL, | |
"object": "model", | |
"created": 0, # Timestamp not available, so set to zero | |
"owned_by": "J.A.R.V.I.S." | |
} | |
] | |
}) | |