From 1e9b7d90e7eba975fc8774de424f943f339ded5a Mon Sep 17 00:00:00 2001 From: z30057876 Date: Fri, 28 Nov 2025 14:39:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=A3=8E=E6=8E=A7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=881=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/{oidc.py => auth.py} | 1 + apps/common/wordscheck.py | 49 ------ apps/routers/auth.py | 2 +- apps/routers/blacklist.py | 263 ------------------------------- apps/routers/chat.py | 24 +-- 5 files changed, 3 insertions(+), 336 deletions(-) rename apps/common/{oidc.py => auth.py} (99%) delete mode 100644 apps/common/wordscheck.py delete mode 100644 apps/routers/blacklist.py diff --git a/apps/common/oidc.py b/apps/common/auth.py similarity index 99% rename from apps/common/oidc.py rename to apps/common/auth.py index f0a5692ec..a29c84cd4 100644 --- a/apps/common/oidc.py +++ b/apps/common/auth.py @@ -1,6 +1,7 @@ # Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. """OIDC模块""" +import grp import logging from datetime import UTC, datetime, timedelta from typing import Any diff --git a/apps/common/wordscheck.py b/apps/common/wordscheck.py deleted file mode 100644 index 4495c6316..000000000 --- a/apps/common/wordscheck.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. -"""敏感词检查模块""" - -import logging -from pathlib import Path - -from .config import config - -logger = logging.getLogger(__name__) - - -class _WordsCheck: - """敏感词检查工具(内部类)""" - - def __init__(self) -> None: - """初始化""" - self._words_list: list[str] = [] - self._initialized = False - - def _init_words_list(self) -> None: - """同步初始化敏感词列表""" - if not self._initialized and config.check.enable: - with Path(config.check.words_list).open(encoding="utf-8") as f: - self._words_list = f.read().splitlines() - self._initialized = True - - async def _check_wordlist(self, message: str) -> int: - """使用关键词列表检查敏感词""" - if not self._initialized: - self._init_words_list() - for word in self._words_list: - if word in message: - return 1 - return 0 - - async def check(self, message: str) -> int: - """ - 检查消息是否包含关键词 - - 异常-1,拦截0,正常1 - """ - if config.check.enable: - return await self._check_wordlist(message) - # 不设置检查类型,默认不拦截 - return 1 - - -# 全局单例对象 -words_check = _WordsCheck() diff --git a/apps/routers/auth.py b/apps/routers/auth.py index 718d49a98..73e0326f4 100644 --- a/apps/routers/auth.py +++ b/apps/routers/auth.py @@ -10,7 +10,7 @@ from fastapi.encoders import jsonable_encoder from fastapi.responses import HTMLResponse, JSONResponse from fastapi.templating import Jinja2Templates -from apps.common.oidc import oidc_provider +from apps.common.auth import oidc_provider from apps.dependency import verify_personal_token, verify_session from apps.schemas.personal_token import PostPersonalTokenMsg, PostPersonalTokenRsp from apps.schemas.response_data import ( diff --git a/apps/routers/blacklist.py b/apps/routers/blacklist.py deleted file mode 100644 index e6e29e54b..000000000 --- a/apps/routers/blacklist.py +++ /dev/null @@ -1,263 +0,0 @@ -# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. -"""FastAPI 黑名单相关路由""" - -from fastapi import APIRouter, Depends, Request, status -from fastapi.encoders import jsonable_encoder -from fastapi.responses import JSONResponse - -from apps.dependency.user import verify_admin, verify_personal_token, verify_session -from apps.schemas.blacklist import ( - AbuseProcessRequest, - AbuseRequest, - BlacklistSchema, - GetBlacklistQuestionMsg, - GetBlacklistQuestionRsp, - GetBlacklistUserMsg, - GetBlacklistUserRsp, - QuestionBlacklistRequest, - UserBlacklistRequest, -) -from apps.schemas.response_data import ( - ResponseData, -) -from apps.services.blacklist import AbuseManager, QuestionBlacklistManager, UserBlacklistManager - -admin_router = APIRouter( - prefix="/api/blacklist", - tags=["blacklist"], - dependencies=[ - Depends(verify_session), - Depends(verify_personal_token), - Depends(verify_admin), - ], -) -router = APIRouter( - prefix="/api/blacklist", - tags=["blacklist"], - dependencies=[ - Depends(verify_session), - Depends(verify_personal_token), - ], -) -PAGE_SIZE = 20 -MAX_CREDIT = 100 - - -@admin_router.get("/user", response_model=GetBlacklistUserRsp) -async def get_blacklist_user(page: int = 0) -> JSONResponse: - """GET /blacklist/user?page=xxx: 获取黑名单用户""" - # 计算分页 - user_list = await UserBlacklistManager.get_blacklisted_users( - PAGE_SIZE, - page * PAGE_SIZE, - ) - - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - GetBlacklistUserRsp( - code=status.HTTP_200_OK, - message="ok", - result=GetBlacklistUserMsg(users=user_list), - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - - -@admin_router.post("/user", response_model=ResponseData) -async def change_blacklist_user(request: UserBlacklistRequest) -> JSONResponse: - """POST /blacklist/user: 操作黑名单用户""" - # 拉黑用户 - if request.is_ban: - result = await UserBlacklistManager.change_blacklisted_users( - request.user_id, - -MAX_CREDIT, - ) - # 解除拉黑 - else: - result = await UserBlacklistManager.change_blacklisted_users( - request.user_id, - MAX_CREDIT, - ) - - if not result: - return JSONResponse( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_500_INTERNAL_SERVER_ERROR, - message="Change user blacklist error.", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_200_OK, - message="ok", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - -@admin_router.get("/question", response_model=GetBlacklistQuestionRsp) -async def get_blacklist_question(page: int = 0) -> JSONResponse: - """ - GET /blacklist/question?page=xxx: 获取黑名单问题 - - 目前情况下,先直接输出问题,不做用户类型校验 - """ - # 计算分页 - question_list = await QuestionBlacklistManager.get_blacklisted_questions( - PAGE_SIZE, - page * PAGE_SIZE, - is_audited=True, - ) - # 将SQLAlchemy模型转换为Pydantic模型 - question_schemas = [BlacklistSchema.model_validate(q) for q in question_list] - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - GetBlacklistQuestionRsp( - code=status.HTTP_200_OK, - message="ok", - result=GetBlacklistQuestionMsg(question_list=question_schemas), - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - -@admin_router.post("/question", response_model=ResponseData) -async def change_blacklist_question(request: QuestionBlacklistRequest) -> JSONResponse: - """POST /blacklist/question: 黑名单问题检测或操作""" - # 删问题 - if request.is_deletion: - result = await QuestionBlacklistManager.change_blacklisted_questions( - request.id, - request.question, - request.answer, - is_deletion=True, - ) - else: - # 改问题 - result = await QuestionBlacklistManager.change_blacklisted_questions( - request.id, - request.question, - request.answer, - is_deletion=False, - ) - - if not result: - return JSONResponse( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_500_INTERNAL_SERVER_ERROR, - message="Modify question blacklist error.", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_200_OK, - message="ok", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - - -@router.post("/complaint", response_model=ResponseData) -async def abuse_report(raw_request: Request, request: AbuseRequest) -> JSONResponse: - """POST /blacklist/complaint: 用户实施举报""" - result = await AbuseManager.change_abuse_report( - raw_request.state.user_id, - request.record_id, - request.reason_type, - request.reason, - ) - - if not result: - return JSONResponse( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_500_INTERNAL_SERVER_ERROR, - message="Report abuse complaint error.", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_200_OK, - message="ok", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - - -@admin_router.get("/abuse", response_model=GetBlacklistQuestionRsp) -async def get_abuse_report(page: int = 0) -> JSONResponse: - """GET /blacklist/abuse?page=xxx: 获取待审核的问答对""" - # 此处前端需记录ID - result = await QuestionBlacklistManager.get_blacklisted_questions( - PAGE_SIZE, - page * PAGE_SIZE, - is_audited=False, - ) - # 将SQLAlchemy模型转换为Pydantic模型 - result_schemas = [BlacklistSchema.model_validate(r) for r in result] - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - GetBlacklistQuestionRsp( - code=status.HTTP_200_OK, - message="ok", - result=GetBlacklistQuestionMsg(question_list=result_schemas), - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - -@admin_router.post("/abuse", response_model=ResponseData) -async def change_abuse_report(request: AbuseProcessRequest) -> JSONResponse: - """POST /blacklist/abuse: 对被举报问答对进行操作""" - if request.is_deletion: - result = await AbuseManager.audit_abuse_report( - request.id, - is_deletion=True, - ) - else: - result = await AbuseManager.audit_abuse_report( - request.id, - is_deletion=False, - ) - - if not result: - return JSONResponse( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_500_INTERNAL_SERVER_ERROR, - message="Audit abuse question error.", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) - return JSONResponse( - status_code=status.HTTP_200_OK, - content=jsonable_encoder( - ResponseData( - code=status.HTTP_200_OK, - message="ok", - result={}, - ).model_dump(exclude_none=True, by_alias=True), - ), - ) diff --git a/apps/routers/chat.py b/apps/routers/chat.py index 08fc0a562..1c1e19738 100644 --- a/apps/routers/chat.py +++ b/apps/routers/chat.py @@ -5,19 +5,17 @@ import asyncio import logging from collections.abc import AsyncGenerator -from fastapi import APIRouter, Depends, HTTPException, Request, status +from fastapi import APIRouter, Depends, Request, status from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse, StreamingResponse from apps.common.queue import MessageQueue -from apps.common.wordscheck import words_check from apps.dependency import verify_personal_token, verify_session from apps.models import ExecutorStatus from apps.scheduler.scheduler import Scheduler from apps.schemas.request_data import RequestData from apps.schemas.response_data import ResponseData from apps.services.activity import Activity -from apps.services.blacklist import QuestionBlacklistManager, UserBlacklistManager from apps.services.flow import FlowManager _logger = logging.getLogger(__name__) @@ -33,12 +31,6 @@ router = APIRouter( async def chat_generator(post_body: RequestData, user_id: str, auth_header: str) -> AsyncGenerator[str, None]: """进行实际问答,并从MQ中获取消息""" try: - # 敏感词检查 - if await words_check.check(post_body.question) != 1: - yield "data: [SENSITIVE]\n\n" - _logger.info("[Chat] 问题包含敏感词!") - return - # 创建queue;由Scheduler进行关闭 queue = MessageQueue() await queue.init() @@ -71,13 +63,6 @@ async def chat_generator(post_body: RequestData, user_id: str, auth_header: str) await Activity.remove_active(user_id) return - # 对结果进行敏感词检查 - if await words_check.check(task.runtime.fullAnswer) != 1: - yield "data: [SENSITIVE]\n\n" - _logger.info("[Chat] 答案包含敏感词!") - await Activity.remove_active(user_id) - return - if post_body.app and post_body.app.flow_id: await FlowManager.update_flow_debug_by_app_and_flow_id( post_body.app.app_id, @@ -100,13 +85,6 @@ async def chat(request: Request, post_body: RequestData) -> StreamingResponse: """LLM流式对话接口""" auth_header = request.headers.get("Authorization", "").replace("Bearer ", "") user_id = request.state.user_id - # 问题黑名单检测 - if (post_body.question is not None) and ( - not await QuestionBlacklistManager.check_blacklisted_questions(input_question=post_body.question) - ): - # 用户扣分 - await UserBlacklistManager.change_blacklisted_users(user_id, -10) - raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="question is blacklisted") res = chat_generator(post_body, user_id, auth_header) return StreamingResponse( -- Gitee From 3d87d9ae5575423bd74a23637e6d2d834b7c403c Mon Sep 17 00:00:00 2001 From: z30057876 Date: Fri, 28 Nov 2025 14:40:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=A3=8E=E6=8E=A7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=882=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/main.py | 3 - apps/services/blacklist.py | 218 ------------------------------------- apps/services/session.py | 8 -- apps/services/task.py | 6 +- apps/services/token.py | 2 +- 5 files changed, 5 insertions(+), 232 deletions(-) delete mode 100644 apps/services/blacklist.py diff --git a/apps/main.py b/apps/main.py index 083a66a1f..9aa852e33 100644 --- a/apps/main.py +++ b/apps/main.py @@ -17,7 +17,6 @@ from .common.postgres import postgres from .routers import ( appcenter, auth, - blacklist, chat, comment, conversation, @@ -65,8 +64,6 @@ app.add_middleware( app.include_router(appcenter.router) app.include_router(auth.admin_router) app.include_router(auth.router) -app.include_router(blacklist.admin_router) -app.include_router(blacklist.router) app.include_router(chat.router) app.include_router(comment.router) app.include_router(conversation.router) diff --git a/apps/services/blacklist.py b/apps/services/blacklist.py deleted file mode 100644 index a0bd62a76..000000000 --- a/apps/services/blacklist.py +++ /dev/null @@ -1,218 +0,0 @@ -# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. -"""黑名单相关操作""" - -import logging -import uuid - -from sqlalchemy import and_, select - -from apps.common.postgres import postgres -from apps.common.security import Security -from apps.models import Blacklist, Record, User -from apps.schemas.blacklist import BlacklistedUser -from apps.schemas.record import RecordContent - -logger = logging.getLogger(__name__) - - -class QuestionBlacklistManager: - """问题黑名单相关操作""" - - @staticmethod - async def check_blacklisted_questions(input_question: str) -> bool: - """给定问题,查找问题是否在黑名单里""" - async with postgres.session() as session: - # 查找是否有审核通过的黑名单问题包含输入的问题 - blacklist_item = (await session.scalars(select(Blacklist).where( - and_( - Blacklist.question.ilike(f"%{input_question}%"), - Blacklist.isAudited == True, # noqa: E712 - ), - ).limit(1))).one_or_none() - - if blacklist_item: - # 用户输入的问题中包含黑名单问题的一部分,故拉黑 - logger.info("[QuestionBlacklistManager] 问题在黑名单中") - return False - return True - - @staticmethod - async def change_blacklisted_questions( - blacklist_id: str, question: str, answer: str, *, is_deletion: bool = False, - ) -> bool: - """ - 删除或修改已在黑名单里的问题 - - is_deletion标识是否为删除操作 - """ - async with postgres.session() as session: - # 根据ID查找黑名单记录 - blacklist_item = await session.get(Blacklist, int(blacklist_id)) - - if not blacklist_item: - logger.info("[QuestionBlacklistManager] 黑名单记录不存在") - return False - - if is_deletion: - await session.delete(blacklist_item) - logger.info("[QuestionBlacklistManager] 问题从黑名单中删除") - else: - # 修改 - blacklist_item.question = question - blacklist_item.answer = answer - logger.info("[QuestionBlacklistManager] 问题在黑名单中修改") - - await session.commit() - return True - - @staticmethod - async def get_blacklisted_questions(limit: int, offset: int, *, is_audited: bool) -> list[Blacklist]: - """分页式获取目前所有的问题(待审核或已拉黑)黑名单""" - async with postgres.session() as session: - return list((await session.scalars(select(Blacklist).where( - Blacklist.isAudited == is_audited, - ).offset(offset).limit(limit))).all()) - - -class UserBlacklistManager: - """用户黑名单相关操作""" - - @staticmethod - async def get_blacklisted_users(limit: int, offset: int) -> list[BlacklistedUser]: - """获取当前所有黑名单用户""" - async with postgres.session() as session: - users = (await session.scalars(select(User).where( - User.credit <= 0, - ).order_by(User.userName).offset(offset).limit(limit))).all() - return [BlacklistedUser(user_id=user.id, user_name=user.userName) for user in users] - - @staticmethod - async def check_blacklisted_users(user_id: str) -> bool: - """检测某用户是否已被拉黑""" - async with postgres.session() as session: - conditions = [ - User.credit <= 0, - User.isWhitelisted == False, # noqa: E712 - User.id == user_id, - ] - - user = (await session.scalars(select(User).where( - and_(*conditions), - ).limit(1))).one_or_none() - - if user: - logger.info("[UserBlacklistManager] 用户在黑名单中") - return True - return False - - @staticmethod - async def change_blacklisted_users(user_id: str, credit_diff: int, credit_limit: int = 100) -> bool: - """修改用户的信用分""" - async with postgres.session() as session: - # 获取用户当前信用分 - user = (await session.scalars(select(User).where(User.id == user_id))).one_or_none() - - # 用户不存在 - if user is None: - logger.info("[UserBlacklistManager] 用户不存在") - return False - - # 用户已被加白,什么都不做 - if user.isWhitelisted: - return False - - if user.credit > 0 and credit_diff > 0: - logger.info("[UserBlacklistManager] 用户已解禁") - return True - if user.credit <= 0 and credit_diff < 0: - logger.info("[UserBlacklistManager] 用户已封禁") - return True - - # 给当前用户的信用分加上偏移量 - new_credit = user.credit + credit_diff - # 不得超过积分上限 - if new_credit > credit_limit: - new_credit = credit_limit - # 不得小于0 - elif new_credit < 0: - new_credit = 0 - - # 更新用户信用分 - user.credit = new_credit - await session.commit() - return True - - -class AbuseManager: - """用户举报相关操作""" - - @staticmethod - async def change_abuse_report(user_id: str, record_id: uuid.UUID, reason_type: str, reason: str) -> bool: - """存储用户举报详情""" - async with postgres.session() as session: - # Verify user exists - user = (await session.scalars(select(User).where(User.id == user_id))).one_or_none() - if not user: - logger.info("[AbuseManager] 用户不存在") - return False - - record = (await session.scalars(select(Record).where( - and_( - Record.userId == user_id, - Record.id == record_id, - ), - ))).one_or_none() - - if not record: - logger.info("[AbuseManager] 举报记录不合法") - return False - - # 获得Record明文内容 - record_data = Security.decrypt(record.content, record.key) - record_content = RecordContent.model_validate_json(record_data) - - # 检查该条目类似内容是否已被举报过 - existing_blacklist = (await session.scalars(select(Blacklist).where( - Blacklist.recordId == record_id, - ).limit(1))).one_or_none() - - if existing_blacklist is not None: - logger.info("[AbuseManager] 问题已被举报过") - return True - - # 增加新条目 - new_blacklist = Blacklist( - recordId=record_id, - question=record_content.question, - answer=record_content.answer, - isAudited=False, - reasonType=reason_type, - reason=reason, - ) - - session.add(new_blacklist) - await session.commit() - return True - - @staticmethod - async def audit_abuse_report(record_id: uuid.UUID, *, is_deletion: bool = False) -> bool: - """对某一特定的待审问题进行操作,包括批准审核与删除未审问题""" - async with postgres.session() as session: - blacklist_item = (await session.scalars(select(Blacklist).where( - and_( - Blacklist.recordId == record_id, - Blacklist.isAudited == False, # noqa: E712 - ), - ))).one_or_none() - - if not blacklist_item: - logger.info("[AbuseManager] 待审核问题不存在") - return False - - if is_deletion: - await session.delete(blacklist_item) - else: - blacklist_item.isAudited = True - - await session.commit() - return True diff --git a/apps/services/session.py b/apps/services/session.py index fb3947ab8..5f672d9a2 100644 --- a/apps/services/session.py +++ b/apps/services/session.py @@ -10,8 +10,6 @@ from apps.common.postgres import postgres from apps.constants import SESSION_TTL from apps.models import Session, SessionType -from .blacklist import UserBlacklistManager - logger = logging.getLogger(__name__) @@ -65,12 +63,6 @@ class SessionManager: if not user_id: return None - # 查询黑名单 - if user_id and await UserBlacklistManager.check_blacklisted_users(user_id): - logger.error("[SessionManager] 用户在Session黑名单中") - await SessionManager.delete_session(session_id) - return None - return user_id diff --git a/apps/services/task.py b/apps/services/task.py index 4cd35bf90..b4bfa494b 100644 --- a/apps/services/task.py +++ b/apps/services/task.py @@ -44,11 +44,13 @@ class TaskManager: )).one_or_none() if not task: # 任务不存在,新建Task - return Task( + new_task = Task( conversationId=conversation_id, userId=user_id, ) - logger.info("[TaskManager] 新建任务 %s", task.id) + logger.info("[TaskManager] 创建新任务对象 (未保存)") + return new_task + logger.info("[TaskManager] 找到已存在的任务 %s", task.id) return task diff --git a/apps/services/token.py b/apps/services/token.py index a4c335d69..e9466058e 100644 --- a/apps/services/token.py +++ b/apps/services/token.py @@ -10,7 +10,7 @@ from fastapi import status from sqlalchemy import and_, select from apps.common.config import config -from apps.common.oidc import oidc_provider +from apps.common.auth import oidc_provider from apps.common.postgres import postgres from apps.constants import OIDC_ACCESS_TOKEN_EXPIRE_TIME from apps.models import Session, SessionType -- Gitee From c9455d7366487847d1b076d468023e230a86a7ad Mon Sep 17 00:00:00 2001 From: z30057876 Date: Fri, 28 Nov 2025 14:40:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D=E3=80=81=E6=9B=B4=E6=96=B0=E6=A0=B7=E4=BE=8B=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/.config.example.toml | 52 +++++++------------------ data/prompts/call/llm_step_memory.en.md | 4 +- data/prompts/call/llm_step_memory.zh.md | 4 +- 3 files changed, 18 insertions(+), 42 deletions(-) diff --git a/data/.config.example.toml b/data/.config.example.toml index a59ee23a4..2af0066e9 100644 --- a/data/.config.example.toml +++ b/data/.config.example.toml @@ -8,6 +8,7 @@ provider = 'authhub' admin_user = [ "admin" ] + [login.settings] host = 'http://127.0.0.1:8000' host_inner = 'http://127.0.0.1:11120' @@ -15,30 +16,11 @@ login_api = 'http://127.0.0.1:8080/api/auth/login' app_id = '' app_secret = '' -[fastapi] -domain = '127.0.0.1' - -[security] -half_key1 = '' -half_key2 = '' -half_key3 = '' -jwt_key = '' - -[embedding] -type = 'openai' -endpoint = 'https://api.openai.com/v1' -api_key = '' -model = 'bge-m3' - [rag] rag_service = 'http://127.0.0.1:9988' -[mongodb] -host = '127.0.0.1' -port = 27017 -user = 'euler_copilot' -password = '' -database = 'euler_copilot' +[fastapi] +domain = '127.0.0.1' [minio] endpoint = '127.0.0.1:9000' @@ -46,24 +28,18 @@ access_key = 'minioadmin' secret_key = '' secure = false -[llm] -endpoint = 'https://api.openai.com/v1' -key = '' -model = 'gpt-4o-mini' -max_tokens = 8192 -temperature = 0.7 - -[function_call] -backend = 'ollama' -endpoint = 'http://localhost:11434' -model = 'qwen2.5:7b' -api_key = '' -max_tokens = 8192 -temperature = 0.7 +[postgres] +host = '127.0.0.1' +port = 5432 +user = 'euler_copilot' +password = '' +database = 'euler_copilot' -[check] -enable = false -words_list = '' +[security] +half_key1 = '' +half_key2 = '' +half_key3 = '' +jwt_key = '' [extra] sql_url = 'http://127.0.0.1:9015' diff --git a/data/prompts/call/llm_step_memory.en.md b/data/prompts/call/llm_step_memory.en.md index 2646fa4d8..1092614bd 100644 --- a/data/prompts/call/llm_step_memory.en.md +++ b/data/prompts/call/llm_step_memory.en.md @@ -14,7 +14,7 @@ To complete this step, we invoked the tool `{{ step_name }}`. The parameters provided to the tool are: ```json -{{ input_data | tojson }} +{{ input_data | tojson(ensure_ascii=False, indent=2) }} ``` {% elif role == "assistant" %} @@ -31,7 +31,7 @@ Execution status: {{ step_status }} The data obtained from the tool execution is: ```json -{{ output_data | tojson }} +{{ output_data | tojson(ensure_ascii=False, indent=2) }} ``` This data will be used as input or reference information for subsequent steps. diff --git a/data/prompts/call/llm_step_memory.zh.md b/data/prompts/call/llm_step_memory.zh.md index d11588746..fad1ae56c 100644 --- a/data/prompts/call/llm_step_memory.zh.md +++ b/data/prompts/call/llm_step_memory.zh.md @@ -14,7 +14,7 @@ 提供给工具的参数为: ```json -{{ input_data | tojson }} +{{ input_data | tojson(ensure_ascii=False, indent=2) }} ``` {% elif role == "assistant" %} @@ -31,7 +31,7 @@ 工具执行后得到的数据为: ```json -{{ output_data | tojson }} +{{ output_data | tojson(ensure_ascii=False, indent=2) }} ``` 这些数据将作为后续步骤的输入或参考信息使用。 -- Gitee From c063966918b74448914cccc299742df3fe3c46c3 Mon Sep 17 00:00:00 2001 From: z30057876 Date: Fri, 28 Nov 2025 14:41:20 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=A3=8E=E6=8E=A7?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=883=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/schemas/blacklist.py | 96 --------------------------------------- apps/schemas/config.py | 8 ---- tests/common/test_oidc.py | 2 +- 3 files changed, 1 insertion(+), 105 deletions(-) delete mode 100644 apps/schemas/blacklist.py diff --git a/apps/schemas/blacklist.py b/apps/schemas/blacklist.py deleted file mode 100644 index 093d066ae..000000000 --- a/apps/schemas/blacklist.py +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. -"""黑名单相关数据结构""" - -import uuid - -from pydantic import BaseModel - -from apps.schemas.response_data import ResponseData - - -class QuestionBlacklistRequest(BaseModel): - """POST /api/blacklist/question 请求数据结构""" - - id: str - question: str - answer: str - is_deletion: int - - -class UserBlacklistRequest(BaseModel): - """POST /api/blacklist/user 请求数据结构""" - - user_id: str - is_ban: int - - -class AbuseRequest(BaseModel): - """POST /api/blacklist/complaint 请求数据结构""" - - record_id: uuid.UUID - reason: str - reason_type: str - - -class AbuseProcessRequest(BaseModel): - """POST /api/blacklist/abuse 请求数据结构""" - - id: uuid.UUID - is_deletion: int - - -class BlacklistSchema(BaseModel): - """黑名单 Pydantic 数据结构""" - - id: int - """主键ID""" - recordId: uuid.UUID # noqa: N815 - """关联的问答对ID""" - question: str - """黑名单问题""" - answer: str | None - """应做出的固定回答""" - isAudited: bool # noqa: N815 - """黑名单是否生效""" - reasonType: str # noqa: N815 - """举报类型""" - reason: str - """举报原因""" - updatedAt: str # noqa: N815 - """更新时间""" - - class Config: - """Pydantic 配置""" - - from_attributes = True - - -class BlacklistedUser(BaseModel): - """被封禁用户的数据结构""" - - user_id: str - user_name: str - - -class GetBlacklistUserMsg(BaseModel): - """GET /api/blacklist/user Result数据结构""" - - users: list[BlacklistedUser] - - -class GetBlacklistUserRsp(ResponseData): - """GET /api/blacklist/user 返回数据结构""" - - result: GetBlacklistUserMsg - - -class GetBlacklistQuestionMsg(BaseModel): - """GET /api/blacklist/question Result数据结构""" - - question_list: list[BlacklistSchema] - - -class GetBlacklistQuestionRsp(ResponseData): - """GET /api/blacklist/question 返回数据结构""" - - result: GetBlacklistQuestionMsg diff --git a/apps/schemas/config.py b/apps/schemas/config.py index 34e48b57d..3ff43fd0a 100644 --- a/apps/schemas/config.py +++ b/apps/schemas/config.py @@ -80,13 +80,6 @@ class SecurityConfig(BaseModel): jwt_key: str = Field(description="JWT key") -class CheckConfig(BaseModel): - """敏感词检测配置""" - - enable: bool = Field(description="是否启用敏感词检测") - words_list: str = Field(description="敏感词列表文件路径") - - class ExtraConfig(BaseModel): """额外配置""" @@ -103,5 +96,4 @@ class ConfigModel(BaseModel): minio: MinioConfig postgres: PostgresConfig security: SecurityConfig - check: CheckConfig extra: ExtraConfig diff --git a/tests/common/test_oidc.py b/tests/common/test_oidc.py index f376f14fa..53edaf01b 100644 --- a/tests/common/test_oidc.py +++ b/tests/common/test_oidc.py @@ -5,7 +5,7 @@ import unittest from unittest.mock import patch, MagicMock from http import HTTPStatus from fastapi.exceptions import HTTPException -from apps.common.oidc import get_oidc_token, get_oidc_user +from apps.common.auth import get_oidc_token, get_oidc_user from apps.common.config import config -- Gitee