Compare commits
No commits in common. "e068850e4c7b617e54b313f6b3f968f28e617d89" and "2c121c9a1e353d22182e1ca8ba1dcf0a6bbf69c7" have entirely different histories.
e068850e4c
...
2c121c9a1e
|
|
@ -35,12 +35,6 @@ async def search(request: Request, body: SearchRequest, user=Depends(get_current
|
||||||
)
|
)
|
||||||
if not word_contents:
|
if not word_contents:
|
||||||
raise HTTPException(status_code=404, detail="Word not found")
|
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_seen = set()
|
||||||
pos_contents = []
|
pos_contents = []
|
||||||
contents: List[SearchItemFr] = []
|
contents: List[SearchItemFr] = []
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import requests
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
from app.models import User
|
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 app.utils.security import is_admin_user, get_current_user
|
||||||
from scripts.md5 import make_md5
|
from scripts.md5 import make_md5
|
||||||
from settings import settings
|
from settings import settings
|
||||||
|
|
@ -60,18 +60,18 @@ async def baidu_translation(query: str, from_lang: str, to_lang: str):
|
||||||
"sign": sign,
|
"sign": sign,
|
||||||
}
|
}
|
||||||
|
|
||||||
# print(payload)
|
print(payload)
|
||||||
#
|
|
||||||
# request = httpx.Request(
|
request = httpx.Request(
|
||||||
# "POST",
|
"POST",
|
||||||
# url,
|
url,
|
||||||
# data=payload,
|
data=payload,
|
||||||
# headers={"Content-Type": "application/x-www-form-urlencoded"}
|
headers={"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
# )
|
)
|
||||||
# print("完整请求内容:")
|
print("完整请求内容:")
|
||||||
# print("URL:", request.url)
|
print("URL:", request.url)
|
||||||
# print("Headers:", request.headers)
|
print("Headers:", request.headers)
|
||||||
# print("Body:", request.content.decode("utf-8"))
|
print("Body:", request.content.decode("utf-8"))
|
||||||
|
|
||||||
async with httpx.AsyncClient(timeout=10) as client:
|
async with httpx.AsyncClient(timeout=10) as client:
|
||||||
response = await client.post(
|
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)
|
@translator_router.post('/translate', response_model=TransResponse)
|
||||||
async def translate(
|
async def translate(
|
||||||
translate_request: TransRequest,
|
query: str,
|
||||||
|
from_lang: str = 'auto',
|
||||||
|
to_lang: str = 'zh',
|
||||||
user=Depends(get_current_user)
|
user=Depends(get_current_user)
|
||||||
):
|
):
|
||||||
text = await baidu_translation(
|
text = await baidu_translation(
|
||||||
query=translate_request.query,
|
query=query,
|
||||||
from_lang=translate_request.from_lang,
|
from_lang=from_lang,
|
||||||
to_lang=translate_request.to_lang,
|
to_lang=to_lang
|
||||||
)
|
)
|
||||||
return TransResponse(translated_text=text)
|
return TransResponse(translated_text=text)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ from pydantic import BaseModel, field_validator, model_validator
|
||||||
|
|
||||||
|
|
||||||
class TransRequest(BaseModel):
|
class TransRequest(BaseModel):
|
||||||
query: str
|
from_lang: Literal['fr', 'jp', 'zh'] = 'fr'
|
||||||
from_lang: Literal['auto', 'fr', 'jp', 'zh'] = 'auto'
|
|
||||||
to_lang: Literal['fr', 'jp', 'zh'] = 'zh'
|
to_lang: Literal['fr', 'jp', 'zh'] = 'zh'
|
||||||
|
|
||||||
@field_validator('from_lang', 'to_lang')
|
@field_validator('from_lang', 'to_lang')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue