From 82a524ebf145e389be5e280c69b1464e3ba7fd5b Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Sun, 2 Jun 2024 12:57:10 +0200 Subject: [PATCH] config docs --- docs/config.md | 37 +++++++++++++++++++++++++++++++++++++ docs/index.md | 1 + src/banks/config.py | 5 +++-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 docs/config.md diff --git a/docs/config.md b/docs/config.md new file mode 100644 index 0000000..1a2609a --- /dev/null +++ b/docs/config.md @@ -0,0 +1,37 @@ +## Configuration + +Banks can smoothly run with defaults, but you can configure the library by changing the `config` object or by +setting the correspondent environment variables. + +Example usage: + +```python +from banks import config + + +config.ASYNC_ENABLED = True +``` + + +### ASYNC_ENABLED + +| | | +| -------------- | ----------------------- | +| Type: | `bool` or truthy string | +| Default value: | `False` | +| Env var: | `BANKS_ASYNC_ENABLED` | + +Whether or not to use `asyncio` for template rendering and LLM generation. This setting won't speed up your +application, only set it to `True` if you need to integrate Banks into an async codebase. + + +### USER_DATA_PATH + +| | | +| -------------- | ---------------------- | +| Type: | `Path` or path string | +| Default value: | depending on OS | +| Env var: | `BANKS_USER_DATA_PATH` | + +A user-writable folder where Banks will store its data. Banks uses a meaningful default for your operating system, so +change it only if you have to. diff --git a/docs/index.md b/docs/index.md index cded458..6b8c956 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,6 +14,7 @@ are replaced by actual data provided by the user. * [Filters](prompt.md#filters): useful to manipulate the text during template rendering. * [Extensions](prompt.md#extensions): useful to support custom functions (e.g. text generation via OpenAI). * [Macros](prompt.md#macros): useful to implement complex logic in the template itself instead of Python code. +* [Configuration](config.md): how to configure the library. ## Installation diff --git a/src/banks/config.py b/src/banks/config.py index faf196e..7fe5e83 100644 --- a/src/banks/config.py +++ b/src/banks/config.py @@ -1,4 +1,5 @@ import os +from pathlib import Path from platformdirs import user_data_path @@ -6,8 +7,8 @@ class BanksConfig: - ASYNC_ENABLED = strtobool(os.environ.get("BANKS_ASYNC_ENABLED", "false")) - USER_DATA_PATH = user_data_path(os.environ.get("BANKS_USER_DATA_PATH", "banks")) + ASYNC_ENABLED: bool = strtobool(os.environ.get("BANKS_ASYNC_ENABLED", "false")) + USER_DATA_PATH: Path = Path(os.environ.get("BANKS_USER_DATA_PATH", "")) or user_data_path("banks") config = BanksConfig()