The config.py
file serves as the central configuration hub for the Ollama_Agents project. It uses environment variables and the pathlib
library to manage settings and paths, providing flexibility and portability across different environments.
The configuration uses os.getenv()
to read environment variables, allowing for easy customization without modifying the code. For example:
USER_NAME = os.getenv("AI_USER_NAME", "MikeBee")
This line sets USER_NAME
to the value of the AI_USER_NAME
environment variable if it exists, otherwise defaulting to "MikeBee".
The pathlib
library is used for cross-platform path handling. For example:
PROJECT_ROOT = Path(__file__).parent.parent
DATA_DIR = PROJECT_ROOT / "data" / "json_history"
This creates platform-independent paths, ensuring consistency across different operating systems.
USER_NAME
: Name of the user interacting with the systemAGENT_NAME
: Name of the AI agent
DEFAULT_MODEL
: Specifies the default language modelEMBEDDING_MODEL
: Specifies the model used for generating embeddings
MEMORY_LENGTH
: Number of interactions to keep in short-term memoryCHUNK_SIZE
: Size of text chunks for processingCHUNK_OVERLAP
: Overlap between chunks to maintain contextCHUNK_LENGTH
: Number of chunks to keep in memory
PROJECT_ROOT
: Root directory of the projectDATA_DIR
: Directory for storing JSON history filesEMBEDDINGS_DIR
: Directory for storing embedding filesCHAT_HISTORY_FILE
: Path to the chat history file
DEFAULT_TOP_K
: Number of top results to return in memory searchDEFAULT_SIMILARITY_THRESHOLD
: Minimum similarity score for search results
LOG_LEVEL
: Sets the logging levelLOG_FILE
: Path to the log file
The configuration file ensures that necessary directories exist:
DATA_DIR.mkdir(parents=True, exist_ok=True)
EMBEDDINGS_DIR.mkdir(parents=True, exist_ok=True)
This automatically creates the required directories if they don't exist.
To use these configurations in other parts of the project, simply import the required variables:
from config import USER_NAME, DEFAULT_MODEL, DATA_DIR
To customize the configuration:
- Set environment variables before running the application, or
- Modify the default values in the
config.py
file
For example, to change the user name:
export AI_USER_NAME="JohnDoe"
Or in the config.py
file:
USER_NAME = os.getenv("AI_USER_NAME", "JohnDoe")
- Use environment variables for sensitive or frequently changing values
- Keep the
config.py
file under version control, but don't commit sensitive information - Use
.env
files for local development and CI/CD pipelines for production environments