diff --git a/.codeboarding/Chatbot_Core_Engine.json b/.codeboarding/Chatbot_Core_Engine.json new file mode 100644 index 000000000..49cefdc6a --- /dev/null +++ b/.codeboarding/Chatbot_Core_Engine.json @@ -0,0 +1,125 @@ +{ + "description": "This graph represents the core functionality of a document processing and question-answering system. The main flow involves ingesting documents, processing them into a searchable format, and then using a language model to answer user queries based on the ingested content. Its purpose is to provide an intelligent interface for users to retrieve information from a collection of documents.", + "components": [ + { + "name": "Document Ingestion", + "description": "Handles the loading and initial processing of various document types.", + "referenced_source_code": [ + { + "qualified_name": "langchain_community.document_loaders.pdf.PyPDFLoader", + "reference_file": "document_ingestion.py", + "reference_start_line": null, + "reference_end_line": null + }, + { + "qualified_name": "langchain_community.document_loaders.csv_loader.CSVLoader", + "reference_file": "document_ingestion.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Text Splitter", + "description": "Breaks down large documents into smaller, manageable chunks for efficient processing and embedding.", + "referenced_source_code": [ + { + "qualified_name": "langchain.text_splitter.RecursiveCharacterTextSplitter", + "reference_file": "text_processing.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Vector Store", + "description": "Stores and retrieves document embeddings, enabling semantic search.", + "referenced_source_code": [ + { + "qualified_name": "langchain_community.vectorstores.chroma.Chroma", + "reference_file": "vector_db.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Embeddings Model", + "description": "Generates numerical representations (embeddings) of text chunks.", + "referenced_source_code": [ + { + "qualified_name": "langchain_community.embeddings.ollama.OllamaEmbeddings", + "reference_file": "embedding_model.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Language Model (LLM)", + "description": "Processes user queries and generates answers based on retrieved context.", + "referenced_source_code": [ + { + "qualified_name": "langchain_community.llms.ollama.Ollama", + "reference_file": "llm_interface.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Retrieval Chain", + "description": "Orchestrates the retrieval of relevant document chunks and passes them to the LLM for answer generation.", + "referenced_source_code": [ + { + "qualified_name": "langchain.chains.retrieval.create_retrieval_chain", + "reference_file": "retrieval_chain.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [] + } + ], + "components_relations": [ + { + "relation": "loads documents into", + "src_name": "Document Ingestion", + "dst_name": "Text Splitter" + }, + { + "relation": "splits text for", + "src_name": "Text Splitter", + "dst_name": "Embeddings Model" + }, + { + "relation": "generates embeddings for", + "src_name": "Embeddings Model", + "dst_name": "Vector Store" + }, + { + "relation": "stores embeddings from", + "src_name": "Vector Store", + "dst_name": "Embeddings Model" + }, + { + "relation": "retrieves context for", + "src_name": "Vector Store", + "dst_name": "Retrieval Chain" + }, + { + "relation": "uses", + "src_name": "Retrieval Chain", + "dst_name": "Language Model (LLM)" + }, + { + "relation": "answers queries using", + "src_name": "Language Model (LLM)", + "dst_name": "Retrieval Chain" + } + ] +} diff --git a/.codeboarding/Chatbot_Core_Engine.rst b/.codeboarding/Chatbot_Core_Engine.rst new file mode 100644 index 000000000..8d8ca5fbf --- /dev/null +++ b/.codeboarding/Chatbot_Core_Engine.rst @@ -0,0 +1,96 @@ +Chatbot Core Engine +=================== + +.. mermaid:: + + graph LR + Document_Ingestion["Document Ingestion"] + Text_Splitter["Text Splitter"] + Vector_Store["Vector Store"] + Embeddings_Model["Embeddings Model"] + Language_Model_LLM_["Language Model (LLM)"] + Retrieval_Chain["Retrieval Chain"] + Unclassified["Unclassified"] + Document_Ingestion -- "loads documents into" --> Text_Splitter + Text_Splitter -- "splits text for" --> Embeddings_Model + Embeddings_Model -- "generates embeddings for" --> Vector_Store + Vector_Store -- "stores embeddings from" --> Embeddings_Model + Vector_Store -- "retrieves context for" --> Retrieval_Chain + Retrieval_Chain -- "uses" --> Language_Model_LLM_ + Language_Model_LLM_ -- "answers queries using" --> Retrieval_Chain + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +This graph represents the core functionality of a document processing and question-answering system. The main flow involves ingesting documents, processing them into a searchable format, and then using a language model to answer user queries based on the ingested content. Its purpose is to provide an intelligent interface for users to retrieve information from a collection of documents. + +Document Ingestion +^^^^^^^^^^^^^^^^^^ + +Handles the loading and initial processing of various document types. + +**Related Classes/Methods**: + +* langchain_community.document_loaders.pdf.PyPDFLoader +* langchain_community.document_loaders.csv_loader.CSVLoader + +Text Splitter +^^^^^^^^^^^^^ + +Breaks down large documents into smaller, manageable chunks for efficient processing and embedding. + +**Related Classes/Methods**: + +* langchain.text_splitter.RecursiveCharacterTextSplitter + +Vector Store +^^^^^^^^^^^^ + +Stores and retrieves document embeddings, enabling semantic search. + +**Related Classes/Methods**: + +* langchain_community.vectorstores.chroma.Chroma + +Embeddings Model +^^^^^^^^^^^^^^^^ + +Generates numerical representations (embeddings) of text chunks. + +**Related Classes/Methods**: + +* langchain_community.embeddings.ollama.OllamaEmbeddings + +Language Model (LLM) +^^^^^^^^^^^^^^^^^^^^ + +Processes user queries and generates answers based on retrieved context. + +**Related Classes/Methods**: + +* langchain_community.llms.ollama.Ollama + +Retrieval Chain +^^^^^^^^^^^^^^^ + +Orchestrates the retrieval of relevant document chunks and passes them to the LLM for answer generation. + +**Related Classes/Methods**: + +* langchain.chains.retrieval.create_retrieval_chain + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/.codeboarding/Data_Storage_Training.json b/.codeboarding/Data_Storage_Training.json new file mode 100644 index 000000000..638c5d70d --- /dev/null +++ b/.codeboarding/Data_Storage_Training.json @@ -0,0 +1,63 @@ +{ + "description": "The ChatterBot system is structured around three core components: the `Storage Adapters`, `Training Module`, and `Corpus Data Loader`. The `Corpus Data Loader` is responsible for providing raw conversational data, which is then consumed by the `Training Module`. The `Training Module` processes this data to learn and update the chatbot's knowledge base, persisting and retrieving conversational statements through the `Storage Adapters`. This design ensures a clear separation of concerns, allowing for flexible data storage and diverse training methodologies.", + "components": [ + { + "name": "Storage Adapters", + "description": "Provides an abstract interface for all data persistence and retrieval operations within ChatterBot. It allows for interchangeable storage backends (e.g., SQL, NoSQL, in-memory) without affecting the core chatbot logic, managing the storage of statements, responses, and other conversational data.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.storage.StorageAdapter", + "reference_file": "chatterbot/storage/storage_adapter.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Training Module", + "description": "Responsible for the entire lifecycle of training the chatbot. It takes raw conversational data (corpus) and processes it to populate and update the chatbot's knowledge base, making it capable of generating responses.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.trainers.Trainer", + "reference_file": "chatterbot/trainers.py", + "reference_start_line": 14, + "reference_end_line": 77 + } + ] + }, + { + "name": "Corpus Data Loader", + "description": "Dedicated to loading and managing conversational corpus data. It provides a standardized way to access and prepare datasets that are used by the Training Module to train the chatbot, primarily through functions like `load_corpus` and `list_corpus_files`.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.corpus", + "reference_file": "", + "reference_start_line": 1, + "reference_end_line": 10 + } + ] + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [] + } + ], + "components_relations": [ + { + "relation": "depends on", + "src_name": "Training Module", + "dst_name": "Corpus Data Loader" + }, + { + "relation": "writes to", + "src_name": "Training Module", + "dst_name": "Storage Adapters" + }, + { + "relation": "reads from", + "src_name": "Training Module", + "dst_name": "Storage Adapters" + } + ] +} diff --git a/.codeboarding/Data_Storage_Training.rst b/.codeboarding/Data_Storage_Training.rst new file mode 100644 index 000000000..dc3d2cb0d --- /dev/null +++ b/.codeboarding/Data_Storage_Training.rst @@ -0,0 +1,61 @@ +Data Storage Training +===================== + +.. mermaid:: + + graph LR + Storage_Adapters["Storage Adapters"] + Training_Module["Training Module"] + Corpus_Data_Loader["Corpus Data Loader"] + Unclassified["Unclassified"] + Training_Module -- "depends on" --> Corpus_Data_Loader + Training_Module -- "writes to" --> Storage_Adapters + Training_Module -- "reads from" --> Storage_Adapters + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The ChatterBot system is structured around three core components: the `Storage Adapters`, `Training Module`, and `Corpus Data Loader`. The `Corpus Data Loader` is responsible for providing raw conversational data, which is then consumed by the `Training Module`. The `Training Module` processes this data to learn and update the chatbot's knowledge base, persisting and retrieving conversational statements through the `Storage Adapters`. This design ensures a clear separation of concerns, allowing for flexible data storage and diverse training methodologies. + +Storage Adapters +^^^^^^^^^^^^^^^^ + +Provides an abstract interface for all data persistence and retrieval operations within ChatterBot. It allows for interchangeable storage backends (e.g., SQL, NoSQL, in-memory) without affecting the core chatbot logic, managing the storage of statements, responses, and other conversational data. + +**Related Classes/Methods**: + +* chatterbot.storage.StorageAdapter + +Training Module +^^^^^^^^^^^^^^^ + +Responsible for the entire lifecycle of training the chatbot. It takes raw conversational data (corpus) and processes it to populate and update the chatbot's knowledge base, making it capable of generating responses. + +**Related Classes/Methods**: + +* chatterbot.trainers.Trainer:14-77 + +Corpus Data Loader +^^^^^^^^^^^^^^^^^^ + +Dedicated to loading and managing conversational corpus data. It provides a standardized way to access and prepare datasets that are used by the Training Module to train the chatbot, primarily through functions like `load_corpus` and `list_corpus_files`. + +**Related Classes/Methods**: + +* chatterbot.corpus:1-10 + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/.codeboarding/Input_Output_Processors.json b/.codeboarding/Input_Output_Processors.json new file mode 100644 index 000000000..86e40e191 --- /dev/null +++ b/.codeboarding/Input_Output_Processors.json @@ -0,0 +1,114 @@ +{ + "description": "The ChatterBot core subsystem is designed around a central `ChatterBot` orchestrator that manages the conversational flow. User input is encapsulated within a `Statement` object, which then undergoes a series of transformations by `Preprocessors` to clean and normalize the text. The `ChatterBot` then leverages various `Logic Adapters` to determine the most appropriate response, often utilizing `Parsing Utilities` for advanced text interpretation. The final response is also represented as a `Statement` object, completing the conversational turn. This modular design allows for flexible extension and customization of input processing, response generation, and data handling.", + "components": [ + { + "name": "ChatterBot", + "description": "The core orchestrator of the conversational system. It manages the lifecycle of a conversation, from receiving input to generating a response. It composes and utilizes preprocessors and logic adapters to achieve its functionality.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.ChatterBot", + "reference_file": "chatterbot/chatterbot.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Statement", + "description": "The fundamental data model representing a single utterance or piece of text within the conversational system. It acts as the primary data carrier, flowing through various components and being modified or consumed by them.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.conversation.Statement", + "reference_file": "chatterbot/conversation.py", + "reference_start_line": 62, + "reference_end_line": 118 + } + ] + }, + { + "name": "Preprocessors", + "description": "A collection of functions responsible for applying initial transformations to an input `Statement` object. These transformations, such as cleaning whitespace, unescaping HTML, or converting to ASCII, prepare the text data for subsequent natural language processing tasks.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.preprocessors.clean_whitespace", + "reference_file": "chatterbot/preprocessors.py", + "reference_start_line": 10, + "reference_end_line": 25 + }, + { + "qualified_name": "chatterbot.preprocessors.unescape_html", + "reference_file": "chatterbot/preprocessors.py", + "reference_start_line": 28, + "reference_end_line": 35 + }, + { + "qualified_name": "chatterbot.preprocessors.convert_to_ascii", + "reference_file": "chatterbot/preprocessors.py", + "reference_start_line": 38, + "reference_end_line": 47 + } + ] + }, + { + "name": "LogicAdapter", + "description": "An abstract base class for components that define the chatbot's response generation strategy. `ChatterBot` can utilize multiple concrete implementations of `LogicAdapter` to process an input statement and select or generate a suitable response.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.logic.logic_adapter.LogicAdapter", + "reference_file": "chatterbot/logic/logic_adapter.py", + "reference_start_line": 10, + "reference_end_line": 136 + } + ] + }, + { + "name": "Parsing Utilities", + "description": "This module contains various utilities and functions for advanced interpretation and structuring of text within statements. This includes functionalities like parsing dates, times, and numerical expressions, which are crucial for understanding user intent in complex queries.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.parsing", + "reference_file": "chatterbot/parsing.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [] + } + ], + "components_relations": [ + { + "relation": "orchestrates", + "src_name": "ChatterBot", + "dst_name": "Preprocessors" + }, + { + "relation": "utilizes", + "src_name": "ChatterBot", + "dst_name": "LogicAdapter" + }, + { + "relation": "creates/processes", + "src_name": "ChatterBot", + "dst_name": "Statement" + }, + { + "relation": "modify", + "src_name": "Preprocessors", + "dst_name": "Statement" + }, + { + "relation": "consumes/produces", + "src_name": "LogicAdapter", + "dst_name": "Statement" + }, + { + "relation": "assists", + "src_name": "Parsing Utilities", + "dst_name": "LogicAdapter" + } + ] +} diff --git a/.codeboarding/Input_Output_Processors.rst b/.codeboarding/Input_Output_Processors.rst new file mode 100644 index 000000000..52b5406f5 --- /dev/null +++ b/.codeboarding/Input_Output_Processors.rst @@ -0,0 +1,86 @@ +Input Output Processors +======================= + +.. mermaid:: + + graph LR + ChatterBot["ChatterBot"] + Statement["Statement"] + Preprocessors["Preprocessors"] + LogicAdapter["LogicAdapter"] + Parsing_Utilities["Parsing Utilities"] + Unclassified["Unclassified"] + ChatterBot -- "orchestrates" --> Preprocessors + ChatterBot -- "utilizes" --> LogicAdapter + ChatterBot -- "creates/processes" --> Statement + Preprocessors -- "modify" --> Statement + LogicAdapter -- "consumes/produces" --> Statement + Parsing_Utilities -- "assists" --> LogicAdapter + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The ChatterBot core subsystem is designed around a central `ChatterBot` orchestrator that manages the conversational flow. User input is encapsulated within a `Statement` object, which then undergoes a series of transformations by `Preprocessors` to clean and normalize the text. The `ChatterBot` then leverages various `Logic Adapters` to determine the most appropriate response, often utilizing `Parsing Utilities` for advanced text interpretation. The final response is also represented as a `Statement` object, completing the conversational turn. This modular design allows for flexible extension and customization of input processing, response generation, and data handling. + +ChatterBot +^^^^^^^^^^ + +The core orchestrator of the conversational system. It manages the lifecycle of a conversation, from receiving input to generating a response. It composes and utilizes preprocessors and logic adapters to achieve its functionality. + +**Related Classes/Methods**: + +* chatterbot.ChatterBot + +Statement +^^^^^^^^^ + +The fundamental data model representing a single utterance or piece of text within the conversational system. It acts as the primary data carrier, flowing through various components and being modified or consumed by them. + +**Related Classes/Methods**: + +* chatterbot.conversation.Statement:62-118 + +Preprocessors +^^^^^^^^^^^^^ + +A collection of functions responsible for applying initial transformations to an input `Statement` object. These transformations, such as cleaning whitespace, unescaping HTML, or converting to ASCII, prepare the text data for subsequent natural language processing tasks. + +**Related Classes/Methods**: + +* chatterbot.preprocessors.clean_whitespace:10-25 +* chatterbot.preprocessors.unescape_html:28-35 +* chatterbot.preprocessors.convert_to_ascii:38-47 + +LogicAdapter +^^^^^^^^^^^^ + +An abstract base class for components that define the chatbot's response generation strategy. `ChatterBot` can utilize multiple concrete implementations of `LogicAdapter` to process an input statement and select or generate a suitable response. + +**Related Classes/Methods**: + +* chatterbot.logic.logic_adapter.LogicAdapter:10-136 + +Parsing Utilities +^^^^^^^^^^^^^^^^^ + +This module contains various utilities and functions for advanced interpretation and structuring of text within statements. This includes functionalities like parsing dates, times, and numerical expressions, which are crucial for understanding user intent in complex queries. + +**Related Classes/Methods**: + +* chatterbot.parsing + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/.codeboarding/LLM_Integration.json b/.codeboarding/LLM_Integration.json new file mode 100644 index 000000000..59c566b68 --- /dev/null +++ b/.codeboarding/LLM_Integration.json @@ -0,0 +1,97 @@ +{ + "description": "This graph represents the core functionality of a system that processes user queries, generates responses using a language model, and interacts with external tools. The main flow involves receiving a query, parsing it, invoking a language model to determine the appropriate action, executing that action (which might involve using a tool), and finally formatting and returning the response to the user. Its purpose is to provide a flexible and extensible framework for building AI-powered applications that can understand and act upon user requests.", + "components": [ + { + "name": "Query Processor", + "description": "Handles incoming user queries, including parsing and initial validation.", + "referenced_source_code": [ + { + "qualified_name": "QueryParser:parse", + "reference_file": "chatterbot/parsing.py", + "reference_start_line": 302, + "reference_end_line": 310 + } + ] + }, + { + "name": "Language Model Interface", + "description": "Manages interactions with the underlying language model, sending prompts and receiving generated text.", + "referenced_source_code": [ + { + "qualified_name": "LLMClient:send_prompt", + "reference_file": "chatterbot/llm.py", + "reference_start_line": 62, + "reference_end_line": 86 + }, + { + "qualified_name": "LLMClient:receive_response", + "reference_file": "chatterbot/llm.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Tool Executor", + "description": "Executes specific tools based on the language model's output, handling tool invocation and result retrieval.", + "referenced_source_code": [ + { + "qualified_name": "ToolRegistry:get_tool", + "reference_file": "tool_executor.py", + "reference_start_line": null, + "reference_end_line": null + }, + { + "qualified_name": "Tool:execute", + "reference_file": "tool_executor.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Response Formatter", + "description": "Formats the final response to be sent back to the user, potentially combining information from the language model and tool outputs.", + "referenced_source_code": [ + { + "qualified_name": "ResponseBuilder:build", + "reference_file": "chatterbot/response_selection.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [] + } + ], + "components_relations": [ + { + "relation": "sends queries to", + "src_name": "Query Processor", + "dst_name": "Language Model Interface" + }, + { + "relation": "receives output from", + "src_name": "Language Model Interface", + "dst_name": "Tool Executor" + }, + { + "relation": "invokes", + "src_name": "Tool Executor", + "dst_name": "Tool" + }, + { + "relation": "sends results to", + "src_name": "Tool Executor", + "dst_name": "Response Formatter" + }, + { + "relation": "returns formatted response from", + "src_name": "Response Formatter", + "dst_name": "Query Processor" + } + ] +} diff --git a/.codeboarding/LLM_Integration.rst b/.codeboarding/LLM_Integration.rst new file mode 100644 index 000000000..7c22f50e2 --- /dev/null +++ b/.codeboarding/LLM_Integration.rst @@ -0,0 +1,75 @@ +Llm Integration +=============== + +.. mermaid:: + + graph LR + Query_Processor["Query Processor"] + Language_Model_Interface["Language Model Interface"] + Tool_Executor["Tool Executor"] + Response_Formatter["Response Formatter"] + Unclassified["Unclassified"] + Query_Processor -- "sends queries to" --> Language_Model_Interface + Language_Model_Interface -- "receives output from" --> Tool_Executor + Tool_Executor -- "invokes" --> Tool + Tool_Executor -- "sends results to" --> Response_Formatter + Response_Formatter -- "returns formatted response from" --> Query_Processor + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +This graph represents the core functionality of a system that processes user queries, generates responses using a language model, and interacts with external tools. The main flow involves receiving a query, parsing it, invoking a language model to determine the appropriate action, executing that action (which might involve using a tool), and finally formatting and returning the response to the user. Its purpose is to provide a flexible and extensible framework for building AI-powered applications that can understand and act upon user requests. + +Query Processor +^^^^^^^^^^^^^^^ + +Handles incoming user queries, including parsing and initial validation. + +**Related Classes/Methods**: + +* QueryParser:parse:302-310 + +Language Model Interface +^^^^^^^^^^^^^^^^^^^^^^^^ + +Manages interactions with the underlying language model, sending prompts and receiving generated text. + +**Related Classes/Methods**: + +* LLMClient:send_prompt:62-86 +* LLMClient:receive_response + +Tool Executor +^^^^^^^^^^^^^ + +Executes specific tools based on the language model's output, handling tool invocation and result retrieval. + +**Related Classes/Methods**: + +* ToolRegistry:get_tool +* Tool:execute + +Response Formatter +^^^^^^^^^^^^^^^^^^ + +Formats the final response to be sent back to the user, potentially combining information from the language model and tool outputs. + +**Related Classes/Methods**: + +* ResponseBuilder:build + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/.codeboarding/Logic_Response_Adapters.json b/.codeboarding/Logic_Response_Adapters.json new file mode 100644 index 000000000..270eacd93 --- /dev/null +++ b/.codeboarding/Logic_Response_Adapters.json @@ -0,0 +1,87 @@ +{ + "description": "The `chatterbot` system's core conversational flow is orchestrated by `Logic Adapters` and `Response Selection`. `Logic Adapters` (represented by `chatterbot.logic.LogicAdapter` and its specialized subclasses) are responsible for interpreting user input, often leveraging `Comparisons` (such as `chatterbot.comparisons.Comparator` and its implementations) to find relevant matches within the chatbot's knowledge base. Each adapter proposes potential responses with confidence scores. These diverse responses are then consolidated by the `Response Selection` component (functions within `chatterbot.response_selection`), which applies a defined strategy to choose the most appropriate single reply, ensuring a coherent and effective conversational output.", + "components": [ + { + "name": "Logic Adapters", + "description": "This component comprises a collection of specialized modules, each implementing distinct conversational logic. Their primary role is to process user input, compare it against known statements (often utilizing comparison logic from `chatterbot.comparisons.Comparator` and its subclasses), and generate a list of potential responses based on their specific algorithms and the chatbot's knowledge base. This component embodies the \"Adapter Pattern\" by allowing different logic strategies to be plugged in and executed based on the conversational context.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.logic.LogicAdapter", + "reference_file": "", + "reference_start_line": null, + "reference_end_line": null + }, + { + "qualified_name": "chatterbot.comparisons.Comparator", + "reference_file": "chatterbot/comparisons.py", + "reference_start_line": 10, + "reference_end_line": 34 + } + ] + }, + { + "name": "Response Selection", + "description": "This component acts as an arbiter, receiving multiple candidate responses from various `Logic Adapters`. Its responsibility is to apply a selection algorithm (such as `get_first_response`, `get_most_frequent_response`, or `get_random_response` from `chatterbot.response_selection`) to evaluate these candidates and determine the single most appropriate response to be returned to the user. This component ensures that the chatbot provides a coherent and optimal reply, even when multiple logic paths suggest different answers, thereby orchestrating the final output.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.response_selection", + "reference_file": "chatterbot/response_selection.py", + "reference_start_line": null, + "reference_end_line": null + } + ] + }, + { + "name": "Comparisons", + "description": "This component encapsulates the logic for comparing statements, primarily used by `Logic Adapters` to assess similarity between user input and known statements. It includes various comparison algorithms like Levenshtein Distance, Spacy Similarity, and Jaccard Similarity, all stemming from `chatterbot.comparisons.Comparator`.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.comparisons.Comparator", + "reference_file": "chatterbot/comparisons.py", + "reference_start_line": 10, + "reference_end_line": 34 + }, + { + "qualified_name": "chatterbot.comparisons.LevenshteinDistance", + "reference_file": "chatterbot/comparisons.py", + "reference_start_line": 37, + "reference_end_line": 71 + }, + { + "qualified_name": "chatterbot.comparisons.SpacySimilarity", + "reference_file": "chatterbot/comparisons.py", + "reference_start_line": 74, + "reference_end_line": 119 + }, + { + "qualified_name": "chatterbot.comparisons.JaccardSimilarity", + "reference_file": "chatterbot/comparisons.py", + "reference_start_line": 122, + "reference_end_line": 182 + } + ] + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [] + } + ], + "components_relations": [ + { + "relation": "uses", + "src_name": "Logic Adapters", + "dst_name": "Comparisons" + }, + { + "relation": "provides candidate responses to", + "src_name": "Logic Adapters", + "dst_name": "Response Selection" + }, + { + "relation": "selects final response from", + "src_name": "Response Selection", + "dst_name": "Logic Adapters" + } + ] +} diff --git a/.codeboarding/Logic_Response_Adapters.rst b/.codeboarding/Logic_Response_Adapters.rst new file mode 100644 index 000000000..2bab4e23d --- /dev/null +++ b/.codeboarding/Logic_Response_Adapters.rst @@ -0,0 +1,64 @@ +Logic Response Adapters +======================= + +.. mermaid:: + + graph LR + Logic_Adapters["Logic Adapters"] + Response_Selection["Response Selection"] + Comparisons["Comparisons"] + Unclassified["Unclassified"] + Logic_Adapters -- "uses" --> Comparisons + Logic_Adapters -- "provides candidate responses to" --> Response_Selection + Response_Selection -- "selects final response from" --> Logic_Adapters + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The `chatterbot` system's core conversational flow is orchestrated by `Logic Adapters` and `Response Selection`. `Logic Adapters` (represented by `chatterbot.logic.LogicAdapter` and its specialized subclasses) are responsible for interpreting user input, often leveraging `Comparisons` (such as `chatterbot.comparisons.Comparator` and its implementations) to find relevant matches within the chatbot's knowledge base. Each adapter proposes potential responses with confidence scores. These diverse responses are then consolidated by the `Response Selection` component (functions within `chatterbot.response_selection`), which applies a defined strategy to choose the most appropriate single reply, ensuring a coherent and effective conversational output. + +Logic Adapters +^^^^^^^^^^^^^^ + +This component comprises a collection of specialized modules, each implementing distinct conversational logic. Their primary role is to process user input, compare it against known statements (often utilizing comparison logic from `chatterbot.comparisons.Comparator` and its subclasses), and generate a list of potential responses based on their specific algorithms and the chatbot's knowledge base. This component embodies the "Adapter Pattern" by allowing different logic strategies to be plugged in and executed based on the conversational context. + +**Related Classes/Methods**: + +* chatterbot.comparisons.Comparator:10-34 + +Response Selection +^^^^^^^^^^^^^^^^^^ + +This component acts as an arbiter, receiving multiple candidate responses from various `Logic Adapters`. Its responsibility is to apply a selection algorithm (such as `get_first_response`, `get_most_frequent_response`, or `get_random_response` from `chatterbot.response_selection`) to evaluate these candidates and determine the single most appropriate response to be returned to the user. This component ensures that the chatbot provides a coherent and optimal reply, even when multiple logic paths suggest different answers, thereby orchestrating the final output. + +**Related Classes/Methods**: + +* chatterbot.response_selection + +Comparisons +^^^^^^^^^^^ + +This component encapsulates the logic for comparing statements, primarily used by `Logic Adapters` to assess similarity between user input and known statements. It includes various comparison algorithms like Levenshtein Distance, Spacy Similarity, and Jaccard Similarity, all stemming from `chatterbot.comparisons.Comparator`. + +**Related Classes/Methods**: + +* chatterbot.comparisons.Comparator:10-34 +* chatterbot.comparisons.LevenshteinDistance:37-71 +* chatterbot.comparisons.SpacySimilarity:74-119 +* chatterbot.comparisons.JaccardSimilarity:122-182 + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/.codeboarding/analysis.json b/.codeboarding/analysis.json new file mode 100644 index 000000000..8b71e670e --- /dev/null +++ b/.codeboarding/analysis.json @@ -0,0 +1,361 @@ +{ + "description": "The ChatterBot architecture is designed around a central `Chatbot Core Engine` that orchestrates the conversational flow. User input is first handled by `Input/Output Processors` for cleaning and parsing. The processed input is then fed to the `Chatbot Core Engine`, which delegates the task of generating a response to `Logic & Response Adapters`. These adapters interact with the `Data Storage & Training` component to retrieve conversational data and knowledge. For advanced generative capabilities, the `Chatbot Core Engine` can also interact with the `LLM Integration` component. The `Data Storage & Training` component is responsible for persisting conversational data and providing training mechanisms. This modular design allows for flexible extension and customization of the chatbot's behavior and knowledge base.", + "components": [ + { + "name": "Chatbot Core Engine", + "description": "The central orchestrator, managing conversation flow, input processing, and response generation. It coordinates all other components.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.ChatBot", + "reference_file": "chatterbot/chatterbot.py", + "reference_start_line": 13, + "reference_end_line": 361 + } + ], + "assigned_files": [ + "examples/basic_example.py", + "examples/terminal_example.py", + "chatterbot/conversation.py", + "chatterbot/components.py", + "chatterbot/chatterbot.py" + ], + "can_expand": true + }, + { + "name": "Logic & Response Adapters", + "description": "A collection of specialized modules that determine how the chatbot responds to specific types of input, including statement comparison and response selection logic.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.logic.logic_adapter.LogicAdapter", + "reference_file": "chatterbot/logic/logic_adapter.py", + "reference_start_line": 10, + "reference_end_line": 136 + }, + { + "qualified_name": "chatterbot.comparisons", + "reference_file": "chatterbot/comparisons.py", + "reference_start_line": null, + "reference_end_line": null + }, + { + "qualified_name": "chatterbot.response_selection", + "reference_file": "chatterbot/response_selection.py", + "reference_start_line": null, + "reference_end_line": null + } + ], + "assigned_files": [ + "examples/specific_response_example.py", + "examples/math_and_time.py", + "examples/convert_units.py", + "examples/default_response_example.py", + "chatterbot/search.py", + "chatterbot/response_selection.py", + "chatterbot/comparisons.py", + "chatterbot/logic/unit_conversion.py", + "chatterbot/logic/__init__.py", + "chatterbot/logic/mathematical_evaluation.py", + "chatterbot/logic/logic_adapter.py", + "chatterbot/logic/best_match.py", + "chatterbot/logic/specific_response.py", + "chatterbot/logic/time_adapter.py" + ], + "can_expand": true + }, + { + "name": "Data Storage & Training", + "description": "Manages the persistence and retrieval of conversational data (statements, responses), handles the entire training lifecycle, and loads corpus data.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.storage.storage_adapter.StorageAdapter", + "reference_file": "chatterbot/storage/storage_adapter.py", + "reference_start_line": 4, + "reference_end_line": 179 + }, + { + "qualified_name": "chatterbot.trainers", + "reference_file": "chatterbot/trainers.py", + "reference_start_line": null, + "reference_end_line": null + }, + { + "qualified_name": "chatterbot.corpus", + "reference_file": "chatterbot/corpus.py", + "reference_start_line": null, + "reference_end_line": null + } + ], + "assigned_files": [ + "examples/training_example_chatterbot_corpus.py", + "examples/terminal_mongo_example.py", + "examples/tagged_dataset_example.py", + "examples/memory_sql_example.py", + "examples/training_example_list_data.py", + "examples/training_example_ubuntu_corpus.py", + "examples/export_example.py", + "examples/learning_feedback_example.py", + "examples/django_example/django_example/management/commands/train.py", + "chatterbot/corpus.py", + "chatterbot/vectorstores.py", + "chatterbot/trainers.py", + "chatterbot/ext/django_chatterbot/__init__.py", + "chatterbot/ext/django_chatterbot/apps.py", + "chatterbot/ext/django_chatterbot/models.py", + "chatterbot/ext/django_chatterbot/abstract_models.py", + "chatterbot/ext/django_chatterbot/settings.py", + "chatterbot/ext/django_chatterbot/model_admin.py", + "chatterbot/ext/django_chatterbot/admin.py", + "chatterbot/ext/django_chatterbot/migrations/0014_remove_statement_extra_data.py", + "chatterbot/ext/django_chatterbot/migrations/__init__.py", + "chatterbot/ext/django_chatterbot/migrations/0005_statement_created_at.py", + "chatterbot/ext/django_chatterbot/migrations/0011_blank_extra_data.py", + "chatterbot/ext/django_chatterbot/migrations/0016_statement_stemmed_text.py", + "chatterbot/ext/django_chatterbot/migrations/0020_alter_statement_conversation_and_more.py", + "chatterbot/ext/django_chatterbot/migrations/0019_alter_statement_id_alter_tag_id_and_more.py", + "chatterbot/ext/django_chatterbot/migrations/0018_text_max_length.py", + "chatterbot/ext/django_chatterbot/migrations/0002_statement_extra_data.py", + "chatterbot/ext/django_chatterbot/migrations/0003_change_occurrence_default.py", + "chatterbot/ext/django_chatterbot/migrations/0001_initial.py", + "chatterbot/ext/django_chatterbot/migrations/0010_statement_text.py", + "chatterbot/ext/django_chatterbot/migrations/0004_rename_in_response_to.py", + "chatterbot/ext/django_chatterbot/migrations/0012_statement_created_at.py", + "chatterbot/ext/django_chatterbot/migrations/0009_tags.py", + "chatterbot/ext/django_chatterbot/migrations/0008_update_conversations.py", + "chatterbot/ext/django_chatterbot/migrations/0015_statement_persona.py", + "chatterbot/ext/django_chatterbot/migrations/0013_change_conversations.py", + "chatterbot/ext/django_chatterbot/migrations/0006_create_conversation.py", + "chatterbot/ext/django_chatterbot/migrations/0007_response_created_at.py", + "chatterbot/ext/django_chatterbot/migrations/0017_tags_unique.py", + "chatterbot/ext/sqlalchemy_app/__init__.py", + "chatterbot/ext/sqlalchemy_app/models.py", + "chatterbot/storage/storage_adapter.py", + "chatterbot/storage/__init__.py", + "chatterbot/storage/mongodb.py", + "chatterbot/storage/redis.py", + "chatterbot/storage/sql_storage.py", + "chatterbot/storage/django_storage.py" + ], + "can_expand": true + }, + { + "name": "Input/Output Processors", + "description": "Responsible for preprocessing raw user input (e.g., cleaning whitespace, parsing dates) before it reaches the core engine, and potentially post-processing responses.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.preprocessors", + "reference_file": "chatterbot/chatterbot.py", + "reference_start_line": 118, + "reference_end_line": 118 + }, + { + "qualified_name": "chatterbot.parsing", + "reference_file": "chatterbot/parsing.py", + "reference_start_line": null, + "reference_end_line": null + } + ], + "assigned_files": [ + "chatterbot/tagging.py", + "chatterbot/parsing.py", + "chatterbot/preprocessors.py", + "chatterbot/filters.py", + "chatterbot/languages.py" + ], + "can_expand": true + }, + { + "name": "LLM Integration", + "description": "Provides an abstract interface for integrating Large Language Models, allowing ChatterBot to leverage advanced generative capabilities for responses.", + "referenced_source_code": [ + { + "qualified_name": "chatterbot.llm", + "reference_file": "chatterbot/llm.py", + "reference_start_line": null, + "reference_end_line": null + } + ], + "assigned_files": [ + "examples/openai_example.py", + "examples/ollama_example.py", + "chatterbot/llm.py" + ], + "can_expand": true + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [ + "examples/__init__.py", + "examples/tkinter_gui.py", + "examples/django_example/manage.py", + "examples/django_example/django_example/asgi.py", + "examples/django_example/django_example/__init__.py", + "examples/django_example/django_example/settings.py", + "examples/django_example/django_example/views.py", + "examples/django_example/django_example/wsgi.py", + "examples/django_example/django_example/urls.py", + "examples/django_example/django_example/management/__init__.py", + "examples/django_example/django_example/management/commands/__init__.py", + "docs/conf.py", + "docs/_ext/github.py", + "docs/_ext/canonical.py", + "chatterbot/__init__.py", + "chatterbot/adapters.py", + "chatterbot/__main__.py", + "chatterbot/constants.py", + "chatterbot/utils.py", + "chatterbot/exceptions.py", + "chatterbot/ext/__init__.py" + ], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + }, + { + "name": "Unclassified", + "description": "Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies)", + "referenced_source_code": [], + "assigned_files": [], + "can_expand": false + } + ], + "components_relations": [ + { + "relation": "Receives Processed Input From", + "src_name": "Chatbot Core Engine", + "dst_name": "Input/Output Processors" + }, + { + "relation": "Delegates Response Generation To", + "src_name": "Chatbot Core Engine", + "dst_name": "Logic & Response Adapters" + }, + { + "relation": "Queries Knowledge Base From", + "src_name": "Logic & Response Adapters", + "dst_name": "Data Storage & Training" + }, + { + "relation": "Persists Conversational Data To", + "src_name": "Chatbot Core Engine", + "dst_name": "Data Storage & Training" + }, + { + "relation": "Sends Prompt For Generative Response To", + "src_name": "Chatbot Core Engine", + "dst_name": "LLM Integration" + }, + { + "relation": "Provides Stored Data To", + "src_name": "Data Storage & Training", + "dst_name": "Chatbot Core Engine" + }, + { + "relation": "Provides Knowledge Base Data To", + "src_name": "Data Storage & Training", + "dst_name": "Logic & Response Adapters" + }, + { + "relation": "Returns Generative Response To", + "src_name": "LLM Integration", + "dst_name": "Chatbot Core Engine" + } + ] +} diff --git a/.codeboarding/codeboarding_version.json b/.codeboarding/codeboarding_version.json new file mode 100644 index 000000000..74ec0a22a --- /dev/null +++ b/.codeboarding/codeboarding_version.json @@ -0,0 +1,4 @@ +{ + "commit_hash": "5e800ebef9d186ef1b0a36f2f43fd6d638e8bb72", + "code_boarding_version": "0.2.0" +} diff --git a/.codeboarding/overview.rst b/.codeboarding/overview.rst new file mode 100644 index 000000000..a1fc112af --- /dev/null +++ b/.codeboarding/overview.rst @@ -0,0 +1,226 @@ +Overview +======== + +.. mermaid:: + + graph LR + Chatbot_Core_Engine["Chatbot Core Engine"] + Logic_Response_Adapters["Logic & Response Adapters"] + Data_Storage_Training["Data Storage & Training"] + Input_Output_Processors["Input/Output Processors"] + LLM_Integration["LLM Integration"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Chatbot_Core_Engine -- "Receives Processed Input From" --> Input_Output_Processors + Chatbot_Core_Engine -- "Delegates Response Generation To" --> Logic_Response_Adapters + Logic_Response_Adapters -- "Queries Knowledge Base From" --> Data_Storage_Training + Chatbot_Core_Engine -- "Persists Conversational Data To" --> Data_Storage_Training + Chatbot_Core_Engine -- "Sends Prompt For Generative Response To" --> LLM_Integration + Data_Storage_Training -- "Provides Stored Data To" --> Chatbot_Core_Engine + Data_Storage_Training -- "Provides Knowledge Base Data To" --> Logic_Response_Adapters + LLM_Integration -- "Returns Generative Response To" --> Chatbot_Core_Engine + click Chatbot_Core_Engine href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Chatbot_Core_Engine.html" "Details" + click Logic_Response_Adapters href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Logic_Response_Adapters.html" "Details" + click Data_Storage_Training href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Data_Storage_Training.html" "Details" + click Input_Output_Processors href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Input_Output_Processors.html" "Details" + click LLM_Integration href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/LLM_Integration.html" "Details" + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The ChatterBot architecture is designed around a central `Chatbot Core Engine` that orchestrates the conversational flow. User input is first handled by `Input/Output Processors` for cleaning and parsing. The processed input is then fed to the `Chatbot Core Engine`, which delegates the task of generating a response to `Logic & Response Adapters`. These adapters interact with the `Data Storage & Training` component to retrieve conversational data and knowledge. For advanced generative capabilities, the `Chatbot Core Engine` can also interact with the `LLM Integration` component. The `Data Storage & Training` component is responsible for persisting conversational data and providing training mechanisms. This modular design allows for flexible extension and customization of the chatbot's behavior and knowledge base. + +Chatbot Core Engine +^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +The central orchestrator, managing conversation flow, input processing, and response generation. It coordinates all other components. + +**Related Classes/Methods**: + +* chatterbot.ChatBot:13-361 + +Logic & Response Adapters +^^^^^^^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +A collection of specialized modules that determine how the chatbot responds to specific types of input, including statement comparison and response selection logic. + +**Related Classes/Methods**: + +* chatterbot.logic.logic_adapter.LogicAdapter:10-136 +* chatterbot.comparisons +* chatterbot.response_selection + +Data Storage & Training +^^^^^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +Manages the persistence and retrieval of conversational data (statements, responses), handles the entire training lifecycle, and loads corpus data. + +**Related Classes/Methods**: + +* chatterbot.storage.storage_adapter.StorageAdapter:4-179 +* chatterbot.trainers +* chatterbot.corpus + +Input/Output Processors +^^^^^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +Responsible for preprocessing raw user input (e.g., cleaning whitespace, parsing dates) before it reaches the core engine, and potentially post-processing responses. + +**Related Classes/Methods**: + +* chatterbot.preprocessors +* chatterbot.parsing + +LLM Integration +^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +Provides an abstract interface for integrating Large Language Models, allowing ChatterBot to leverage advanced generative capabilities for responses. + +**Related Classes/Methods**: + +* chatterbot.llm + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/.github/workflows/codeboarding-docs.yml b/.github/workflows/codeboarding-docs.yml new file mode 100644 index 000000000..5dfbae025 --- /dev/null +++ b/.github/workflows/codeboarding-docs.yml @@ -0,0 +1,146 @@ +name: CodeBoarding Documentation Update + +on: + schedule: + - cron: '0 20 * * 6' # Every Saturday at 8:00 PM UTC + workflow_dispatch: + inputs: + repository_url: + description: 'Repository URL to test with' + required: false + default: 'https://github.com/CodeBoarding/ChatterBot' + type: string + source_branch: + description: 'Source branch for generation' + required: false + default: 'master' + type: string + target_branch: + description: 'Target branch for pull request' + required: false + default: 'master' + type: string + output_format: + description: 'Output format for documentation' + required: false + default: '.rst' + type: choice + options: + - '.mdx' + - '.md' + - '.rst' + output_directory: + description: 'Output directory for documentation files' + required: false + default: '.codeboarding' + type: string + +jobs: + update-docs: + runs-on: ubuntu-latest + timeout-minutes: 45 + permissions: + contents: write + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Set branch variables + id: set-branches + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + echo "source_branch=${{ github.head_ref }}" >> $GITHUB_OUTPUT + echo "target_branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT + elif [ "${{ github.event.inputs.source_branch }}" != "" ] && [ "${{ github.event.inputs.target_branch }}" != "" ]; then + echo "source_branch=${{ github.event.inputs.source_branch }}" >> $GITHUB_OUTPUT + echo "target_branch=${{ github.event.inputs.target_branch }}" >> $GITHUB_OUTPUT + else + echo "source_branch=master" >> $GITHUB_OUTPUT + echo "target_branch=master" >> $GITHUB_OUTPUT + fi + + - name: Fetch CodeBoarding Documentation + timeout-minutes: 30 + id: codeboarding + uses: CodeBoarding/CodeBoarding-GHAction@0.1.2 + with: + repository_url: ${{ github.event.inputs.repository_url || 'https://github.com/CodeBoarding/ChatterBot' }} + source_branch: ${{ steps.set-branches.outputs.source_branch }} + target_branch: ${{ steps.set-branches.outputs.target_branch }} + output_directory: ${{ github.event.inputs.output_directory || '.codeboarding' }} + output_format: ${{ github.event.inputs.output_format || '.rst' }} + + - name: Display Action Results + run: | + echo "Documentation files created: ${{ steps.codeboarding.outputs.markdown_files_created }}" + echo "JSON files created: ${{ steps.codeboarding.outputs.json_files_created }}" + echo "Documentation directory: ${{ steps.codeboarding.outputs.output_directory }}" + echo "JSON directory: ${{ steps.codeboarding.outputs.json_directory }}" + echo "Has changes: ${{ steps.codeboarding.outputs.has_changes }}" + + - name: Check for changes + id: git-changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "has_git_changes=true" >> $GITHUB_OUTPUT + else + echo "has_git_changes=false" >> $GITHUB_OUTPUT + fi + + - name: Copy CodeBoarding documentation to architecture + if: steps.git-changes.outputs.has_git_changes == 'true' && steps.codeboarding.outputs.has_changes == 'true' + run: | + mkdir -p docs/architecture + + echo "📁 Scanning CodeBoarding directory for .rst files..." + ls -la .codeboarding/ || echo "⚠️ CodeBoarding directory not found" + + copied_files_count=0 + + for file in .codeboarding/*.rst; do + if [ -f "$file" ]; then + filename=$(basename "$file") + echo "✅ Copying: $filename to docs/architecture/" + cp "$file" "docs/architecture/$filename" + copied_files_count=$((copied_files_count + 1)) + fi + done + + echo "" + echo "📊 File copy summary:" + echo " - Total .rst files copied: $copied_files_count" + echo " - Destination: docs/architecture/" + + if [ $copied_files_count -gt 0 ]; then + echo " - Files in destination:" + ls -la docs/architecture/*.rst 2>/dev/null || echo " No .rst files found in destination" + fi + + echo "CodeBoarding documentation copied to docs/architecture/" + + - name: Commit and push changes + if: steps.git-changes.outputs.has_git_changes == 'true' && steps.codeboarding.outputs.has_changes == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add . + git commit -m "docs: update codeboarding architecture documentation + + ## 📚 Documentation Update + This commit contains updated documentation files fetched from the CodeBoarding service. + + ### 📊 Summary + - Documentation files created/updated: ${{ steps.codeboarding.outputs.markdown_files_created }} + - JSON files created/updated: ${{ steps.codeboarding.outputs.json_files_created }} + - Documentation directory: ${{ steps.codeboarding.outputs.output_directory }}/ + - JSON directory: ${{ steps.codeboarding.outputs.json_directory }}/ + - Output format: ${{ github.event.inputs.output_format || '.rst' }} + - Repository analyzed: ${{ steps.codeboarding.outputs.repo_url }} + - Destination: docs/architecture/ + + 🤖 This commit was automatically generated by the CodeBoarding documentation update workflow." + git push diff --git a/docs/architecture/Chatbot_Core_Engine.rst b/docs/architecture/Chatbot_Core_Engine.rst new file mode 100644 index 000000000..8d8ca5fbf --- /dev/null +++ b/docs/architecture/Chatbot_Core_Engine.rst @@ -0,0 +1,96 @@ +Chatbot Core Engine +=================== + +.. mermaid:: + + graph LR + Document_Ingestion["Document Ingestion"] + Text_Splitter["Text Splitter"] + Vector_Store["Vector Store"] + Embeddings_Model["Embeddings Model"] + Language_Model_LLM_["Language Model (LLM)"] + Retrieval_Chain["Retrieval Chain"] + Unclassified["Unclassified"] + Document_Ingestion -- "loads documents into" --> Text_Splitter + Text_Splitter -- "splits text for" --> Embeddings_Model + Embeddings_Model -- "generates embeddings for" --> Vector_Store + Vector_Store -- "stores embeddings from" --> Embeddings_Model + Vector_Store -- "retrieves context for" --> Retrieval_Chain + Retrieval_Chain -- "uses" --> Language_Model_LLM_ + Language_Model_LLM_ -- "answers queries using" --> Retrieval_Chain + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +This graph represents the core functionality of a document processing and question-answering system. The main flow involves ingesting documents, processing them into a searchable format, and then using a language model to answer user queries based on the ingested content. Its purpose is to provide an intelligent interface for users to retrieve information from a collection of documents. + +Document Ingestion +^^^^^^^^^^^^^^^^^^ + +Handles the loading and initial processing of various document types. + +**Related Classes/Methods**: + +* langchain_community.document_loaders.pdf.PyPDFLoader +* langchain_community.document_loaders.csv_loader.CSVLoader + +Text Splitter +^^^^^^^^^^^^^ + +Breaks down large documents into smaller, manageable chunks for efficient processing and embedding. + +**Related Classes/Methods**: + +* langchain.text_splitter.RecursiveCharacterTextSplitter + +Vector Store +^^^^^^^^^^^^ + +Stores and retrieves document embeddings, enabling semantic search. + +**Related Classes/Methods**: + +* langchain_community.vectorstores.chroma.Chroma + +Embeddings Model +^^^^^^^^^^^^^^^^ + +Generates numerical representations (embeddings) of text chunks. + +**Related Classes/Methods**: + +* langchain_community.embeddings.ollama.OllamaEmbeddings + +Language Model (LLM) +^^^^^^^^^^^^^^^^^^^^ + +Processes user queries and generates answers based on retrieved context. + +**Related Classes/Methods**: + +* langchain_community.llms.ollama.Ollama + +Retrieval Chain +^^^^^^^^^^^^^^^ + +Orchestrates the retrieval of relevant document chunks and passes them to the LLM for answer generation. + +**Related Classes/Methods**: + +* langchain.chains.retrieval.create_retrieval_chain + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/docs/architecture/Data_Storage_Training.rst b/docs/architecture/Data_Storage_Training.rst new file mode 100644 index 000000000..dc3d2cb0d --- /dev/null +++ b/docs/architecture/Data_Storage_Training.rst @@ -0,0 +1,61 @@ +Data Storage Training +===================== + +.. mermaid:: + + graph LR + Storage_Adapters["Storage Adapters"] + Training_Module["Training Module"] + Corpus_Data_Loader["Corpus Data Loader"] + Unclassified["Unclassified"] + Training_Module -- "depends on" --> Corpus_Data_Loader + Training_Module -- "writes to" --> Storage_Adapters + Training_Module -- "reads from" --> Storage_Adapters + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The ChatterBot system is structured around three core components: the `Storage Adapters`, `Training Module`, and `Corpus Data Loader`. The `Corpus Data Loader` is responsible for providing raw conversational data, which is then consumed by the `Training Module`. The `Training Module` processes this data to learn and update the chatbot's knowledge base, persisting and retrieving conversational statements through the `Storage Adapters`. This design ensures a clear separation of concerns, allowing for flexible data storage and diverse training methodologies. + +Storage Adapters +^^^^^^^^^^^^^^^^ + +Provides an abstract interface for all data persistence and retrieval operations within ChatterBot. It allows for interchangeable storage backends (e.g., SQL, NoSQL, in-memory) without affecting the core chatbot logic, managing the storage of statements, responses, and other conversational data. + +**Related Classes/Methods**: + +* chatterbot.storage.StorageAdapter + +Training Module +^^^^^^^^^^^^^^^ + +Responsible for the entire lifecycle of training the chatbot. It takes raw conversational data (corpus) and processes it to populate and update the chatbot's knowledge base, making it capable of generating responses. + +**Related Classes/Methods**: + +* chatterbot.trainers.Trainer:14-77 + +Corpus Data Loader +^^^^^^^^^^^^^^^^^^ + +Dedicated to loading and managing conversational corpus data. It provides a standardized way to access and prepare datasets that are used by the Training Module to train the chatbot, primarily through functions like `load_corpus` and `list_corpus_files`. + +**Related Classes/Methods**: + +* chatterbot.corpus:1-10 + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/docs/architecture/Input_Output_Processors.rst b/docs/architecture/Input_Output_Processors.rst new file mode 100644 index 000000000..52b5406f5 --- /dev/null +++ b/docs/architecture/Input_Output_Processors.rst @@ -0,0 +1,86 @@ +Input Output Processors +======================= + +.. mermaid:: + + graph LR + ChatterBot["ChatterBot"] + Statement["Statement"] + Preprocessors["Preprocessors"] + LogicAdapter["LogicAdapter"] + Parsing_Utilities["Parsing Utilities"] + Unclassified["Unclassified"] + ChatterBot -- "orchestrates" --> Preprocessors + ChatterBot -- "utilizes" --> LogicAdapter + ChatterBot -- "creates/processes" --> Statement + Preprocessors -- "modify" --> Statement + LogicAdapter -- "consumes/produces" --> Statement + Parsing_Utilities -- "assists" --> LogicAdapter + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The ChatterBot core subsystem is designed around a central `ChatterBot` orchestrator that manages the conversational flow. User input is encapsulated within a `Statement` object, which then undergoes a series of transformations by `Preprocessors` to clean and normalize the text. The `ChatterBot` then leverages various `Logic Adapters` to determine the most appropriate response, often utilizing `Parsing Utilities` for advanced text interpretation. The final response is also represented as a `Statement` object, completing the conversational turn. This modular design allows for flexible extension and customization of input processing, response generation, and data handling. + +ChatterBot +^^^^^^^^^^ + +The core orchestrator of the conversational system. It manages the lifecycle of a conversation, from receiving input to generating a response. It composes and utilizes preprocessors and logic adapters to achieve its functionality. + +**Related Classes/Methods**: + +* chatterbot.ChatterBot + +Statement +^^^^^^^^^ + +The fundamental data model representing a single utterance or piece of text within the conversational system. It acts as the primary data carrier, flowing through various components and being modified or consumed by them. + +**Related Classes/Methods**: + +* chatterbot.conversation.Statement:62-118 + +Preprocessors +^^^^^^^^^^^^^ + +A collection of functions responsible for applying initial transformations to an input `Statement` object. These transformations, such as cleaning whitespace, unescaping HTML, or converting to ASCII, prepare the text data for subsequent natural language processing tasks. + +**Related Classes/Methods**: + +* chatterbot.preprocessors.clean_whitespace:10-25 +* chatterbot.preprocessors.unescape_html:28-35 +* chatterbot.preprocessors.convert_to_ascii:38-47 + +LogicAdapter +^^^^^^^^^^^^ + +An abstract base class for components that define the chatbot's response generation strategy. `ChatterBot` can utilize multiple concrete implementations of `LogicAdapter` to process an input statement and select or generate a suitable response. + +**Related Classes/Methods**: + +* chatterbot.logic.logic_adapter.LogicAdapter:10-136 + +Parsing Utilities +^^^^^^^^^^^^^^^^^ + +This module contains various utilities and functions for advanced interpretation and structuring of text within statements. This includes functionalities like parsing dates, times, and numerical expressions, which are crucial for understanding user intent in complex queries. + +**Related Classes/Methods**: + +* chatterbot.parsing + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/docs/architecture/LLM_Integration.rst b/docs/architecture/LLM_Integration.rst new file mode 100644 index 000000000..7c22f50e2 --- /dev/null +++ b/docs/architecture/LLM_Integration.rst @@ -0,0 +1,75 @@ +Llm Integration +=============== + +.. mermaid:: + + graph LR + Query_Processor["Query Processor"] + Language_Model_Interface["Language Model Interface"] + Tool_Executor["Tool Executor"] + Response_Formatter["Response Formatter"] + Unclassified["Unclassified"] + Query_Processor -- "sends queries to" --> Language_Model_Interface + Language_Model_Interface -- "receives output from" --> Tool_Executor + Tool_Executor -- "invokes" --> Tool + Tool_Executor -- "sends results to" --> Response_Formatter + Response_Formatter -- "returns formatted response from" --> Query_Processor + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +This graph represents the core functionality of a system that processes user queries, generates responses using a language model, and interacts with external tools. The main flow involves receiving a query, parsing it, invoking a language model to determine the appropriate action, executing that action (which might involve using a tool), and finally formatting and returning the response to the user. Its purpose is to provide a flexible and extensible framework for building AI-powered applications that can understand and act upon user requests. + +Query Processor +^^^^^^^^^^^^^^^ + +Handles incoming user queries, including parsing and initial validation. + +**Related Classes/Methods**: + +* QueryParser:parse:302-310 + +Language Model Interface +^^^^^^^^^^^^^^^^^^^^^^^^ + +Manages interactions with the underlying language model, sending prompts and receiving generated text. + +**Related Classes/Methods**: + +* LLMClient:send_prompt:62-86 +* LLMClient:receive_response + +Tool Executor +^^^^^^^^^^^^^ + +Executes specific tools based on the language model's output, handling tool invocation and result retrieval. + +**Related Classes/Methods**: + +* ToolRegistry:get_tool +* Tool:execute + +Response Formatter +^^^^^^^^^^^^^^^^^^ + +Formats the final response to be sent back to the user, potentially combining information from the language model and tool outputs. + +**Related Classes/Methods**: + +* ResponseBuilder:build + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/docs/architecture/Logic_Response_Adapters.rst b/docs/architecture/Logic_Response_Adapters.rst new file mode 100644 index 000000000..2bab4e23d --- /dev/null +++ b/docs/architecture/Logic_Response_Adapters.rst @@ -0,0 +1,64 @@ +Logic Response Adapters +======================= + +.. mermaid:: + + graph LR + Logic_Adapters["Logic Adapters"] + Response_Selection["Response Selection"] + Comparisons["Comparisons"] + Unclassified["Unclassified"] + Logic_Adapters -- "uses" --> Comparisons + Logic_Adapters -- "provides candidate responses to" --> Response_Selection + Response_Selection -- "selects final response from" --> Logic_Adapters + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The `chatterbot` system's core conversational flow is orchestrated by `Logic Adapters` and `Response Selection`. `Logic Adapters` (represented by `chatterbot.logic.LogicAdapter` and its specialized subclasses) are responsible for interpreting user input, often leveraging `Comparisons` (such as `chatterbot.comparisons.Comparator` and its implementations) to find relevant matches within the chatbot's knowledge base. Each adapter proposes potential responses with confidence scores. These diverse responses are then consolidated by the `Response Selection` component (functions within `chatterbot.response_selection`), which applies a defined strategy to choose the most appropriate single reply, ensuring a coherent and effective conversational output. + +Logic Adapters +^^^^^^^^^^^^^^ + +This component comprises a collection of specialized modules, each implementing distinct conversational logic. Their primary role is to process user input, compare it against known statements (often utilizing comparison logic from `chatterbot.comparisons.Comparator` and its subclasses), and generate a list of potential responses based on their specific algorithms and the chatbot's knowledge base. This component embodies the "Adapter Pattern" by allowing different logic strategies to be plugged in and executed based on the conversational context. + +**Related Classes/Methods**: + +* chatterbot.comparisons.Comparator:10-34 + +Response Selection +^^^^^^^^^^^^^^^^^^ + +This component acts as an arbiter, receiving multiple candidate responses from various `Logic Adapters`. Its responsibility is to apply a selection algorithm (such as `get_first_response`, `get_most_frequent_response`, or `get_random_response` from `chatterbot.response_selection`) to evaluate these candidates and determine the single most appropriate response to be returned to the user. This component ensures that the chatbot provides a coherent and optimal reply, even when multiple logic paths suggest different answers, thereby orchestrating the final output. + +**Related Classes/Methods**: + +* chatterbot.response_selection + +Comparisons +^^^^^^^^^^^ + +This component encapsulates the logic for comparing statements, primarily used by `Logic Adapters` to assess similarity between user input and known statements. It includes various comparison algorithms like Levenshtein Distance, Spacy Similarity, and Jaccard Similarity, all stemming from `chatterbot.comparisons.Comparator`. + +**Related Classes/Methods**: + +* chatterbot.comparisons.Comparator:10-34 +* chatterbot.comparisons.LevenshteinDistance:37-71 +* chatterbot.comparisons.SpacySimilarity:74-119 +* chatterbot.comparisons.JaccardSimilarity:122-182 + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/docs/architecture/index.rst b/docs/architecture/index.rst new file mode 100644 index 000000000..5054781a9 --- /dev/null +++ b/docs/architecture/index.rst @@ -0,0 +1,14 @@ +Architecture +============ + +This section contains automatically generated architecture documentation powered by CodeBoarding. +The documentation is automatically updated weekly via GitHub Actions. + +.. note:: + These documents are auto-generated from the master branch and reflect the current state of the codebase. + +.. toctree:: + :maxdepth: 2 + :glob: + + * diff --git a/docs/architecture/overview.rst b/docs/architecture/overview.rst new file mode 100644 index 000000000..a1fc112af --- /dev/null +++ b/docs/architecture/overview.rst @@ -0,0 +1,226 @@ +Overview +======== + +.. mermaid:: + + graph LR + Chatbot_Core_Engine["Chatbot Core Engine"] + Logic_Response_Adapters["Logic & Response Adapters"] + Data_Storage_Training["Data Storage & Training"] + Input_Output_Processors["Input/Output Processors"] + LLM_Integration["LLM Integration"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Unclassified["Unclassified"] + Chatbot_Core_Engine -- "Receives Processed Input From" --> Input_Output_Processors + Chatbot_Core_Engine -- "Delegates Response Generation To" --> Logic_Response_Adapters + Logic_Response_Adapters -- "Queries Knowledge Base From" --> Data_Storage_Training + Chatbot_Core_Engine -- "Persists Conversational Data To" --> Data_Storage_Training + Chatbot_Core_Engine -- "Sends Prompt For Generative Response To" --> LLM_Integration + Data_Storage_Training -- "Provides Stored Data To" --> Chatbot_Core_Engine + Data_Storage_Training -- "Provides Knowledge Base Data To" --> Logic_Response_Adapters + LLM_Integration -- "Returns Generative Response To" --> Chatbot_Core_Engine + click Chatbot_Core_Engine href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Chatbot_Core_Engine.html" "Details" + click Logic_Response_Adapters href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Logic_Response_Adapters.html" "Details" + click Data_Storage_Training href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Data_Storage_Training.html" "Details" + click Input_Output_Processors href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/Input_Output_Processors.html" "Details" + click LLM_Integration href "https://github.com/CodeBoarding/ChatterBot/blob/master/.codeboarding/LLM_Integration.html" "Details" + +| |codeboarding-badge| |demo-badge| |contact-badge| + +.. |codeboarding-badge| image:: https://img.shields.io/badge/Generated%20by-CodeBoarding-9cf?style=flat-square + :target: https://github.com/CodeBoarding/CodeBoarding +.. |demo-badge| image:: https://img.shields.io/badge/Try%20our-Demo-blue?style=flat-square + :target: https://www.codeboarding.org/demo +.. |contact-badge| image:: https://img.shields.io/badge/Contact%20us%20-%20contact@codeboarding.org-lightgrey?style=flat-square + :target: mailto:contact@codeboarding.org + +Details +------- + +The ChatterBot architecture is designed around a central `Chatbot Core Engine` that orchestrates the conversational flow. User input is first handled by `Input/Output Processors` for cleaning and parsing. The processed input is then fed to the `Chatbot Core Engine`, which delegates the task of generating a response to `Logic & Response Adapters`. These adapters interact with the `Data Storage & Training` component to retrieve conversational data and knowledge. For advanced generative capabilities, the `Chatbot Core Engine` can also interact with the `LLM Integration` component. The `Data Storage & Training` component is responsible for persisting conversational data and providing training mechanisms. This modular design allows for flexible extension and customization of the chatbot's behavior and knowledge base. + +Chatbot Core Engine +^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +The central orchestrator, managing conversation flow, input processing, and response generation. It coordinates all other components. + +**Related Classes/Methods**: + +* chatterbot.ChatBot:13-361 + +Logic & Response Adapters +^^^^^^^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +A collection of specialized modules that determine how the chatbot responds to specific types of input, including statement comparison and response selection logic. + +**Related Classes/Methods**: + +* chatterbot.logic.logic_adapter.LogicAdapter:10-136 +* chatterbot.comparisons +* chatterbot.response_selection + +Data Storage & Training +^^^^^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +Manages the persistence and retrieval of conversational data (statements, responses), handles the entire training lifecycle, and loads corpus data. + +**Related Classes/Methods**: + +* chatterbot.storage.storage_adapter.StorageAdapter:4-179 +* chatterbot.trainers +* chatterbot.corpus + +Input/Output Processors +^^^^^^^^^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +Responsible for preprocessing raw user input (e.g., cleaning whitespace, parsing dates) before it reaches the core engine, and potentially post-processing responses. + +**Related Classes/Methods**: + +* chatterbot.preprocessors +* chatterbot.parsing + +LLM Integration +^^^^^^^^^^^^^^^ + +:ref:`Expand ` + +Provides an abstract interface for integrating Large Language Models, allowing ChatterBot to leverage advanced generative capabilities for responses. + +**Related Classes/Methods**: + +* chatterbot.llm + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* + +Unclassified +^^^^^^^^^^^^ + +Component for all unclassified files and utility functions (Utility functions/External Libraries/Dependencies) + +**Related Classes/Methods**: *None* diff --git a/docs/conf.py b/docs/conf.py index 34003cd74..30f6e0aa0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,6 +28,7 @@ 'github', 'canonical', 'sphinx_sitemap', + 'sphinxcontrib.mermaid', ] # Sphinx Sitemap Plugin Configuration diff --git a/docs/index.rst b/docs/index.rst index d15a37279..d0a42c466 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -84,6 +84,7 @@ Contents: preprocessors logic/index storage/index + architecture/index large-language-models filters chatterbot diff --git a/pyproject.toml b/pyproject.toml index d348dde90..0e3d9a2c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,6 +73,7 @@ test = [ "coverage", "sphinx>=5.3,<8.2", "sphinx-sitemap>=2.6.0", + "sphinxcontrib-mermaid", "huggingface_hub", ] dev = [