From 7b81c8a6901f65fe6076fd4d4ca6e6b4ff488859 Mon Sep 17 00:00:00 2001 From: seehi <6580@pm.me> Date: Mon, 28 Oct 2024 21:12:09 +0800 Subject: [PATCH] make context length configurable --- metagpt/configs/llm_config.py | 1 + metagpt/rag/factories/llm.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/metagpt/configs/llm_config.py b/metagpt/configs/llm_config.py index 60118303c..0d4561a7a 100644 --- a/metagpt/configs/llm_config.py +++ b/metagpt/configs/llm_config.py @@ -83,6 +83,7 @@ class LLMConfig(YamlModel): logprobs: Optional[bool] = None top_logprobs: Optional[int] = None timeout: int = 600 + context_length: Optional[int] = None # Max input tokens # For Amazon Bedrock region_name: str = None diff --git a/metagpt/rag/factories/llm.py b/metagpt/rag/factories/llm.py index 9fd19cab5..c1069cc6c 100644 --- a/metagpt/rag/factories/llm.py +++ b/metagpt/rag/factories/llm.py @@ -23,10 +23,12 @@ class RAGLLM(CustomLLM): """LlamaIndex's LLM is different from MetaGPT's LLM. Inherit CustomLLM from llamaindex, making MetaGPT's LLM can be used by LlamaIndex. + + Set context_length or max_token of LLM in config.yaml if you encounter "Calculated available context size -xxx was not non-negative" error. """ model_infer: BaseLLM = Field(..., description="The MetaGPT's LLM.") - context_window: int = TOKEN_MAX.get(config.llm.model, DEFAULT_CONTEXT_WINDOW) + context_window: int = config.llm.context_length or TOKEN_MAX.get(config.llm.model, DEFAULT_CONTEXT_WINDOW) num_output: int = config.llm.max_token model_name: str = config.llm.model