Add analysis feature
This commit is contained in:
@@ -90,6 +90,45 @@ class KnowledgeRetrievalConfig(CamelModel):
|
||||
return value
|
||||
|
||||
|
||||
class AnalysisField(CamelModel):
|
||||
id: str = Field(min_length=1, max_length=64)
|
||||
name: str = Field(pattern=r"^[A-Za-z][A-Za-z0-9_]{0,63}$")
|
||||
type: Literal["string", "boolean", "integer", "number", "enum"] = "string"
|
||||
description: str = Field(default="", max_length=500)
|
||||
enum_values: list[str] = Field(default_factory=list, max_length=30)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_enum_values(self):
|
||||
normalized = list(
|
||||
dict.fromkeys(
|
||||
value.strip() for value in self.enum_values if value.strip()
|
||||
)
|
||||
)
|
||||
if self.type == "enum" and not normalized:
|
||||
raise ValueError("enum 字段必须至少配置一个枚举值")
|
||||
self.enum_values = normalized if self.type == "enum" else []
|
||||
return self
|
||||
|
||||
|
||||
class AnalysisConfig(CamelModel):
|
||||
enabled: bool = False
|
||||
model_resource_id: str = ""
|
||||
fields: list[AnalysisField] = Field(default_factory=list, max_length=20)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_enabled_config(self):
|
||||
if not self.enabled:
|
||||
return self
|
||||
if not self.model_resource_id:
|
||||
raise ValueError("开启通话后分析时必须选择分析模型")
|
||||
if not self.fields:
|
||||
raise ValueError("开启通话后分析时必须配置至少一个关键信息字段")
|
||||
names = [field.name for field in self.fields]
|
||||
if len(names) != len(set(names)):
|
||||
raise ValueError("关键信息字段名不能重复")
|
||||
return self
|
||||
|
||||
|
||||
# 各 type 允许的瘦字段(其余字段写入时清零,防止跨类型脏数据)
|
||||
ALLOWED_FIELDS: dict[str, set[str]] = {
|
||||
"prompt": {"prompt"},
|
||||
@@ -171,6 +210,7 @@ class AssistantUpsert(CamelModel):
|
||||
dynamic_variable_definitions: dict[str, "DynamicVariableDefinition"] = Field(
|
||||
default_factory=dict
|
||||
)
|
||||
analysis_config: AnalysisConfig = Field(default_factory=AnalysisConfig)
|
||||
api_url: str = ""
|
||||
api_key: str = "" # 写时:占位符/空 → 保留旧(哨兵)
|
||||
app_id: str = ""
|
||||
@@ -500,9 +540,25 @@ class ConversationOut(CamelModel):
|
||||
ended_at: datetime | None
|
||||
|
||||
|
||||
class ConversationAnalysisFieldOut(CamelModel):
|
||||
name: str
|
||||
type: str
|
||||
value: Any = None
|
||||
|
||||
|
||||
class ConversationAnalysisOut(CamelModel):
|
||||
status: Literal[
|
||||
"none", "pending", "processing", "completed", "failed"
|
||||
] = "none"
|
||||
fields: list[ConversationAnalysisFieldOut] = Field(default_factory=list)
|
||||
error: str = ""
|
||||
completed_at: datetime | None = None
|
||||
|
||||
|
||||
class ConversationDetailOut(ConversationOut):
|
||||
extra: dict[str, Any] = Field(default_factory=dict)
|
||||
messages: list[ConversationMessageOut] = Field(default_factory=list)
|
||||
analysis: ConversationAnalysisOut = Field(default_factory=ConversationAnalysisOut)
|
||||
|
||||
|
||||
class ConversationListOut(CamelModel):
|
||||
|
||||
Reference in New Issue
Block a user