Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sandboxes/llm_local/app/mocks/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ class ChatCompletionRequest(BaseModel):
)


@router.get("/v1/models")
def list_models(token: str = Depends(verify_api_key)) -> Any:
"""OpenAI-compatible models list endpoint, proxied from the Ollama backend.

Many OpenAI-compatible clients use GET /v1/models as a preflight liveness
check before sending any chat request. Without this route, such a check
fails and reports a working sandbox as unreachable.

Returns:
Any: OpenAI-compatible model list response from Ollama.

Raises:
HTTPException: If the Ollama backend returns an error (status 500).
"""
try:
return client.models.list()
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))


@router.post("/v1/chat/completions")
def chat_completions(
request: ChatCompletionRequest, token: str = Depends(verify_api_key)
Expand Down