2024-01-02 23:42:00 +08:00
|
|
|
from enum import Enum
|
2024-04-08 18:51:46 +08:00
|
|
|
from typing import Any, Optional
|
2024-02-06 13:21:13 +08:00
|
|
|
|
|
|
|
from pydantic import BaseModel
|
2024-01-02 23:42:00 +08:00
|
|
|
|
|
|
|
from core.model_runtime.entities.message_entities import PromptMessageRole
|
2024-04-08 18:51:46 +08:00
|
|
|
from models.model import AppMode
|
2024-01-02 23:42:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ModelConfigEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Model Config Entity.
|
|
|
|
"""
|
|
|
|
provider: str
|
|
|
|
model: str
|
2024-04-08 18:51:46 +08:00
|
|
|
mode: Optional[str] = None
|
2024-01-02 23:42:00 +08:00
|
|
|
parameters: dict[str, Any] = {}
|
|
|
|
stop: list[str] = []
|
|
|
|
|
|
|
|
|
|
|
|
class AdvancedChatMessageEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Advanced Chat Message Entity.
|
|
|
|
"""
|
|
|
|
text: str
|
|
|
|
role: PromptMessageRole
|
|
|
|
|
|
|
|
|
|
|
|
class AdvancedChatPromptTemplateEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Advanced Chat Prompt Template Entity.
|
|
|
|
"""
|
|
|
|
messages: list[AdvancedChatMessageEntity]
|
|
|
|
|
|
|
|
|
|
|
|
class AdvancedCompletionPromptTemplateEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Advanced Completion Prompt Template Entity.
|
|
|
|
"""
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
class RolePrefixEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Role Prefix Entity.
|
|
|
|
"""
|
|
|
|
user: str
|
|
|
|
assistant: str
|
|
|
|
|
|
|
|
prompt: str
|
|
|
|
role_prefix: Optional[RolePrefixEntity] = None
|
|
|
|
|
|
|
|
|
|
|
|
class PromptTemplateEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Prompt Template Entity.
|
|
|
|
"""
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
class PromptType(Enum):
|
|
|
|
"""
|
|
|
|
Prompt Type.
|
|
|
|
'simple', 'advanced'
|
|
|
|
"""
|
|
|
|
SIMPLE = 'simple'
|
|
|
|
ADVANCED = 'advanced'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def value_of(cls, value: str) -> 'PromptType':
|
|
|
|
"""
|
|
|
|
Get value of given mode.
|
|
|
|
|
|
|
|
:param value: mode value
|
|
|
|
:return: mode
|
|
|
|
"""
|
|
|
|
for mode in cls:
|
|
|
|
if mode.value == value:
|
|
|
|
return mode
|
|
|
|
raise ValueError(f'invalid prompt type value {value}')
|
|
|
|
|
|
|
|
prompt_type: PromptType
|
|
|
|
simple_prompt_template: Optional[str] = None
|
|
|
|
advanced_chat_prompt_template: Optional[AdvancedChatPromptTemplateEntity] = None
|
|
|
|
advanced_completion_prompt_template: Optional[AdvancedCompletionPromptTemplateEntity] = None
|
|
|
|
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class VariableEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Variable Entity.
|
|
|
|
"""
|
|
|
|
class Type(Enum):
|
|
|
|
TEXT_INPUT = 'text-input'
|
|
|
|
SELECT = 'select'
|
|
|
|
PARAGRAPH = 'paragraph'
|
|
|
|
NUMBER = 'number'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def value_of(cls, value: str) -> 'VariableEntity.Type':
|
|
|
|
"""
|
|
|
|
Get value of given mode.
|
|
|
|
|
|
|
|
:param value: mode value
|
|
|
|
:return: mode
|
|
|
|
"""
|
|
|
|
for mode in cls:
|
|
|
|
if mode.value == value:
|
|
|
|
return mode
|
|
|
|
raise ValueError(f'invalid variable type value {value}')
|
|
|
|
|
|
|
|
variable: str
|
|
|
|
label: str
|
|
|
|
description: Optional[str] = None
|
|
|
|
type: Type
|
|
|
|
required: bool = False
|
|
|
|
max_length: Optional[int] = None
|
|
|
|
options: Optional[list[str]] = None
|
|
|
|
default: Optional[str] = None
|
|
|
|
hint: Optional[str] = None
|
|
|
|
|
2024-07-02 18:58:07 +08:00
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
|
|
|
return self.variable
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
class ExternalDataVariableEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
External Data Variable Entity.
|
|
|
|
"""
|
|
|
|
variable: str
|
|
|
|
type: str
|
|
|
|
config: dict[str, Any] = {}
|
|
|
|
|
|
|
|
|
|
|
|
class DatasetRetrieveConfigEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Dataset Retrieve Config Entity.
|
|
|
|
"""
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
class RetrieveStrategy(Enum):
|
|
|
|
"""
|
|
|
|
Dataset Retrieve Strategy.
|
|
|
|
'single' or 'multiple'
|
|
|
|
"""
|
|
|
|
SINGLE = 'single'
|
|
|
|
MULTIPLE = 'multiple'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def value_of(cls, value: str) -> 'RetrieveStrategy':
|
|
|
|
"""
|
|
|
|
Get value of given mode.
|
|
|
|
|
|
|
|
:param value: mode value
|
|
|
|
:return: mode
|
|
|
|
"""
|
|
|
|
for mode in cls:
|
|
|
|
if mode.value == value:
|
|
|
|
return mode
|
|
|
|
raise ValueError(f'invalid retrieve strategy value {value}')
|
|
|
|
|
|
|
|
query_variable: Optional[str] = None # Only when app mode is completion
|
|
|
|
|
|
|
|
retrieve_strategy: RetrieveStrategy
|
|
|
|
top_k: Optional[int] = None
|
|
|
|
score_threshold: Optional[float] = None
|
2024-07-24 12:50:11 +08:00
|
|
|
rerank_mode: Optional[str] = 'reranking_model'
|
2024-01-02 23:42:00 +08:00
|
|
|
reranking_model: Optional[dict] = None
|
2024-07-24 12:50:11 +08:00
|
|
|
weights: Optional[dict] = None
|
|
|
|
|
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
class DatasetEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Dataset Config Entity.
|
|
|
|
"""
|
|
|
|
dataset_ids: list[str]
|
|
|
|
retrieve_config: DatasetRetrieveConfigEntity
|
|
|
|
|
|
|
|
|
|
|
|
class SensitiveWordAvoidanceEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Sensitive Word Avoidance Entity.
|
|
|
|
"""
|
|
|
|
type: str
|
|
|
|
config: dict[str, Any] = {}
|
|
|
|
|
|
|
|
|
2024-02-15 22:41:18 +08:00
|
|
|
class TextToSpeechEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Sensitive Word Avoidance Entity.
|
|
|
|
"""
|
|
|
|
enabled: bool
|
|
|
|
voice: Optional[str] = None
|
|
|
|
language: Optional[str] = None
|
|
|
|
|
|
|
|
|
2024-06-26 17:33:29 +08:00
|
|
|
class TracingConfigEntity(BaseModel):
|
|
|
|
"""
|
|
|
|
Tracing Config Entity.
|
|
|
|
"""
|
|
|
|
enabled: bool
|
|
|
|
tracing_provider: str
|
|
|
|
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class FileExtraConfig(BaseModel):
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
|
|
|
File Upload Entity.
|
|
|
|
"""
|
|
|
|
image_config: Optional[dict[str, Any]] = None
|
|
|
|
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class AppAdditionalFeatures(BaseModel):
|
|
|
|
file_upload: Optional[FileExtraConfig] = None
|
|
|
|
opening_statement: Optional[str] = None
|
|
|
|
suggested_questions: list[str] = []
|
|
|
|
suggested_questions_after_answer: bool = False
|
|
|
|
show_retrieve_source: bool = False
|
|
|
|
more_like_this: bool = False
|
|
|
|
speech_to_text: bool = False
|
|
|
|
text_to_speech: Optional[TextToSpeechEntity] = None
|
2024-06-26 17:33:29 +08:00
|
|
|
trace_config: Optional[TracingConfigEntity] = None
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class AppConfig(BaseModel):
|
2024-01-23 19:58:23 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
Application Config Entity.
|
2024-01-23 19:58:23 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
tenant_id: str
|
|
|
|
app_id: str
|
|
|
|
app_mode: AppMode
|
|
|
|
additional_features: AppAdditionalFeatures
|
|
|
|
variables: list[VariableEntity] = []
|
|
|
|
sensitive_word_avoidance: Optional[SensitiveWordAvoidanceEntity] = None
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class EasyUIBasedAppModelConfigFrom(Enum):
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
App Model Config From.
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
ARGS = 'args'
|
|
|
|
APP_LATEST_CONFIG = 'app-latest-config'
|
|
|
|
CONVERSATION_SPECIFIC_CONFIG = 'conversation-specific-config'
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class EasyUIBasedAppConfig(AppConfig):
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
Easy UI Based App Config Entity.
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
app_model_config_from: EasyUIBasedAppModelConfigFrom
|
|
|
|
app_model_config_id: str
|
|
|
|
app_model_config_dict: dict
|
|
|
|
model: ModelConfigEntity
|
2024-01-02 23:42:00 +08:00
|
|
|
prompt_template: PromptTemplateEntity
|
|
|
|
dataset: Optional[DatasetEntity] = None
|
2024-04-08 18:51:46 +08:00
|
|
|
external_data_variables: list[ExternalDataVariableEntity] = []
|
2024-01-02 23:42:00 +08:00
|
|
|
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
class WorkflowUIBasedAppConfig(AppConfig):
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
2024-04-08 18:51:46 +08:00
|
|
|
Workflow UI Based App Config Entity.
|
2024-01-02 23:42:00 +08:00
|
|
|
"""
|
2024-05-27 22:01:11 +08:00
|
|
|
workflow_id: str
|