搜索次数接口

This commit is contained in:
Miyamizu-MitsuhaSang 2025-11-06 21:26:36 +08:00
parent f2956d6f28
commit 8884e92f2d
4 changed files with 17 additions and 6 deletions

View File

@ -768,7 +768,8 @@ Authorization: Bearer <your_jwt_token>
```json
{
"title_content": "我的作文全文......",
"theme": "标题(可选)",
"content": "正文内容",
"article_type": "议论文"
}
```

View File

@ -1,9 +1,11 @@
from typing import Optional
from pydantic import BaseModel
class UserArticleRequest(BaseModel):
# theme: Optional[str]
title_content: str
theme: Optional[str]
content: str
article_type: str
class UserQuery(BaseModel):

View File

@ -33,7 +33,7 @@ async def article_director(
article_lang = "法语" if lang == "fr-FR" else "日语"
user_id = user[0].id
article = upload_article.title_content
article = upload_article.content
# 读取历史对话
session = await service.get_session(redis_client=redis, user_id=user_id)

View File

@ -42,10 +42,16 @@ def chat_ecnu_request(
return completion
def set_user_prompt(user_article: UserArticleRequest, article_lang: str):
user_prompt = f"以下是我的{article_lang}作文,作文体裁为{user_article.article_type},请帮我修改:{user_article.title_content}"
if user_article.theme is not None:
user_prompt = f"以下是我的{article_lang}作文,作文体裁为{user_article.article_type},标题为{user_article.theme}, 请帮我修改:{user_article.content}"
else:
user_prompt = f"以下是我的{article_lang}作文,作文体裁为{user_article.article_type} 请帮我修改:{user_article.content}"
return user_prompt
async def get_session(redis_client: Redis, user_id: str) -> List[Dict[str, str]]:
"""从 Redis 读取对话上下文"""
data = await redis_client.get(f"session:{user_id}")
@ -55,10 +61,12 @@ async def get_session(redis_client: Redis, user_id: str) -> List[Dict[str, str]]
# 如果没有记录,创建带 system prompt 的初始会话
return [{"role": "system", "content": SYSTEM_PROMPT}]
async def save_session(redis_client: Redis, user_id: str, session: List[Dict[str, str]]):
"""保存对话上下文到 Redis"""
await redis_client.setex(f"session:{user_id}", 86400, json.dumps(session))
async def reset_session(redis_client: Redis, user_id: str):
"""清空用户上下文"""
await redis_client.delete(f"session:{user_id}")