Compare commits

..

No commits in common. "e068850e4c7b617e54b313f6b3f968f28e617d89" and "2c121c9a1e353d22182e1ca8ba1dcf0a6bbf69c7" have entirely different histories.

3 changed files with 20 additions and 25 deletions

View File

@ -35,12 +35,6 @@ async def search(request: Request, body: SearchRequest, user=Depends(get_current
)
if not word_contents:
raise HTTPException(status_code=404, detail="Word not found")
# 修改freq
first_word = word_contents[0].word
current_freq = first_word.freq
await first_word.update(freq=current_freq+1)
pos_seen = set()
pos_contents = []
contents: List[SearchItemFr] = []

View File

@ -10,7 +10,7 @@ import requests
from fastapi import APIRouter, Depends, HTTPException
from app.models import User
from app.schemas.trans_schemas import TransResponse, TransRequest
from app.schemas.trans_schemas import TransResponse
from app.utils.security import is_admin_user, get_current_user
from scripts.md5 import make_md5
from settings import settings
@ -60,18 +60,18 @@ async def baidu_translation(query: str, from_lang: str, to_lang: str):
"sign": sign,
}
# print(payload)
#
# request = httpx.Request(
# "POST",
# url,
# data=payload,
# headers={"Content-Type": "application/x-www-form-urlencoded"}
# )
# print("完整请求内容:")
# print("URL:", request.url)
# print("Headers:", request.headers)
# print("Body:", request.content.decode("utf-8"))
print(payload)
request = httpx.Request(
"POST",
url,
data=payload,
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
print("完整请求内容:")
print("URL:", request.url)
print("Headers:", request.headers)
print("Body:", request.content.decode("utf-8"))
async with httpx.AsyncClient(timeout=10) as client:
response = await client.post(
@ -94,13 +94,15 @@ async def baidu_translation(query: str, from_lang: str, to_lang: str):
@translator_router.post('/translate', response_model=TransResponse)
async def translate(
translate_request: TransRequest,
query: str,
from_lang: str = 'auto',
to_lang: str = 'zh',
user=Depends(get_current_user)
):
text = await baidu_translation(
query=translate_request.query,
from_lang=translate_request.from_lang,
to_lang=translate_request.to_lang,
query=query,
from_lang=from_lang,
to_lang=to_lang
)
return TransResponse(translated_text=text)

View File

@ -4,8 +4,7 @@ from pydantic import BaseModel, field_validator, model_validator
class TransRequest(BaseModel):
query: str
from_lang: Literal['auto', 'fr', 'jp', 'zh'] = 'auto'
from_lang: Literal['fr', 'jp', 'zh'] = 'fr'
to_lang: Literal['fr', 'jp', 'zh'] = 'zh'
@field_validator('from_lang', 'to_lang')