Skip to content

Commit

Permalink
docs:
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Jun 5, 2024
1 parent 0245b2b commit 195331a
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 61 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
description: set release version
required: true

permissions:
contents: write

jobs:
pypi:
Expand All @@ -19,6 +21,15 @@ jobs:
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: build docs
run: |
poetry install --with docs
python3 docs/build.py
- name: Deploy docs
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs/_build/html
- name: Publish
run: |
poetry version ${{ github.event.inputs.version }}
Expand Down
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import os
project = 'thundra'
import importlib.metadata
project = 'thundra-ai'
copyright = '2024, krypton-byte'
author = 'krypton-byte'
release = '0.1.0'
release = importlib.metadata.version('thundra-ai')
import sys
from pathlib import Path
sys.path.insert(0, Path(os.getcwd()).parent.parent.__str__())
Expand Down Expand Up @@ -39,5 +40,5 @@
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_theme = 'furo'
# html_static_path = ['_static']
36 changes: 35 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ watchfiles = "^0.22.0"
sphinx-autodoc-typehints = "^2.1.1"
sphinx = "^7.3.7"
sphinx-rtd-theme = "^2.0.0"
furo = "^2024.5.6"

[[tool.poetry.source]]
name = "thundra-ai"
Expand Down
97 changes: 69 additions & 28 deletions thundra/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Optional,
TypeVar,
Type,
Union,
)
from .core.graph import Graph
from neonize.client import NewClient
Expand Down Expand Up @@ -80,24 +81,59 @@ class OP(Enum):

@dataclass
class CommandFunc:
"""
A class representing a command function with its associated metadata.
Attributes:
name (str): The name of the command.
filter (Filter | FilterOP): The filter to determine when this command should be executed.
description (str): A description of the command.
func (Callable[[NewClient, Message]]): The function to execute for this command.
category (Sequence[str]): Categories this command belongs to.
allow_broadcast (bool): Whether this command can be used in broadcast messages.
on_error (Optional[Union[str, Callable[[NewClient, Message, Exception], None]]]): Error handler for the command.
"""
name: str
filter: Filter | FilterOP
description: str
func: Callable[[NewClient, Message]]
category: Sequence[str]
allow_broadcast: bool
on_error: Optional[str | Callable[[NewClient, Message, Exception], None]] = None
on_error: Optional[Union[str, Callable[[NewClient, Message, Exception], None]]] = None


class GlobalCommand(dict[str, CommandFunc], Graph):
"""
A class representing a global command registry that integrates with a graph.
Commands are stored in a dictionary with their names as keys, and can be executed
based on incoming messages.
Attributes:
start_point (int): The starting point for generating command names.
"""
start_point: int = 1

def get_all_names(self) -> Generator[str, None, None]:
"""
Generate the names of all commands in the registry.
:yield: The name of each command.
:rtype: Generator[str, None, None]
"""
for command in self.values():
yield command.name

@classmethod
def generate_name(cls, start_point: int):
def generate_name(cls, start_point: int) -> str:
"""
Generate a unique name based on the start point.
:param start_point: The starting point for generating the name.
:type start_point: int
:return: The generated unique name.
:rtype: str
"""
point = start_point
uid = ""
while point > 0:
Expand All @@ -107,31 +143,33 @@ def generate_name(cls, start_point: int):
return uid[::-1]

def add(self, command: CommandFunc):
"""_summary_
"""
Add a command to the registry.
:param command: _description_
:param command: The command function to be added.
:type command: CommandFunc
"""
"""
self.update({self.generate_name(self.start_point): command})
self.start_point += 1

def execute(self, client: NewClient, message: Message):
"""_summary_
def execute(self, client: NewClient, message: Message) -> bool:
"""
Execute the appropriate command based on the given message.
:param client: _description_
:param client: The client instance to use for executing the command.
:type client: NewClient
:param message: _description_
:param message: The message to process and execute the command.
:type message: Message
:raises e: _description_
:return: _description_
:rtype: _type_
"""
:raises e: If an error occurs during command execution and no error handler is provided.
:return: True if a command is executed successfully, otherwise False.
:rtype: bool
"""
for v in self.values():
if (
v.allow_broadcast
or not message.Info.MessageSource.Chat.User == "broadcast"
):
if v.filter.filter( client, message):
if v.filter.filter(client, message):
try:
v.func(client, message)
except Exception as e:
Expand All @@ -142,6 +180,7 @@ def execute(self, client: NewClient, message: Message):
else:
raise e
return True
return False

def register(
self,
Expand All @@ -150,26 +189,27 @@ def register(
description: str = "",
category: Sequence[str] = ["all"],
allow_broadcast: bool = False,
on_error: Optional[
str | Callable[[NewClient, Message, Exception], None]
] = None,
):
"""_summary_
on_error: Optional[Union[str, Callable[[NewClient, Message, Exception], None]]] = None,
) -> Callable[[Callable[[NewClient, Message], Any]], Callable[[NewClient, Message], Any]]:
"""
Register a new command with the provided parameters.
:param filter: _description_
:param filter: The filter to apply to messages for this command.
:type filter: Filterable
:param name: _description_, defaults to ""
:param name: The name of the command, defaults to the function name if not provided.
:type name: str, optional
:param description: _description_, defaults to ""
:param description: A description of the command, defaults to an empty string.
:type description: str, optional
:param category: _description_, defaults to ["all"]
:param category: The categories this command belongs to, defaults to ["all"].
:type category: Sequence[str], optional
:param allow_broadcast: _description_, defaults to False
:param allow_broadcast: Whether this command can be used in broadcast messages, defaults to False.
:type allow_broadcast: bool, optional
:param on_error: _description_, defaults to None
:type on_error: Optional[ str | Callable[[NewClient, Message, Exception], None] ], optional
"""
def command(f: Callable[[NewClient, Message], Any]):
:param on_error: An error handler for this command, defaults to None.
:type on_error: Optional[Union[str, Callable[[NewClient, Message, Exception], None]]], optional
:return: A decorator that registers the command.
:rtype: Callable[[Callable[[NewClient, Message], Any]], Callable[[NewClient, Message], Any]]
"""
def command(f: Callable[[NewClient, Message], Any]) -> Callable[[NewClient, Message], Any]:
log.debug(f"{name} command loaded")
self.add(
CommandFunc(
Expand All @@ -187,6 +227,7 @@ def command(f: Callable[[NewClient, Message], Any]):
return command



command = GlobalCommand()


Expand Down
5 changes: 0 additions & 5 deletions thundra/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
class Graph(ABC):
"""
Abstract base class representing a graph with nodes and edges.
Methods:
graph(): Generates the graph representation of the object in a specific format.
get_all_names(): Abstract method to get all node names in the graph.
combine_graph(*graphs): Class method to combine multiple graph representations into a single graph.
"""

def graph(self) -> str:
Expand Down
10 changes: 0 additions & 10 deletions thundra/core/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ class LLM:
Attributes:
chat_models (BaseChatModel): The chat model to be used.
llm_available (Event): An event to signal the availability of the LLM.
Methods:
llm():
Get the currently set language model. Waits if the model is not yet set.
llm(llm: BaseChatModel):
Set the language model and signal its availability.
available():
Check if the language model is available.
remove_llm():
Remove the currently set language model and reset its availability.
"""
chat_models: BaseChatModel

Expand Down
14 changes: 0 additions & 14 deletions thundra/storage/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ def download(self, client: NewClient, mediatype: MediaType) -> bytes:
class FileRegistry(dict[str, File]):
"""
A registry to manage files, allowing updates while maintaining a maximum number of stored files.
Methods:
update(id: str, data: File, max_data: int):
Updates the registry with a new file, ensuring the maximum number of files does not exceed `max_data`.
"""

def update(self, id: str, data: File, max_data: int): # type: ignore
Expand Down Expand Up @@ -122,16 +118,6 @@ class StorageRegistry(dict[str, FileRegistry]):
Attributes:
max_files (int): The maximum number of files allowed per user registry.
Methods:
save(user_id: str, file_id: str, file: File):
Save a file in the user's registry.
get_file(user_id: str, file_id: str) -> File:
Retrieve a specific file from the user's registry.
get_files(user_id: str) -> FileRegistry:
Retrieve all files from the user's registry.
get_files_by_type(user_id: str, types: Iterable[type]) -> Generator[File, None, None]:
Retrieve files of specific types from the user's registry.
"""
max_files: int = 10

Expand Down

0 comments on commit 195331a

Please sign in to comment.