Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function calling #25

Merged
merged 46 commits into from
Jan 10, 2024
Merged

Function calling #25

merged 46 commits into from
Jan 10, 2024

Conversation

ericmjl
Copy link
Owner

@ericmjl ericmjl commented Jan 6, 2024

No description provided.

- Add new class FunctionMessage in chatbot.py
- Update ollama_model_names.txt with new model names
- Add new file messages.py with classes for different types of messages
- Add new file tools.py with class for providing tools to the chatbot
- Add new file functions.ipynb with code for describing functions
- Update outlines_models.ipynb with new code
- Add new test file test_messages.py for testing message classes
- Added 'chromadb' to conda dependencies
- Added 'unstructured[all-docs]' to pip dependencies
- Refactored SimpleBot class in simplebot.py to use a client for model interaction instead of directly creating a model.
- Updated the way messages are handled and responses are generated.
- Added new model names to ollama_model_names.txt.
- Imported message types from a new location.
- Removed verbose parameter from SimpleBot initialization.
- Added new method generate_response for generating responses from messages.
- Updated the way streaming responses are handled.
- Updated the way autorecord function is called.
- Updated the way system prompt is initialized.
- Updated the way model name, temperature, and streaming parameters are handled.
- Updated the way messages are created for generating responses.
- Updated the way responses are returned from the SimpleBot call method.
- Updated the way panel method is called.

This refactor improves the modularity and readability of the SimpleBot class and updates the way it interacts with models. The addition of new model names allows for more variety in model usage. The changes to message handling and response generation provide a more streamlined and efficient process. The removal of the verbose parameter simplifies the initialization of the SimpleBot class. The new generate_response method provides a clear and concise way to generate responses from messages. The updates to the handling of streaming responses, autorecord function, system prompt initialization, and model name, temperature, and streaming parameters provide a more efficient and effective way to handle these aspects of the SimpleBot class. The updates to the creation of messages for generating responses and the return of responses from the SimpleBot call method provide a more streamlined and efficient process. The update to the way the panel method is called provides a more efficient and effective way to call this method.
Added a new method __len__ to the BaseMessage class in messages.py.
This method returns the length of the message content.
- Added a new function `make_client` in `model_dispatcher.py` to create an OpenAI client.
- This function will use OpenAI by default, but will switch to LiteLLM for local LLMs if the model name matches any of the keywords in `ollama_model_keywords`.
- This change allows the bot to interface with both OpenAI and local LLMs.
- Removed unused imports and added necessary ones.
- Simplified the ChatBot class by removing unnecessary methods and attributes.
- Moved message handling to a separate SimpleBot class and history handling to a separate History class.
- Updated the __call__ method to use the new SimpleBot and History classes.
- Removed the panel method as it is no longer needed.
- Removed the FunctionMessage class as it is no longer used.
- Updated the __init__ method to accept a session_name and create a new History instance.
- Updated the __repr__ method to work with the new ChatBot structure.
- Overall, these changes make the code cleaner, easier to read, and more maintainable.
…treaming to stream

In this commit, the make_client function from model_dispatcher is replaced with the completion function from litellm. The streaming attribute in the SimpleBot class is also renamed to stream for better readability and consistency. The changes are reflected in the __call__ and generate_response methods of the SimpleBot class.
This commit introduces a new file, __init__.py, which serves as the top-level API for llamabot's components.
This commit introduces a new feature to the codebase, a DocumentStore class for LlamaBot.
This class wraps around ChromaDB and provides methods to append and retrieve documents
from the store. The DocumentStore class is defined in the newly created file
llamabot/components/docstore.py.
This commit introduces two new classes, `History` and `RAGHistory`,
in `llamabot/components/history.py`.
These classes are responsible for storing and retrieving messages from a message history.
The `History` class stores messages in a list, while the `RAGHistory` class
uses a chroma database for storage and enables vector similarity search for message retrieval.
A helper function `retrieve_messages_up_to_budget` is also added to retrieve messages
up to a given character budget.
- This commit introduces a new class, RetrievedMessage, to the messages.py file.
- The RetrievedMessage class represents a message retrieved from the history.
- The class has two attributes: content and role, with role defaulting to "assistant".
…SimpleBot classes

This commit adds type hinting to the system_prompt parameter in the constructors of the ChatBot and SimpleBot classes,
specifying that it should be a string. This provides clearer documentation and can help with code analysis tools.
- Replaced uuid4 with partial from functools for chat_history_class initialization.
- Expanded ChatBot class docstring to include more detailed parameter descriptions.
- Modified ChatBot class initialization to accept a callable chat_history_class and its kwargs.
- This change allows for more flexible and customizable chat history management.
…t.py

This commit includes changes to the .pre-commit-config.yaml file to improve readability by adjusting the indentation.
It also includes modifications to the querybot.py file, where several import statements were removed and replaced with more concise alternatives.
Additionally, new model names were added to the ollama_model_names.txt file.
- Enabled auto import completions for Python
- Set Python type checking mode to basic
The magic_load_doc function in doc_processor.py has been refactored.
The return type has been changed from a list of Document objects to a single Document object.
This change simplifies the handling of the returned document in the calling code.
The function now also initializes a Document object at the start of the function, which is then populated with the loaded document text.
- Renamed `model_chat_token_budgets` to `model_context_window_sizes` to better reflect its purpose.
- Updated the token budgets for various models, including the addition of new `mistral` model variants.
…nused panel function

This commit includes several changes to the SimpleBot class in the llamabot module.
The generate_response method has been refactored for clarity and efficiency.
The messages are now dumped into a list of dictionaries before being passed to the completion function.
The panel function, which was not being used, has been commented out for now.
This commit also removes some unnecessary imports from the top of the file.
- Added an extend method to the DocumentStore class that allows for extending the document store with an iterable of documents.
- Updated the retrieve method to return the first document from the query results.
This commit moves the retrieve_messages_up_to_budget function from history.py to messages.py.
This function retrieves messages up to a given character budget.
The move is done to improve code organization and maintainability.
Additionally, the function now checks if the message is an instance of BaseMessage or str, raising a ValueError if not.
The default role of RetrievedMessage has also been changed from "assistant" to "system".
Removed the unused 'os' import and the 'DEFAULT_SIMILARITY_TOP_KS' and 'SIMILARITY_TOP_K' constants from the querybot.py file. This is part of an effort to clean up and simplify the codebase.
- Added 'nous-hermes2' and 'dolphin-phi' to ollama_model_names.txt
- Updated the return type of the wrapper function in prompt_manager.py to str
- Added a new parameter `json_mode` to the `SimpleBot` class. When `json_mode` is set to True, the response from the `completion` function will be in JSON format.
- Updated the `generate_response` method to include a conditional check for `json_mode`. If `json_mode` is True, the `response_format` argument is added to the `completion` function call with a value of `{"type": "json_object"}`.
- This feature provides more flexibility in handling the bot's responses, especially for applications that prefer working with JSON data.
- Updated the append method in the DocumentStore class to support metadata.
- Extended the docstring for the DocumentStore class to include more details about the interface and the choice of ChromaDB as the default document store.
- This change allows users to add metadata when appending documents to the store, providing more flexibility and context for each document.
- Added new ollama model names to the list in ollama_model_names.txt
- Removed some outdated model names from the list
- Added a new function 'reset' to the DocumentStore class in docstore.py,
  which allows for the deletion and recreation of a collection
- The __call__ method in the ImageBot class has been refactored to handle an optional save_path parameter.
- If save_path is not provided, a filename will be generated from the prompt.
- The typing import has been updated to include Optional.
- This change improves the flexibility of the method and allows for more use cases.
- Changed the variable name db_path to storage_path in DocumentStore class to make it more descriptive.
- Updated all the references of db_path to storage_path.
…t and History

- Removed the use of partial from functools.
- ChatBot now inherits from SimpleBot and History, reducing redundancy and improving code readability.
- Simplified the __call__ method by using inherited methods and properties.
- Renamed the parameter in the __call__ method from 'human_message' to 'message' for consistency.
- Removed unnecessary instance variables such as 'model_name' and 'session_name'.
- Updated the autorecord function call to use the response's content property.
- Updated the __repr__ method to reflect the changes.
Changed the variable name from 'chat_history' to 'messages' in the ChatBot class to better reflect its purpose and usage. This change should make the code easier to understand and maintain.
- QueryBot now inherits from SimpleBot and DocumentStore, instead of instantiating them separately.
- This change simplifies the code and makes it more readable.
- Methods that were previously called on the instances of SimpleBot and DocumentStore are now called directly on the QueryBot instance.
- This change does not affect the functionality of the QueryBot.
ericmjl added 14 commits January 4, 2024 11:50
This commit updates the comment in the history component to specify that the vector similarity search is related to RAGHistory. This provides more context and clarity for future reference.
- Changed parameter names in SimpleBot class for clarity: 'model_name' to 'model', 'streaming' to 'stream', 'verbose' to 'json_mode'.
- Updated 'generate_response' method to return AIMessage instead of string.
- Modified 'autorecord' method call to pass 'response.content' instead of 'response'.
This commit introduces a new feature to the codebase, the Knowledge Graph bot (KGBot). The KGBot takes in a chunk of text and returns a JSON of triplets. It is tested with mistral-medium and uses the default language model. The bot is called with a query and returns a JSON of triplets.
This commit moves the add_documents method from the QueryBot class to the DocumentStore class.
This change improves the organization of the code by placing the method in a more appropriate class.
The method is responsible for adding documents to the DocumentStore,
so it makes more sense for it to be a part of the DocumentStore class.
This change should not affect the functionality of the code.
This commit introduces a new feature to the llamabot codebase. A new class, DocQABot, has been added to the qabot.py file. This bot is designed to use pre-computed questions and answers to generate a response. It includes methods for adding documents for the bot to query and for calling the QABot. This enhancement will improve the bot's ability to generate responses based on the provided documents.
This commit includes the addition of 'litellm' to the list of dependencies in the environment.yml file. This new dependency will provide additional functionality to the project.
This commit includes the addition of 'litellm' to the project dependencies in the pyproject.toml file. This new dependency will provide additional functionality to the project.
- chromadb has been added to the list of dependencies in pyproject.toml
- This addition will allow the project to utilize the functionalities provided by chromadb
Updated the assertions in the test cases of test_doc_processor.py.
The changes include removing the length check of the result and directly asserting the instance and text of the result.
This change reflects the updated behavior of the magic_load_doc function.
…ization and response generation

- Updated the SimpleBot initialization test to include new parameters 'stream' and 'json_mode'.
- Adjusted assertions in the initialization test to match the updated SimpleBot structure.
- Modified the SimpleBot call test to use the new 'generate_response' method instead of the old 'model' method.
- Updated assertions in the call test to check the type and content of the response.
…xtensions

This commit includes several changes to the test_chatbot.py and test_doc_processor.py files. In test_chatbot.py, the tests for the ChatBot class have been expanded and improved. The test_chatbot_initialization now checks for correct instantiation of the ChatBot object. The test_chatbot_call now verifies that the ChatBot correctly processes a human message using pytest-mock. The test_chatbot_repr ensures that the string representation of ChatBot includes both system and human messages.

In test_doc_processor.py, the test_magic_load_doc_extensions has been commented out. This test was previously testing that magic_load_doc returns a list of one Document object, and the text of the Document object is the content of the test file. It also tested that magic_load_doc calls the correct loader. This test has been commented out for now, but may be re-enabled in the future.
This commit enhances the test_chatbot_repr function in the test_chatbot.py file. It now uses the pytest-mock mocker fixture to mock the generate_response method of the ChatBot class. This allows the test to verify that the string representation of the ChatBot includes both human and AI messages. The mocked AI response is also checked to be present in the string representation.
In this commit, we have made the following changes:

- Added a new code cell in the `chatbot_as_simplebot.ipynb` notebook to import the `ChatBot` class from `llamabot` and create a new instance of it.
- Updated the `test_chatbot_repr` function in `test_chatbot.py` to use the `content` attribute of the `AIMessage` instance for the mocked response.
- Modified the `test_split_document_with_overlap` function in `test_doc_processor.py` to expect 3 chunks instead of 4 when splitting a document with overlap.
Copy link

codecov bot commented Jan 7, 2024

Codecov Report

Attention: 49 lines in your changes are missing coverage. Please review.

Comparison is base (f190a87) 62.58% compared to head (17352b8) 68.43%.

Files Patch % Lines
llamabot/components/history.py 54.54% 15 Missing ⚠️
llamabot/bot/simplebot.py 39.13% 14 Missing ⚠️
llamabot/bot/querybot.py 47.36% 10 Missing ⚠️
llamabot/components/messages.py 77.14% 8 Missing ⚠️
llamabot/components/docstore.py 97.22% 1 Missing ⚠️
llamabot/doc_processor.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #25      +/-   ##
==========================================
+ Coverage   62.58%   68.43%   +5.85%     
==========================================
  Files          47       51       +4     
  Lines        1820     1771      -49     
==========================================
+ Hits         1139     1212      +73     
+ Misses        681      559     -122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This commit enhances the document addition method in the DocumentStore class to handle metadata more flexibly. It also introduces tests for the DocumentStore class, including tests for document addition and retrieval.
- Added 'llama-pro' to ollama_model_names.txt
- Removed unused pytest import and make_fake_document function in test_docstore.py
@ericmjl ericmjl merged commit be618af into main Jan 10, 2024
@ericmjl ericmjl deleted the function-calling branch January 10, 2024 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant