From 8d5da7a5cd111500efecf5de8aa4c41f0b4cb3fd Mon Sep 17 00:00:00 2001 From: lasseedfast Date: Mon, 7 Oct 2024 17:24:40 +0200 Subject: [PATCH] Refactor LLM class initialization and add note about default value of num_ctx parameter --- README.md | 4 +++- highlight_pdf.py | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9ef0161..9846843 100644 --- a/README.md +++ b/README.md @@ -167,11 +167,13 @@ A Streamlit example is provided in `example_streamlit_app.py` to demonstrate how #### Methods -- `__init__(self, openai_key=False, model=None, temperature=0, system_prompt=None, num_ctx=None, memory=True, keep_alive=3600)`: Initializes the LLM class with the provided parameters. +- `__init__(self, openai_key=False, model=None, temperature=0, system_prompt=None, num_ctx=None, memory=True, keep_alive=3600)`: Initializes the LLM class with the provided parameters. - `use_openai(self, key, model)`: Configures the class to use OpenAI for generating responses. - `use_ollama(self, model)`: Configures the class to use Ollama for generating responses. - `async generate(self, prompt)`: Asynchronously generates a response based on the provided prompt. +**Note:** The `num_ctx` parameter is set to 20000 by default, which may not be sufficient for all use cases. Adjust this value based on your specific requirements. + ## Contributing Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes. diff --git a/highlight_pdf.py b/highlight_pdf.py index 533550a..ea9dfaf 100644 --- a/highlight_pdf.py +++ b/highlight_pdf.py @@ -46,8 +46,8 @@ class LLM: Attributes: model (str): The model to be used for generating responses. + num_ctx (int): The number of context tokens to be used. Defaults to 20000. temperature (float): The temperature setting for the model's response generation. - num_ctx (int): The number of context tokens to be used. keep_alive (int): The keep-alive duration for the connection. options (dict): Options for the model's response generation. memory (bool): Whether to retain conversation history. @@ -70,11 +70,11 @@ class LLM: def __init__( self, + num_ctx=20000, openai_key=False, model=None, temperature=0, system_prompt=None, - num_ctx=None, memory=True, keep_alive=3600, ): @@ -86,7 +86,7 @@ class LLM: model (str, optional): The model to be used. Defaults to None. temperature (float, optional): Sampling temperature for the model. Defaults to 0. system_prompt (str, optional): Initial system prompt for the model. Defaults to None. - num_ctx (int, optional): Number of context tokens. Defaults to None. + context_window (int, optional): Number of context tokens. Defaults to None. memory (bool, optional): Whether to use memory. Defaults to True. keep_alive (int, optional): Keep-alive duration in seconds. Defaults to 3600. """ @@ -96,12 +96,9 @@ class LLM: else: self.model = os.getenv("LLM_MODEL") self.temperature = temperature - self.num_ctx = num_ctx self.keep_alive = keep_alive - self.options = {"temperature": self.temperature} + self.options = {"temperature": self.temperature, num_ctx: num_ctx} self.memory = memory - if self.num_ctx: - self.options["num_ctx"] = self.num_ctx if system_prompt: self.messages = [{"role": "system", "content": system_prompt}] else: