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

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

from core.respone_format import *
from deepseek.get_article3 import GetArticle
from pydantic import BaseModel, ValidationError, conint,Field
from typing import List, Optional,Literal


router = APIRouter(tags=['deepseek接口'])
get_article = GetArticle()

class Word(BaseModel):
    spell: str = Field(..., description="单词的拼写")
    meaning: str = Field(..., description="单词的意思")


class ArticleRequest(BaseModel):
    words: List[Word] = Field(..., description="单词列表")
    take_count: int = 2 
    student_stage: Literal[1, 2, 3] 
    demo_name: Optional[str] = "无" 


@router.post("/article/reading-comprehension/deepseek")
def post_article(json_data:ArticleRequest,request:Request):
    json_data = json_data.dict()
    real_ip = request.headers.get("X-Real-IP")
    words,take_count,student_stage,demo_name = json_data["words"],json_data["take_count"],json_data["student_stage"],json_data["demo_name"]

    try:
        r = get_article.submit_task(words_meaning_list=words, take_count=take_count,student_stage=student_stage,real_ip=real_ip,demo_name=demo_name)
        return r if not isinstance(r,str) else resp_500(message=r)

    except Exception as e:
        log_err_e(e,msg="文章3,ds接口错误/article/reading-comprehension/deepseek；")
        return resp_500(message=f"{type(e).__name__},{e}")