Skip to content

Commit

Permalink
docs: updated docstrings for all modules, functions in the application (
Browse files Browse the repository at this point in the history
#85)

## Description
Updated documentation of all modules in application, adopting
Google-style docstrings. This PR enables future introduction of
automatic documentation for the project (which is planned to be
introduced in further updates).

## Type of change
- [X] Documentation update

## How Has This Been Tested?
- All local tests pass

## Checklist:
- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my own code
- [X] I have commented my code, particularly in hard-to-understand areas
- [X] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [X] I have added tests that prove my fix is effective or that my
feature works
- [X] New and existing unit tests pass locally with my changes

## Related Issues
- 
## Additional Notes
-

## Automated PR Description
### Commits in this PR:

- **571b1fa** docs: updated docstrings for all modules, functions in the
application
  • Loading branch information
alexander-zuev authored Oct 19, 2024
2 parents 0812c67 + 571b1fa commit 60390c0
Show file tree
Hide file tree
Showing 17 changed files with 1,265 additions and 368 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ See the [LICENSE](LICENSE.md) file for the full license text and additional cond

The project has been renamed from **OmniClaude** to **Kollektiv** to:
- avoid confusion / unintended copyright infringement of Anthropic
- emphasize the goal to become a tool to enhance collaboration through simplifying access to knowledge
- emphasize the goal to become a tool to enhance collaboration through simplifying access to knowledge
- overall cool name (isn't it?)

If you have any questions regarding the renaming, feel free to reach out.
Expand Down
103 changes: 87 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import chainlit as cl

from src.core.component_initializer import ComponentInitializer
from src.ui.terminal_ui import run_terminal_ui
from src.utils.decorators import base_error_handler
from src.utils.logger import configure_logging
from src.utils.logger import configure_logging, get_logger

logger = get_logger()


@base_error_handler
def setup_chainlit():
"""
Set up and initialize the Chainlit environment.
Args:
None
Returns:
ClaudeAssistant: An instance of the ClaudeAssistant initialized with the specified documents.
Raises:
BaseError: If there is an error during the initialization process.
"""
docs = [
"docs_anthropic_com_en_20240928_135426-chunked.json",
"langchain-ai_github_io_langgraph_20240928_210913-chunked.json",
]
initializer = ComponentInitializer(reset_db=False, load_all_docs=False, files=docs)
claude_assistant = initializer.init()
return claude_assistant


@base_error_handler
Expand All @@ -13,29 +40,73 @@ def main(debug: bool = False, reset_db: bool = False):
debug (bool): Defines if debug mode should be enabled.
reset_db (bool): Indicates whether the database should be reset.
Raises:
SomeCustomException: Raises a custom exception if an error occurs during initialization.
Returns:
None
"""
# Configure logging before importing other modules
configure_logging(debug=debug)

# TODO: allow users to select documents locally or pull from a db
docs = [
"docs_anthropic_com_en_20240928_135426-chunked.json",
"langchain-ai_github_io_langgraph_20240928_210913-chunked.json",
# "docs_ragas_io_en_stable_20241015_112520-chunked.json",
]

# Initialize components
initializer = ComponentInitializer(reset_db=reset_db, load_all_docs=False, files=docs)
claude_assistant = initializer.init()

claude_assistant = setup_chainlit()
run_terminal_ui(claude_assistant)


if __name__ == "__main__": # D100
# TODO: reset DB should be a command a user can use
# Initialize the assistant when the Chainlit app starts
assistant = setup_chainlit()


@cl.on_chat_start
async def on_chat_start():
"""
Handle the chat start event and send initial welcome messages.
Args:
None
Returns:
None
"""
await cl.Message(content="Hello! I'm Kollektiv, sync any web content and let's chat!").send()


@cl.on_message
async def handle_message(message: cl.Message):
"""
Handle an incoming message from the CL framework.
Args:
message (cl.Message): The message object containing the user's input.
Returns:
None
"""
if assistant is None:
logger.error("Assistant instance is not initialized.")
await cl.Message(content="Error: Assistant is not initialized.").send()
return

response = assistant.get_response(user_input=message.content, stream=True)

current_message = cl.Message(content="")
await current_message.send()

tool_used = False

for event in response:
if event["type"] == "text":
if tool_used:
# If a tool was used, start a new message for the assistant's response
current_message = cl.Message(content="")
await current_message.send()
tool_used = False
await current_message.stream_token(event["content"])
elif event["type"] == "tool_use":
tool_name = event.get("tool", "Unknown tool")
await cl.Message(content=f"🛠️ Using {tool_name} tool.").send()
tool_used = True

await current_message.update()


if __name__ == "__main__":
main(debug=False, reset_db=False)
97 changes: 0 additions & 97 deletions chainlit_app.py

This file was deleted.

147 changes: 0 additions & 147 deletions chainlit_poc.py

This file was deleted.

Loading

0 comments on commit 60390c0

Please sign in to comment.