| from fastapi import FastAPI |
| from pydantic import BaseModel |
| import uvicorn |
| from translator import translate |
|
|
| app = FastAPI() |
|
|
| |
| class ChatRequest(BaseModel): |
| message: str |
| history: list[dict] = [] |
| system_message: str = "You are a friendly chatbot." |
| max_tokens: int = 512 |
| temperature: float = 0.7 |
| top_p: float = 0.95 |
|
|
| class TranslateRequest(BaseModel): |
| text: str |
| direction: str |
|
|
| |
| @app.post("/chat") |
| def chat_endpoint(req: ChatRequest): |
| |
| return {"response": f"Simulasi jawaban untuk: {req.message}"} |
|
|
| |
| @app.post("/translate") |
| def translate_endpoint(req: TranslateRequest): |
| result = translate(req.text, req.direction) |
| return {"translation": result} |
|
|
| |
| if __name__ == "__main__": |
| uvicorn.run(app, host="0.0.0.0", port=7860) |
|
|