Merge branch 'develop' into fix/memory-enduser-config
This commit is contained in:
@@ -26,6 +26,9 @@ from .app_schema import (
|
||||
MemoryConfig,
|
||||
ToolConfig,
|
||||
VariableDefinition,
|
||||
FileInput,
|
||||
FileType,
|
||||
TransferMethod,
|
||||
)
|
||||
from .conversation_schema import (
|
||||
Conversation,
|
||||
@@ -94,6 +97,9 @@ __all__ = [
|
||||
"MemoryConfig",
|
||||
"ToolConfig",
|
||||
"VariableDefinition",
|
||||
"FileInput",
|
||||
"FileType",
|
||||
"TransferMethod",
|
||||
"Conversation",
|
||||
"ConversationCreate",
|
||||
"ConversationWithMessages",
|
||||
|
||||
@@ -1,10 +1,51 @@
|
||||
import datetime
|
||||
import uuid
|
||||
from typing import Optional, Any, List, Dict, Union
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel, Field, ConfigDict, field_serializer, field_validator
|
||||
|
||||
|
||||
# ---------- Multimodal File Support ----------
|
||||
|
||||
class FileType(str, Enum):
|
||||
"""文件类型枚举"""
|
||||
IMAGE = "image"
|
||||
DOCUMENT = "document"
|
||||
AUDIO = "audio"
|
||||
VIDEO = "video"
|
||||
|
||||
|
||||
class TransferMethod(str, Enum):
|
||||
"""文件传输方式枚举"""
|
||||
LOCAL_FILE = "local_file" # 已上传到系统的文件
|
||||
REMOTE_URL = "remote_url" # 外部URL
|
||||
|
||||
|
||||
class FileInput(BaseModel):
|
||||
"""文件输入 Schema"""
|
||||
type: FileType = Field(..., description="文件类型: image/document/audio/video")
|
||||
transfer_method: TransferMethod = Field(..., description="传输方式: local_file/remote_url")
|
||||
upload_file_id: Optional[uuid.UUID] = Field(None, description="已上传文件ID(local_file时必填)")
|
||||
url: Optional[str] = Field(None, description="远程URL(remote_url时必填)")
|
||||
|
||||
@field_validator("upload_file_id")
|
||||
@classmethod
|
||||
def validate_local_file(cls, v, info):
|
||||
"""验证 local_file 时必须提供 upload_file_id"""
|
||||
if info.data.get("transfer_method") == TransferMethod.LOCAL_FILE and not v:
|
||||
raise ValueError("transfer_method 为 local_file 时,upload_file_id 不能为空")
|
||||
return v
|
||||
|
||||
@field_validator("url")
|
||||
@classmethod
|
||||
def validate_remote_url(cls, v, info):
|
||||
"""验证 remote_url 时必须提供 url"""
|
||||
if info.data.get("transfer_method") == TransferMethod.REMOTE_URL and not v:
|
||||
raise ValueError("transfer_method 为 remote_url 时,url 不能为空")
|
||||
return v
|
||||
|
||||
|
||||
# ---------- Input Schemas ----------
|
||||
|
||||
class KnowledgeBaseConfig(BaseModel):
|
||||
@@ -360,6 +401,7 @@ class AppChatRequest(BaseModel):
|
||||
user_id: Optional[str] = Field(default=None, description="用户ID(用于会话管理)")
|
||||
variables: Optional[Dict[str, Any]] = Field(default=None, description="自定义变量参数值")
|
||||
stream: bool = Field(default=False, description="是否流式返回")
|
||||
files: Optional[List[FileInput]] = Field(default=None, description="附件列表(支持多文件)")
|
||||
|
||||
|
||||
class DraftRunRequest(BaseModel):
|
||||
@@ -369,6 +411,7 @@ class DraftRunRequest(BaseModel):
|
||||
user_id: Optional[str] = Field(default=None, description="用户ID(用于会话管理)")
|
||||
variables: Optional[Dict[str, Any]] = Field(default=None, description="自定义变量参数值")
|
||||
stream: bool = Field(default=False, description="是否流式返回")
|
||||
files: Optional[List[FileInput]] = Field(default=None, description="附件列表(支持多文件)")
|
||||
|
||||
|
||||
class DraftRunResponse(BaseModel):
|
||||
|
||||
@@ -4,6 +4,9 @@ import datetime
|
||||
from typing import Optional, Dict, Any, List
|
||||
from pydantic import BaseModel, Field, ConfigDict, field_serializer
|
||||
|
||||
# 导入 FileInput(用于体验运行)
|
||||
from app.schemas.app_schema import FileInput
|
||||
|
||||
|
||||
# ---------- Input Schemas ----------
|
||||
|
||||
@@ -28,6 +31,7 @@ class ChatRequest(BaseModel):
|
||||
stream: bool = Field(default=False, description="是否流式返回")
|
||||
web_search: bool = Field(default=False, description="是否启用网络搜索")
|
||||
memory: bool = Field(default=True, description="是否启用记忆功能")
|
||||
files: Optional[List[FileInput]] = Field(default=None, description="附件列表(支持多文件)")
|
||||
|
||||
|
||||
# ---------- Output Schemas ----------
|
||||
|
||||
Reference in New Issue
Block a user