docker build 构建修改

This commit is contained in:
2025-11-06 17:15:46 +08:00
parent 33e09afc54
commit ecdb4321e8
58 changed files with 72216 additions and 237 deletions

View File

@@ -24,25 +24,43 @@ from api.utils.api_utils import get_json_result
http_bearer = HTTPBearer(auto_error=False)
def get_current_user(credentials: Optional[HTTPAuthorizationCredentials] = Security(http_bearer)):
def get_current_user(
authorization: Optional[str] = Header(None, alias="Authorization"),
credentials: Optional[HTTPAuthorizationCredentials] = Security(http_bearer)
):
"""FastAPI 依赖注入:获取当前用户(替代 Flask 的 login_required 和 current_user
支持两种格式的 Authorization 头:
1. 标准格式Bearer <token>
2. 简化格式:<token>(不带 Bearer 前缀)
使用 Security(http_bearer) 可以让 FastAPI 自动在 OpenAPI schema 中添加安全要求,
这样 Swagger UI 就会显示授权输入框并自动在请求中添加 Authorization 头。
"""
# 延迟导入以避免循环导入
from api.apps.__init___fastapi import get_current_user_from_token
if not credentials:
token = None
# 优先从 HTTPBearer 获取标准格式Bearer <token>
if credentials:
token = credentials.credentials
# 如果 HTTPBearer 没有获取到,尝试直接从 Header 获取(可能是简化格式)
elif authorization:
# 如果包含 "Bearer " 前缀,则去除它
if authorization.startswith("Bearer "):
token = authorization[7:] # 去除 "Bearer " 前缀7个字符
else:
# 不带 Bearer 前缀,直接使用
token = authorization
if not token:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Authorization header is required"
)
# HTTPBearer 已经提取了 Bearer tokencredentials.credentials 就是 token 本身
authorization = credentials.credentials
user = get_current_user_from_token(authorization)
user = get_current_user_from_token(token)
if not user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,

View File

@@ -0,0 +1,57 @@
#
# Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Optional, List, Dict, Any
from pydantic import BaseModel, Field
class SetDialogRequest(BaseModel):
"""设置/创建对话框请求"""
dialog_id: Optional[str] = Field(default="", description="对话框ID为空时创建新对话框")
name: Optional[str] = Field(default="New Dialog", description="对话框名称")
description: Optional[str] = Field(default="A helpful dialog", description="对话框描述")
icon: Optional[str] = Field(default="", description="图标")
top_n: Optional[int] = Field(default=6, description="Top N")
top_k: Optional[int] = Field(default=1024, description="Top K")
rerank_id: Optional[str] = Field(default="", description="重排序模型ID")
similarity_threshold: Optional[float] = Field(default=0.1, description="相似度阈值")
vector_similarity_weight: Optional[float] = Field(default=0.3, description="向量相似度权重")
llm_setting: Optional[Dict[str, Any]] = Field(default={}, description="LLM设置")
meta_data_filter: Optional[Dict[str, Any]] = Field(default={}, description="元数据过滤器")
prompt_config: Dict[str, Any] = Field(..., description="提示配置")
kb_ids: Optional[List[str]] = Field(default=[], description="知识库ID列表")
llm_id: Optional[str] = Field(default=None, description="LLM ID")
class ListDialogsNextQuery(BaseModel):
"""列出对话框查询参数"""
keywords: Optional[str] = ""
page: Optional[int] = 0
page_size: Optional[int] = 0
parser_id: Optional[str] = None
orderby: Optional[str] = "create_time"
desc: Optional[str] = "true"
class ListDialogsNextBody(BaseModel):
"""列出对话框请求体"""
owner_ids: Optional[List[str]] = []
class DeleteDialogRequest(BaseModel):
"""删除对话框请求"""
dialog_ids: List[str] = Field(..., description="要删除的对话框ID列表")

View File

@@ -138,11 +138,11 @@ class GetDocumentInfosRequest(BaseModel):
class ChangeStatusRequest(BaseModel):
"""修改文档状态请求"""
doc_ids: List[str]
status: str # "0" 或 "1"
status: int
@model_validator(mode='after')
def validate_status(self):
if self.status not in ["0", "1"]:
if self.status not in [0, 1]:
raise ValueError('Status must be either 0 or 1!')
return self
@@ -155,7 +155,7 @@ class DeleteDocumentRequest(BaseModel):
class RunDocumentRequest(BaseModel):
"""运行文档解析请求"""
doc_ids: List[str]
run: str # TaskStatus 值
run: int # TaskStatus 值
delete: Optional[bool] = False

View File

@@ -0,0 +1,23 @@
#
# Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from pydantic import BaseModel, Field, EmailStr
class InviteUserRequest(BaseModel):
"""邀请用户请求"""
email: EmailStr = Field(..., description="要邀请的用户邮箱")