diff --git a/app/api/ai_assist/routes.py b/app/api/ai_assist/routes.py index 05904c7..80134f2 100644 --- a/app/api/ai_assist/routes.py +++ b/app/api/ai_assist/routes.py @@ -20,16 +20,17 @@ MAX_USAGE_PER = 100 CHAT_TTL = 7200 -@ai_router.post("/exp") +@ai_router.post("/word/exp", deprecated=False) async def dict_exp( request: Request, Q: AIQuestionRequest, user: Tuple[User, Dict] = Depends(get_current_user) ): """ - - :param word: - :param question: 不允许question为空调用 + 该接口仅用于查词页面且为具有MCP功能的 + :param request: + :param Q: + :param user: :return: """ if user[0].token_usage > CHAT_TTL and not user[0].is_admin: @@ -95,6 +96,11 @@ async def dict_exp( raise HTTPException(status_code=500, detail=f"AI调用失败: {str(e)}") +@ai_router.post("/univer") +async def universal_main(): + pass + + @ai_router.post("/clear") async def clear_history(word: str, request: Request, user: Tuple[User, Dict] = Depends(get_current_user)): redis = request.app.state.redis diff --git a/app/api/ai_assist/service.py b/app/api/ai_assist/service.py index 7a6a90a..afecc53 100644 --- a/app/api/ai_assist/service.py +++ b/app/api/ai_assist/service.py @@ -8,9 +8,10 @@ CHAT_TTL = 7200 async def get_and_set_last_key(redis: Redis, word: str, user_id: str): last_key = f"last_word:{user_id}" last_word = await redis.get(last_key) + print(last_word) # 如果上一次查的词和这次不同,就清空旧词的记录 - if last_word and last_word.decode() != word: + if last_word and last_word != word: await clear_chat_history(redis, user_id, last_word.decode()) # 更新当前词 diff --git a/app/api/make_comment.py b/app/api/make_comment.py deleted file mode 100644 index 154c7fe..0000000 --- a/app/api/make_comment.py +++ /dev/null @@ -1,28 +0,0 @@ -from typing import Tuple - -from fastapi import APIRouter, Depends - -from app.models import User, CommentFr, CommentJp -from app.schemas.comment_schemas import CommentUpload -from app.utils.security import get_current_user - -comment_router = APIRouter() - - -@comment_router.post("/make-comment") -async def new_word_comment( - upload: CommentUpload, - user: Tuple[User, dict] = Depends(get_current_user) -) -> None: - if upload.lang == "fr": - await CommentFr.create( - user=user[0], - comment_text=upload.comment_content, - comment_word=upload.comment_word, - ) - else: - await CommentJp.create( - user=user[0], - comment_text=upload.comment_content, - comment_word=upload.comment_word, - ) diff --git a/app/api/make_comments/__init__.py b/app/api/make_comments/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/make_comments/comment_schemas.py b/app/api/make_comments/comment_schemas.py new file mode 100644 index 0000000..5ce0098 --- /dev/null +++ b/app/api/make_comments/comment_schemas.py @@ -0,0 +1,34 @@ +from pydantic import BaseModel, field_validator, ValidationError + + +class Feedback(BaseModel): + report_part: str + text: str + + @classmethod + @field_validator("report_part") + def report_part_validator(cls, v): + types = ( + "ui_design", + "dict_fr", + "dict_jp", + "user", + "translate", + "writting", + "ai_assist", + "pronounce", + "comment_api_test", # 该类型仅作测试使用,不对外暴露 + ) + if v not in types: + raise ValidationError("Invalid feedback report type") + return v + + @classmethod + @field_validator("text") + def text_validator(cls, v): + if v is None: + raise ValidationError("Feedback text cannot be NULL") + return v + + class Config: + from_attributes = True diff --git a/app/api/make_comments/routes.py b/app/api/make_comments/routes.py new file mode 100644 index 0000000..76e72e5 --- /dev/null +++ b/app/api/make_comments/routes.py @@ -0,0 +1,110 @@ +from typing import Tuple + +from fastapi import APIRouter, Depends + +from app.api.make_comments.comment_schemas import Feedback +from app.core.email_utils import send_email +from app.models import User +from app.utils.security import get_current_user + +comment_router = APIRouter() + + +@comment_router.post("/improvements") +async def new_comment( + upload: Feedback, + user: Tuple[User, dict] = Depends(get_current_user) +): + user_id = user[0].id + username = user[0].name + type = upload.report_part + mail_text = upload.text + sender = "no-reply@lexiverse.com.cn" + receivers = ["GodricTan@gmail.com"] + + if type == "dict_fr": + receivers.append("aurora@lexiverse.com.cn") + + content = f""" + +
+ + + +| + + | +
您好,
-您正在进行 {ops_dict[ops_type]} 操作。
-- 您的验证码是: - {code} -
-有效期 5 分钟,请勿泄露给他人。
-- 如果这不是您本人的操作,请忽略此邮件。 -
- - - """ + content = f""" + + + + + +| + |