# -*- coding: utf-8 -*-


from fastapi import FastAPI, Form, HTTPException, Request,status,APIRouter,Query,Path, Depends, BackgroundTasks
from tools.loglog import logger,log_err_e

from core.respone_format import *
from gpt.article_annotation import Annotation
from pydantic import BaseModel, ValidationError, conint,Field,conint
from typing import List, Optional,Literal
import asyncio


router_article_annotation = APIRouter()
annotation_obj = Annotation()

class Annotation(BaseModel):
    english_text:str
    split_blank:bool = True

@router_article_annotation.post("/article/meaning/annotation")
def post_annotation(json_data:Annotation,request:Request,):
    """词义标注的同步接口"""
    json_data = json_data.model_dump()
    english_text = json_data.get("english_text")
    split_blank = json_data.get("split_blank")
    real_ip = request.headers.get("X-Real-IP","0.0.0.0")

    resp = annotation_obj.submit_task(
        english_text=english_text,
        split_blank=split_blank,
        real_ip=real_ip,
    )
    return resp_200(data=resp)



@router_article_annotation.get("/article/query_annotation")
async def query_annotation(task_id:int=Query(...)):
    resp = await annotation_obj.query_result_by_taskid(task_id)
    return resp

