from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
from pydantic import BaseModel
import os
app = FastAPI(
title="Sheikh LLM API",
description="A powerful LLM API deployed on Hugging Face Spaces",
version="1.0.0"
)
class ChatRequest(BaseModel):
message: str
max_tokens: int = 100
class ChatResponse(BaseModel):
response: str
status: str
@app.get("/", response_class=HTMLResponse)
def home(): return """
Sheikh LLM
âš¡ Quick Test:
Try this curl command to test the API:
curl -X GET "https://recentcoders-sheikh-llm.hf.space/health"
"""
@app.get("/health")
async def health_check():
return JSONResponse({
"status": "healthy",
"service": "sheikh-llm",
"version": "1.0.0",
"environment": "production"
})
@app.get("/api/status")
async def api_status():
return {
"service": "sheikh-llm",
"version": "1.0.0",
"status": "running",
"endpoints": [
{"path": "/", "method": "GET", "description": "Homepage"},
{"path": "/health", "method": "GET", "description": "Health check"},
{"path": "/api/status", "method": "GET", "description": "API status"},
{"path": "/docs", "method": "GET", "description": "Swagger UI"}
]
}
@app.post("/api/chat", response_model=ChatResponse)
async def chat_endpoint(request: ChatRequest):
"""Simple chat endpoint that echoes the message"""
if not request.message.strip():
raise HTTPException(status_code=400, detail="Message cannot be empty")
response_text = f"Received your message: '{request.message}'. This is from Sheikh LLM API!"
return ChatResponse(
response=response_text,
status="success"
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)