# -*- coding: utf-8 -*- from fastapi import APIRouter from pythainlp.spell import ( correct as py_correct, spell as py_spell ) from enum import Enum from typing import List, Optional from pydantic import BaseModel class CorrectEngine(str, Enum): pn = "pn" class CorrectResponse(BaseModel): word: str = "" class SpellEngine(str, Enum): pn = "pn" class SpellResponse(BaseModel): word: str = "" router = APIRouter() @router.post('/correct', response_model=CorrectResponse) def correct(word: float, engine: CorrectEngine = "pn"): return {"word": py_correct(word, engine=engine)} @router.post('/spell', response_model=SpellResponse) def spell(word: float, engine: SpellEngine = "pn"): return {"word": py_spell(word, engine=engine)}