api_article_annotation.py 955 B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. from fastapi import Request, APIRouter, Query
  3. from pydantic import BaseModel
  4. from core.respone_format import *
  5. from gpt.article_annotation import Annotation
  6. router_article_annotation = APIRouter()
  7. annotation_obj = Annotation()
  8. class Annotation(BaseModel):
  9. english_text: str
  10. @router_article_annotation.post("/article/meaning/annotation")
  11. def post_annotation(json_data: Annotation, request: Request, ):
  12. """词义标注的同步接口"""
  13. json_data = json_data.model_dump()
  14. english_text = json_data.get("english_text")
  15. real_ip = request.headers.get("X-Real-IP", "0.0.0.0")
  16. resp = annotation_obj.submit_task(
  17. english_text=english_text,
  18. real_ip=real_ip,
  19. )
  20. return resp_200(data=resp)
  21. @router_article_annotation.get("/article/query_annotation")
  22. async def query_annotation(task_id: int = Query(...)):
  23. resp = await annotation_obj.query_result_by_taskid(task_id)
  24. return resp