configs.py
Overview
The configs.py file serves as a centralized configuration module for the InfiniFlow application. It provides essential constants and environment-dependent variables that are used throughout the system. This includes host addresses, API keys, user credentials (in an encrypted or encoded form), and limits for various entity names within the application.
The main purpose of this file is to:
Load critical configuration parameters from environment variables.
Define default values and constraints for system components.
Ensure mandatory environment variables are present, exiting tests early if not.
Provide a single source of truth for configuration values used by other modules.
This file is primarily a utility module and does not contain classes or functions but exposes constants and performs validation at import time.
Detailed Explanation
Constants and Variables
Name | Type | Description |
|---|---|---|
| str | The base URL for the host server. Defaults to |
| str | API version string used in requests, fixed as |
| str | API key loaded from environment; mandatory for operation. Exits test suite if not set. |
| str | Default user email for authentication or testing purposes. |
| str | Encrypted or encoded password string corresponding to the |
str | A dummy API token string used for testing invalid authentication scenarios. | |
| int | Maximum allowed length (128 chars) for dataset names in the system. |
int | Maximum allowed length (255 chars) for document names. | |
int | Maximum allowed length (255 chars) for chat assistant names. | |
int | Maximum allowed length (255 chars) for session names involving chats. |
Environment Variable Dependency and Validation
The module attempts to read
ZHIPU_AI_API_KEYfrom the environment.If this key is not set, the module calls
pytest.exit()immediately, stopping any test executions and signaling the missing configuration.
This ensures that the system does not run tests or operations without proper API credentials.
ZHIPU_AI_API_KEY = os.getenv("ZHIPU_AI_API_KEY")
if ZHIPU_AI_API_KEY is None:
pytest.exit("Error: Environment variable ZHIPU_AI_API_KEY must be set")
Usage Examples
Since this file only exposes constants, usage is straightforward:
import configs
print("Connecting to host:", configs.HOST_ADDRESS)
print("Using API version:", configs.VERSION)
print("Dataset name max length:", configs.DATASET_NAME_LIMIT)
api_key = configs.ZHIPU_AI_API_KEY # must be set in environment before import
Implementation Details
Uses Python's built-in
os.getenv()to fetch environment variables safely, providing a default forHOST_ADDRESS.Uses
pytest.exit()to abort testing if a required API key is missing, which integrates tightly with the testing framework.Stores a base64 or similarly encoded password string (not plaintext) to avoid exposing sensitive data directly.
Defines explicit limits for naming conventions, likely to be referenced in validation logic elsewhere in the application.
Interaction with Other Parts of the System
Testing Framework: The use of
pytest.exit()indicates this file is imported before or during test execution to ensure environment readiness.Authentication/Authorization Modules:
EMAILandPASSWORDconstants are probably used for automated login or API authentication in test scenarios.API Requests:
HOST_ADDRESS,VERSION, andZHIPU_AI_API_KEYare essential for constructing requests to the backend services.Validation Logic: The naming limits are constraints that other modules (e.g., dataset management, document handling, chat session management) rely on to validate user inputs or data fields.
Mermaid Diagram
This file is a utility configuration module with no classes or functions. The diagram below illustrates the flow of configuration loading and validation:
flowchart TD
A[Start: Import configs.py] --> B{Load HOST_ADDRESS}
B --> C[Set default if env not set]
A --> D{Load ZHIPU_AI_API_KEY}
D -->|Exists| E[Store API key]
D -->|Not set| F[Call pytest.exit()]
E --> G[Set EMAIL and PASSWORD]
G --> H[Set name length limits]
H --> I[Configuration ready for use]
F --> J[Abort test execution]
Summary
configs.py is a critical configuration module that ensures environment variables and constants are correctly set up before the InfiniFlow system or its tests run. It acts as a gatekeeper for required API keys and centralizes configuration constants, making the system easier to maintain and less error-prone.
By failing fast when key variables are missing and providing explicit constraints for entity naming, it supports robustness and consistent behavior across the application.