init.py
Overview
This init.py file serves as a centralized module for defining various enumerations and constants used throughout the InfiniFlow application. It primarily defines strongly-typed enumerations (using Python's Enum, IntEnum, and StrEnum) that represent fixed sets of categorical values related to system statuses, user roles, file types, task statuses, parsing types, and other domain-specific classifications.
By collecting these enums and constants in one module, the file promotes consistency and maintainability across the codebase when dealing with these fixed categories. This file does not contain executable logic or functions but provides essential building blocks used by other components of the system.
Detailed Explanations
Imported Modules
EnumandIntEnumfrom Python's standardenummodule: Used for creating enumerations with symbolic names bound to constant values.StrEnumfrom the third-party strenum module: Used to create enumerations where members are also subclasses ofstr, allowing enum members to behave like strings.
Classes (Enumerations)
StatusEnum (Enum)
Represents a generic validation status with two possible states.
Member | Value | Description |
|---|---|---|
|
| Indicates a valid state |
|
| Indicates an invalid state |
Usage example:
if status == StatusEnum.VALID:
print("Status is valid.")
UserTenantRole (StrEnum)
Defines the role of a user within a tenant or organization.
Member | Value | Description |
|---|---|---|
|
| User with owner privileges |
|
| Administrator user |
|
| Regular user |
|
| Invited user (pending status) |
TenantPermission (StrEnum)
Represents permission scopes for tenants.
Member | Value | Description |
|---|---|---|
|
| Permission for self |
|
| Permission for team |
SerializedType (IntEnum)
Specifies serialization formats supported by the system.
Member | Value | Description |
|---|---|---|
| 1 | Python pickle format |
| 2 | JSON format |
FileType (StrEnum)
Enumerates supported file types within the system.
Member | Value | Description |
|---|---|---|
|
| PDF documents |
|
| Document files (e.g., Word) |
|
| Visual media files (images, diagrams) |
|
| Audio files |
|
| Virtual files (system-specific) |
|
| Folder type (container) |
|
| Other/unspecified file types |
Constant:
VALID_FILE_TYPES: A set of all validFileTypemembers for easy validation.
LLMType (StrEnum)
Specifies different Large Language Model (LLM) task types or interfaces.
Member | Value | Description |
|---|---|---|
|
| Chat-based LLM interaction |
|
| Embedding generation |
|
| Speech to text transcription |
|
| Image to text conversion |
|
| Ranking or reranking tasks |
|
| Text to speech synthesis |
ChatStyle (StrEnum)
Defines stylistic modes for chat interactions.
Member | Value | Description |
|---|---|---|
|
| Creative style responses |
|
| Precise and concise answers |
|
| Balanced style |
|
| Custom user-defined style |
TaskStatus (StrEnum)
Represents the lifecycle states of an asynchronous or background task.
Member | Value | Description |
|---|---|---|
|
| Task not started |
|
| Task currently running |
|
| Task was cancelled |
|
| Task completed successfully |
|
| Task failed |
Constant:
VALID_TASK_STATUS: Set of all validTaskStatusvalues.
ParserType (StrEnum)
Defines types of document or content parsers supported.
Member | Value | Description |
|---|---|---|
|
| Presentation documents |
|
| Legal documents |
|
| Manuals and guides |
|
| Academic papers |
|
| Resume documents |
|
| Books |
|
| Question-Answer pairs |
|
| Tabular data |
|
| Naive/simple parsing |
|
| Image-based parsing |
|
| Single-page parsing |
|
| Audio transcription parsing |
|
| Email content |
|
| Knowledge graph parsing |
|
| Tagging content |
FileSource (StrEnum)
Indicates the origin or storage location of files.
Member | Value | Description |
|---|---|---|
|
| Local file system |
|
| Files stored in KB |
|
| Amazon S3 cloud storage |
CanvasType (StrEnum)
Specifies the type of canvas or UI component used in the system.
Member | Value | Description |
|---|---|---|
|
| Interactive chat interface |
|
| Document processing interface |
CanvasCategory (StrEnum)
Categorizes canvas types by their functional domain.
Member | Value | Description |
|---|---|---|
|
| Canvas for agent-related tasks |
|
| Canvas for dataflow visualization |
Constant:
VALID_CAVAS_CATEGORIES: Set of valid canvas categories.
MCPServerType (StrEnum)
Defines types of server protocols used for message connection protocols (MCP).
Member | Value | Description |
|---|---|---|
|
| Server-Sent Events protocol |
|
| HTTP streaming protocol |
Constant:
VALID_MCP_SERVER_TYPES: Set of valid MCP server types.
Constants
VALID_FILE_TYPES: Set containing all validFileTypeenum members.VALID_TASK_STATUS: Set containing all validTaskStatusenum members.VALID_CAVAS_CATEGORIES: Set containing all validCanvasCategoryenum members.VALID_MCP_SERVER_TYPES: Set containing all validMCPServerTypeenum members.KNOWLEDGEBASE_FOLDER_NAME: String constant".knowledgebase"representing the folder name used for knowledgebase storage.
Important Implementation Details
Use of
StrEnum: Many enumerations inherit fromStrEnum, which means enum members behave like strings. This facilitates seamless integration with configurations, JSON serialization, and easy comparison with string values without explicit casting.Type Safety and Readability: Using enumerations rather than plain strings or integers improves code readability, reduces errors due to typos, and facilitates IDE support (e.g., auto-completion).
Grouping of Related Constants: Each enum groups related constants logically, enabling modular and maintainable code.
Sets of Valid Values: The module defines sets of valid enum members for quick membership checks and validation.
Interactions with Other System Components
Role and Permission Management:
UserTenantRoleandTenantPermissionenums are likely used by authentication, authorization, and tenant management modules to enforce access controls.File Handling and Parsing:
FileType,FileSource, andParserTypeenums are probably referenced in file management, document processing, and parsing components to determine how files are handled or parsed.Task Management:
TaskStatusenum is essential for tracking and managing asynchronous task states across task scheduler or worker components.LLM Integration:
LLMTypeandChatStylesupport the configuration of different large language model interactions, affecting chatbot or AI services.Canvas and UI Components:
CanvasTypeandCanvasCategoryrelate to front-end or visualization modules defining UI canvas behavior or categorization.Streaming and Communication:
MCPServerTypesupports communication protocols for event streaming or HTTP streaming within real-time features.
This file acts as a foundational enumeration module that other parts of the InfiniFlow application import to maintain consistency in handling fixed categories and states.
Usage Examples
from __init__ import UserTenantRole, TaskStatus, FileType
# Check user role
def is_admin(user_role):
return user_role == UserTenantRole.ADMIN
# Validate file type
def is_valid_file_type(file_type):
return file_type in VALID_FILE_TYPES
# Track task progress
def update_task_status(task, status):
if status in VALID_TASK_STATUS:
task.status = status
Mermaid Class Diagram
classDiagram
class StatusEnum {
<<Enum>>
+VALID: str
+INVALID: str
}
class UserTenantRole {
<<StrEnum>>
+OWNER: str
+ADMIN: str
+NORMAL: str
+INVITE: str
}
class TenantPermission {
<<StrEnum>>
+ME: str
+TEAM: str
}
class SerializedType {
<<IntEnum>>
+PICKLE: int
+JSON: int
}
class FileType {
<<StrEnum>>
+PDF: str
+DOC: str
+VISUAL: str
+AURAL: str
+VIRTUAL: str
+FOLDER: str
+OTHER: str
}
class LLMType {
<<StrEnum>>
+CHAT: str
+EMBEDDING: str
+SPEECH2TEXT: str
+IMAGE2TEXT: str
+RERANK: str
+TTS: str
}
class ChatStyle {
<<StrEnum>>
+CREATIVE: str
+PRECISE: str
+EVENLY: str
+CUSTOM: str
}
class TaskStatus {
<<StrEnum>>
+UNSTART: str
+RUNNING: str
+CANCEL: str
+DONE: str
+FAIL: str
}
class ParserType {
<<StrEnum>>
+PRESENTATION: str
+LAWS: str
+MANUAL: str
+PAPER: str
+RESUME: str
+BOOK: str
+QA: str
+TABLE: str
+NAIVE: str
+PICTURE: str
+ONE: str
+AUDIO: str
+EMAIL: str
+KG: str
+TAG: str
}
class FileSource {
<<StrEnum>>
+LOCAL: str
+KNOWLEDGEBASE: str
+S3: str
}
class CanvasType {
<<StrEnum>>
+ChatBot: str
+DocBot: str
}
class CanvasCategory {
<<StrEnum>>
+Agent: str
+DataFlow: str
}
class MCPServerType {
<<StrEnum>>
+SSE: str
+STREAMABLE_HTTP: str
}
Summary
The init.py module is a foundational configuration file defining all the key enumerations and constants that represent core categorical data used throughout the InfiniFlow project. It ensures data consistency, reduces errors, and improves code clarity by leveraging typed enumerations for roles, file types, statuses, and more, thereby supporting multiple system components ranging from authentication and file management to AI integrations and UI canvas management.