Spaces:
Sleeping
Sleeping
File size: 1,170 Bytes
8351050 | 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 | #!/usr/bin/env python3
"""
Hiroyuki SLM API Service
FastAPI-based API for Hiroyuki-style chat responses
"""
"""
NOT IN USE
""""
import logging
from fastapi import FastAPI, HTTPException
import uvicorn
from pydantic import BaseModel
from slm_model import HiroyukiSLM
logger = logging.getLogger(__name__)
app = FastAPI()
slm = HiroyukiSLM()
class ChatRequest(BaseModel):
message: str
class ChatResponse(BaseModel):
response: str
input: str
@app.get("/health")
async def health_check():
"""APIのヘルスチェックエンドポイント"""
return {"status": "ok"}
@app.post("/chat", response_model=ChatResponse)
async def chat(request: ChatRequest):
"""ユーザーのメッセージに対してひろゆき風の返答を生成するエンドポイント"""
try:
response = await slm.generate(request.message)
return ChatResponse(response=response, input=request.message)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
def start():
"""APIサーバーの起動関数"""
logger.info("Starting Hiroyuki-SLM API server...")
uvicorn.run(app, host="0.0.0.0", port=8000)
|