Spaces:
Runtime error
Runtime error
File size: 1,422 Bytes
3ec4ff0 4a485db 3ec4ff0 bc0521a 4a485db 3ec4ff0 4a485db 3ec4ff0 4a485db 3ec4ff0 bc0521a 4a485db 3ec4ff0 4a485db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
"""API v1 route handlers."""
from fastapi import APIRouter, Response
from typing import Dict, List
from src.modules.transporter import publish_message
from src.modules.models.index import embed_text
import io
# Create v1 router
router = APIRouter(prefix='/v1', tags=['v1'])
import matplotlib.pyplot as plt
@router.get("/hello")
async def hello_world():
"""Hello world endpoint."""
publish_message("hello-python", "Hello from FastAPI!")
embed = embed_text("Hello, world!")
print(f"Generated embedding: {embed}")
return {"message": "Hello, reloaded!", "embedding": list(embed)}
@router.get("/health")
async def health_check() -> Dict[str, str]:
"""Health check endpoint."""
return {"status": "healthy"}
@router.get("/metrics")
async def metrics() -> Dict[str, int]:
"""Application metrics endpoint."""
return {
"total_routes": len(router.routes),
"api_version": 1
}
@router.get("/plot")
async def get_plot():
# Tạo biểu đồ
plt.figure(figsize=(6, 4))
x = [1, 2, 3, 4, 5]
y = [i ** 2 for i in x]
plt.plot(x, y, label="y = x^2")
plt.title("Sample Plot")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
# Lưu vào buffer
buf = io.BytesIO()
plt.savefig(buf, format="png")
plt.close()
buf.seek(0)
# Trả về dưới dạng ảnh PNG
return Response(content=buf.getvalue(), media_type="image/png") |