Compare commits

..

No commits in common. "1c8036cb8de6731f0b0385a6a08d94b20215ca34" and "606675ab339e82f4ad4ab1e1f0fb9ddbb77b83bf" have entirely different histories.

4 changed files with 5 additions and 9 deletions

View File

@ -1,3 +1,4 @@
import os
from typing import Dict, Tuple
import httpx
@ -7,15 +8,13 @@ from starlette.requests import Request
from app.api.ai_assist import service
from app.api.ai_assist.ai_schemas import AIAnswerResponse, AIAnswerOut, AIQuestionRequest
from app.api.ai_assist.utils.redis_memory import get_chat_history, save_message, clear_chat_history
from app.api.article_director.service import reply_process
from app.models import User
from app.utils.security import get_current_user
from settings import settings
ai_router = APIRouter()
ZJU_AI_URL = 'https://chat.zju.edu.cn/api/ai/v1/chat/completions'
AI_API_KEY = settings.AI_ASSIST_KEY
AI_API_KEY = os.getenv("AI_ASSIST_KEY")
MAX_USAGE_PER = 100
CHAT_TTL = 7200
@ -86,11 +85,9 @@ async def dict_exp(
await save_message(redis, user_id, word, "user", question)
await save_message(redis, user_id, word, "assistant", answer)
answer = await reply_process(answer)
return AIAnswerOut(
word=word,
answer=answer,
answer=ai_resp.get_answer(),
model=ai_resp.model,
tokens_used=ai_resp.usage.total_tokens if ai_resp.usage else None
)

View File

@ -11,7 +11,7 @@ async def get_and_set_last_key(redis: Redis, word: str, user_id: str):
print(last_word)
# 如果上一次查的词和这次不同,就清空旧词的记录
if last_word and last_word != word:
if last_word and last_word.decode() != word:
await clear_chat_history(redis, user_id, last_word.decode())
# 更新当前词

View File

@ -78,5 +78,4 @@ async def reply_process(reply: str) -> str:
:return:
"""
reply.replace("**", "")
reply.replace("---", "")
return reply

View File

@ -11,7 +11,7 @@ class TransRequest(BaseModel):
@field_validator('from_lang', 'to_lang')
@classmethod
def validate_lang(cls, v):
allowed_langs = {'auto', 'fr', 'jp', 'zh', 'en'}
allowed_langs = {'auto', 'fr', 'jp', 'zh'}
if v not in allowed_langs:
raise ValueError(f'Unsupported language: {v}')
return v