All-Hands-AI / OpenHands

🙌 OpenHands: Code Less, Make More
https://all-hands.dev
MIT License
37.61k stars 4.25k forks source link

Add option to reduce context window #5193

Open drbarq opened 1 week ago

drbarq commented 1 week ago

This PR adds functionality to allow users to set a lower context window than their LLMs maximum context window size. This is useful when the models performance degrades significantly with larger context windows, allowing users to optimize the tradeoff between context length and model performance.

Background

With PR #4977 being merged in version 0.14, we now support dynamic context window sizes. This PR builds on that by allowing users to manually set a lower context window size than their LLMs maximum, which can be beneficial in cases where:

Changes

Configuration

Users can set max_input_tokens in two ways:

  1. Through config.toml:

    [llm]
    max_input_tokens = 20000
  2. Through environment variables:

    export LLM_MAX_INPUT_TOKENS=20000

Implementation Details

Testing

Added new test case test_context_window_parameter_truncation that verifies:

This implements and enhances the changes from PR #5079.

enyst commented 1 week ago

Thank you for taking this up, @drbarq ! For the record, the reason for this PR "switch" is here.