Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ SHOW_USAGE=True
TEMPERATURE=0
TOP_P=1
MAX_TOKENS=1000
MAX_CONTEXT_TOKENS=8192
MEMORY_KEEP_COUNT=10
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tests

on:
push:
pull_request:

permissions:
contents: read

jobs:
test:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- name: Check out repository
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install dependencies
run: python -m pip install -r requirements.txt

- name: Run tests
run: python -m unittest discover -v
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from openai import OpenAI, OpenAIError

from utils import get_required_config, read_input
from utils import calculate_input_token_budget, get_required_config, read_input


def trim_history(messages, keep_count):
Expand All @@ -26,6 +26,11 @@ def main():
temperature = get_required_config("TEMPERATURE", cast=float)
top_p = get_required_config("TOP_P", cast=float)
memory_keep_count = get_required_config("MEMORY_KEEP_COUNT", cast=int)
max_context_tokens = get_required_config(
"MAX_CONTEXT_TOKENS",
cast=int,
)
calculate_input_token_budget(max_context_tokens, max_tokens)

if memory_keep_count < 0:
raise ValueError("MEMORY_KEEP_COUNT must be 0 or greater")
Expand Down
16 changes: 15 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ def read_input(prompt):
return None


__all__ = ["get_required_config", "read_input"]
def calculate_input_token_budget(context_limit, output_limit):
"""Calculate how many tokens are available for input messages."""
if context_limit <= 0:
raise ValueError("MAX_CONTEXT_TOKENS must be greater than 0")

if output_limit <= 0:
raise ValueError("MAX_TOKENS must be greater than 0")

if output_limit >= context_limit:
raise ValueError("MAX_TOKENS must be smaller than MAX_CONTEXT_TOKENS")

return context_limit - output_limit


__all__ = ["calculate_input_token_budget", "get_required_config", "read_input"]