From 9cc490220edcef2d855db94fb4533b9ffd54fd6c Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 21 Oct 2023 02:49:15 -0400 Subject: [PATCH 1/2] chore: update pre-commit hook versions and replace darglint with pydoclint This commit updates the versions of pre-commit hooks for pre-commit-hooks, black, and ruff-pre-commit. It also replaces the darglint hook with pydoclint for better documentation linting. --- .pre-commit-config.yaml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 336388ce3..a4c6621d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,12 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 23.9.0 + rev: 23.10.0 hooks: - id: black - repo: https://github.com/kynan/nbstripout @@ -18,14 +18,15 @@ repos: hooks: - id: interrogate args: [-c, pyproject.toml] - - repo: https://github.com/terrencepreilly/darglint - rev: v1.8.1 + - repo: https://github.com/jsh9/pydoclint + rev: 0.3.8 hooks: - - id: darglint - args: [-v 2] # this config makes the error messages a bit less cryptic. + - id: pydoclint + args: + - "--config=pyproject.toml" - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.0.287 + rev: v0.1.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From eaabf620077aebfc1adef7da84007000a4dd255d Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 21 Oct 2023 02:53:58 -0400 Subject: [PATCH 2/2] refactor: move docstrings from __init__ to class level This commit moves the docstrings from the __init__ methods to the class level for the ChatBot, QueryBot, and SimpleBot classes in the llamabot/bot directory. This change improves the readability of the code and makes the documentation more accessible. The PromptRecorder and PaperTitleCompleter classes also had minor docstring adjustments. This commit satisfies pydoclint. --- llamabot/bot/chatbot.py | 24 +++++++--------- llamabot/bot/querybot.py | 56 +++++++++++++++++------------------- llamabot/bot/simplebot.py | 18 ++++++------ llamabot/recorder.py | 1 - llamabot/zotero/completer.py | 8 ++---- 5 files changed, 49 insertions(+), 58 deletions(-) diff --git a/llamabot/bot/chatbot.py b/llamabot/bot/chatbot.py index f81d2393d..6323fcba9 100644 --- a/llamabot/bot/chatbot.py +++ b/llamabot/bot/chatbot.py @@ -22,6 +22,17 @@ class ChatBot: Automatic chat memory management happens. h/t Andrew Giessel/GPT4 for the idea. + + :param system_prompt: The system prompt to use. + :param temperature: The model temperature to use. + See https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature + for more information. + :param model_name: The name of the OpenAI model to use. + :param logging: Whether to log the chat history. + :param streaming: (LangChain config) Whether to stream the output to stdout. + :param verbose: (LangChain config) Whether to print debug messages. + :param response_budget: (LangChain config) The maximum number of tokens + to use for the response. """ def __init__( @@ -34,19 +45,6 @@ def __init__( verbose=True, response_budget=2_000, ): - """Initialize the ChatBot. - - :param system_prompt: The system prompt to use. - :param temperature: The model temperature to use. - See https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature - for more information. - :param model_name: The name of the OpenAI model to use. - :param logging: Whether to log the chat history. - :param streaming: (LangChain config) Whether to stream the output to stdout. - :param verbose: (LangChain config) Whether to print debug messages. - :param response_budget: (LangChain config) The maximum number of tokens - to use for the response. - """ self.model = create_model( model_name=model_name, temperature=temperature, diff --git a/llamabot/bot/querybot.py b/llamabot/bot/querybot.py index 11bb6729c..452afb57e 100644 --- a/llamabot/bot/querybot.py +++ b/llamabot/bot/querybot.py @@ -55,7 +55,33 @@ class QueryBot: - """QueryBot is a bot that lets us use GPT4 to query documents.""" + """QueryBot is a bot that lets us use GPT4 to query documents. + + Pass in either the doc_path or saved_index_path to initialize the QueryBot. + + NOTE: QueryBot is not designed to have memory! + + The default text splitter is the TokenTextSplitter from LangChain. + The default index that we use is the GPTVectorStoreIndex from LlamaIndex. + We also default to using GPT4 with temperature 0.0. + + :param system_message: The system message to send to the chatbot. + :param model_name: The name of the OpenAI model to use. + :param temperature: The model temperature to use. + See https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature + for more information. + :param doc_paths: A path to a document, + or a list of paths to multiple documents, + to use for the chatbot. + :param saved_index_path: The path to the saved index to use for the chatbot. + :param response_tokens: The number of tokens to use for responses. + :param history_tokens: The number of tokens to use for history. + :param chunk_sizes: The chunk sizes to use for the LlamaIndex TokenTextSplitter. + Defaults to [2000], but can be a list of integers. + :param streaming: Whether to stream the chatbot or not. + :param verbose: (LangChain config) Whether to print debug messages. + :param use_cache: Whether to use the cache or not. + """ def __init__( self, @@ -71,34 +97,6 @@ def __init__( verbose: bool = True, use_cache: bool = True, ): - """Initialize QueryBot. - - Pass in either the doc_path or saved_index_path to initialize the QueryBot. - - NOTE: QueryBot is not designed to have memory! - - The default text splitter is the TokenTextSplitter from LangChain. - The default index that we use is the GPTVectorStoreIndex from LlamaIndex. - We also default to using GPT4 with temperature 0.0. - - :param system_message: The system message to send to the chatbot. - :param model_name: The name of the OpenAI model to use. - :param temperature: The model temperature to use. - See https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature - for more information. - :param doc_paths: A path to a document, - or a list of paths to multiple documents, - to use for the chatbot. - :param saved_index_path: The path to the saved index to use for the chatbot. - :param response_tokens: The number of tokens to use for responses. - :param history_tokens: The number of tokens to use for history. - :param chunk_sizes: The chunk sizes to use for the LlamaIndex TokenTextSplitter. - Defaults to [2000], but can be a list of integers. - :param streaming: Whether to stream the chatbot or not. - :param verbose: (LangChain config) Whether to print debug messages. - :param use_cache: Whether to use the cache or not. - """ - chat = create_model( model_name=model_name, temperature=temperature, diff --git a/llamabot/bot/simplebot.py b/llamabot/bot/simplebot.py index c36a86f3e..83ba21571 100644 --- a/llamabot/bot/simplebot.py +++ b/llamabot/bot/simplebot.py @@ -18,6 +18,14 @@ class SimpleBot: and sends back a single response. This bot does not retain chat history. + + :param system_prompt: The system prompt to use. + :param temperature: The model temperature to use. + See https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature + for more information. + :param model_name: The name of the OpenAI model to use. + :param streaming: (LangChain config) Whether to stream the output to stdout. + :param verbose: (LangChain config) Whether to print debug messages. """ def __init__( @@ -28,16 +36,6 @@ def __init__( streaming=True, verbose=True, ): - """Initialize the SimpleBot. - - :param system_prompt: The system prompt to use. - :param temperature: The model temperature to use. - See https://platform.openai.com/docs/api-reference/completions/create#completions/create-temperature - for more information. - :param model_name: The name of the OpenAI model to use. - :param streaming: (LangChain config) Whether to stream the output to stdout. - :param verbose: (LangChain config) Whether to print debug messages. - """ self.system_prompt = system_prompt self.model = create_model( model_name=model_name, diff --git a/llamabot/recorder.py b/llamabot/recorder.py index 53c9a026f..30d2e6f9b 100644 --- a/llamabot/recorder.py +++ b/llamabot/recorder.py @@ -13,7 +13,6 @@ class PromptRecorder: """Prompt recorder to support recording of prompts and responses.""" def __init__(self): - """Initialize prompt recorder.""" self.prompts_and_responses = [] def __enter__(self): diff --git a/llamabot/zotero/completer.py b/llamabot/zotero/completer.py index 04084a44a..cc7fd1d7c 100644 --- a/llamabot/zotero/completer.py +++ b/llamabot/zotero/completer.py @@ -3,13 +3,11 @@ class PaperTitleCompleter(Completer): - """Completer class for paper titles.""" + """Completer class for paper titles. - def __init__(self, paper_titles): - """Initialize the completer. + :param paper_titles: A list of paper titles to choose from.""" - :param paper_titles: A list of paper titles to choose from. - """ + def __init__(self, paper_titles): self.paper_titles = paper_titles def get_completions(self, document, complete_event) -> list: