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:

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

HOST_ADDRESS

str

The base URL for the host server. Defaults to "http://127.0.0.1:9380" if not set in env.

VERSION

str

API version string used in requests, fixed as "v1".

ZHIPU_AI_API_KEY

str

API key loaded from environment; mandatory for operation. Exits test suite if not set.

EMAIL

str

Default user email for authentication or testing purposes.

PASSWORD

str

Encrypted or encoded password string corresponding to the EMAIL.

INVALID_API_TOKEN

str

A dummy API token string used for testing invalid authentication scenarios.

DATASET_NAME_LIMIT

int

Maximum allowed length (128 chars) for dataset names in the system.

DOCUMENT_NAME_LIMIT

int

Maximum allowed length (255 chars) for document names.

CHAT_ASSISTANT_NAME_LIMIT

int

Maximum allowed length (255 chars) for chat assistant names.

SESSION_WITH_CHAT_NAME_LIMIT

int

Maximum allowed length (255 chars) for session names involving chats.


Environment Variable Dependency and Validation

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


Interaction with Other Parts of the System


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.