Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature Pack #363

Merged
merged 47 commits into from Jan 17, 2024
Merged

Feature Pack #363

merged 47 commits into from Jan 17, 2024

Conversation

sudoskys
Copy link
Member

@sudoskys sudoskys commented Nov 16, 2023

📚 docs/app.md

Summary by CodeRabbit

  • Chores

    • Removed outdated configurations and updated connection settings for various services.
    • Updated release drafter configuration with new issue categorization labels.
    • Renamed and updated testing workflows for Python using PDM.
    • Added linting, formatting, and code quality hooks to the pre-commit configuration.
    • Downgraded Python version, switched package management to PDM, and adjusted dependencies in the Dockerfile.
    • Updated commands and recommendations for dependency management in README files.
    • Expanded app documentation to cover the implementation of an OpenAI Assistant and its limitations.
  • Refactor

    • Enhanced error message generation and security in error.py.
    • Made adjustments to import statements, function, and class in various modules.
  • Tests

    • Added new test cases for RouterCache and Router classes.
  • Documentation

    • Expanded the app documentation to include new sections on self-regulation, advantages of language models, applicability, and whether strict matching is necessary for release chains.

@sudoskys sudoskys self-assigned this Nov 16, 2023
Copy link
Contributor

coderabbitai bot commented Nov 16, 2023

Walkthrough

The recent changes encompass a variety of updates across the project. The .env.exp file has undergone configuration updates and removals. The release drafter configuration in release-drafter.yml now includes new issue categorization labels. The python_test.yml workflow has been modified to use PDM for Python and dependency installation. Additionally, the Dockerfile has seen changes in Python version, package management, and installation steps. Several Python files and tests have been updated with formatting, method changes, and new functionality.

Changes

File Change Summary
.env.exp Removed commented-out configurations and updated various DSN configurations.
.github/release-drafter.yml Introduced new issue categorization labels.
.github/workflows/python_test.yml Modified to use PDM for Python and dependency installation.
Dockerfile Downgraded Python version, switched to PDM for package management, adjusted installations, and modified volume declarations.
README.md Updated commands and recommendations for using PDM over Poetry for dependency management.
README_EN.md Updated command for running the application to use Poetry for managing dependencies.
docs/app.md Added sections on self-reflection, language model advantages, applicability, and release chain matching requirements.
llmkira/error.py Updated formatting method and error message generation.
llmkira/... (multiple files) Various updates including code adjustments, formatting, and method changes.
tests/test_chain_box.py Changes to import statements and addition of a thead_uuid parameter.
tests/test_router.py Introduces a test case for the RouterCache and Router classes.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@sudoskys sudoskys added the New Features New feature or request label Nov 16, 2023
@sudoskys sudoskys marked this pull request as draft November 16, 2023 16:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between abb146d and 515b6f1.
Files selected for processing (1)
  • docs/app.md (1 hunks)
Additional comments: 1
docs/app.md (1)
  • 372-381: The new section headers added to the documentation are indicative of the expanded content and features of the application. It is important to ensure that the content under each new section is comprehensive and aligns with the section headers. Additionally, the use of Chinese language for the headers suggests that the documentation may be multilingual or region-specific, which should be consistent throughout the document.

@sudoskys
Copy link
Member Author

沉淀

@sudoskys sudoskys linked an issue Nov 16, 2023 that may be closed by this pull request
In this commit, the send_message method in the ChainFunc class is wrapped with a new method to handle sending messages. This is done to improve code organization and readability.
Updated the instructions in the README.md file to use `pdm` as the dependency manager instead of `poetry`. This change was made to prevent version conflicts with the `pydantic^1.9.0` library.
Updated the start commands for llm_sender and llm_receiver in the pm2.json
file. Now using "sleep 3" instead of "sleep 6" and "python -m" instead of
"poetry run python3".
Updated the start commands for llm_sender and llm_receiver in the pm2.json
file. Now using "sleep 3" instead of "sleep 6" and "python -m" instead of
"poetry run python3".
chore: Remove unused dependencies in pdm.lock
chore: Remove unused dependencies in pdm.lock
chore: Remove unused dependencies in pdm.lock
♻️ chore(python_test.yml): change pdm sync command
♻️ chore(python_test.yml): change pdm sync command
♻️ chore(python_test.yml): change pdm sync command
♻️ chore(python_test.yml): change pdm sync command
♻️ chore(python_test.yml): change pdm sync command
♻️ chore(python_test.yml): change pdm sync command
- Wrap the sending of a message in the notify_user method of the ChainFunc class.
…or maintenance

and 'Slow progress' label for plugin updates

The commit adds new labels to improve issue categorization and tracking.
- Fixed line formatting in function.py to improve readability.
- Fixed line formatting in receiver_client.py to improve readability and
  consistency.
Updated the llmkira/task/schema.py file to include additional imports and make some changes to the code.
Adding pre-commit hooks to the project for performing code quality checks
using pre-commit framework. This includes hooks for trailing whitespace,
end-of-file fixer, YAML validation, and checking added large files. Also
includes hooks from ruff-pre-commit for linting and formatting.
@sudoskys sudoskys marked this pull request as ready for review January 17, 2024 02:53
@sudoskys sudoskys merged commit 6185b1a into main Jan 17, 2024
4 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 15

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 515b6f1 and 02cc230.
Files ignored due to path filters (4)
  • docs/SeriveProvider.svg is excluded by: !**/*.svg
  • pdm.lock is excluded by: !**/*.lock
  • pm2.json is excluded by: !**/*.json
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (23)
  • .env.exp (2 hunks)
  • .github/release-drafter.yml (1 hunks)
  • .github/workflows/python_test.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • Dockerfile (1 hunks)
  • README.md (2 hunks)
  • README_EN.md (1 hunks)
  • docs/app.md (1 hunks)
  • llmkira/error.py (4 hunks)
  • llmkira/extra/plugins/search.py (11 hunks)
  • llmkira/middleware/chain_box/init.py (4 hunks)
  • llmkira/middleware/chain_box/schema.py (2 hunks)
  • llmkira/middleware/llm_task.py (1 hunks)
  • llmkira/receiver/function.py (10 hunks)
  • llmkira/receiver/receiver_client.py (2 hunks)
  • llmkira/receiver/telegram/init.py (5 hunks)
  • llmkira/sdk/cache/redis.py (3 hunks)
  • llmkira/sdk/func_calling/schema.py (1 hunks)
  • llmkira/sdk/openapi/fuse/init.py (1 hunks)
  • llmkira/sender/util_func.py (3 hunks)
  • llmkira/task/schema.py (14 hunks)
  • tests/test_chain_box.py (2 hunks)
  • tests/test_router.py (1 hunks)
Files skipped from review due to trivial changes (4)
  • .github/release-drafter.yml
  • llmkira/receiver/receiver_client.py
  • llmkira/receiver/telegram/init.py
  • llmkira/sender/util_func.py
Additional comments: 28
.pre-commit-config.yaml (1)
  • 10-18: The addition of the ruff-pre-commit repository with hooks for linting and formatting is a good practice for maintaining code quality.
.github/workflows/python_test.yml (1)
  • 13-32: The updates to the workflow file to use PDM for Python setup and dependency installation are consistent with the move towards using PDM as the package manager.
Dockerfile (1)
  • 2-31: The changes in the Dockerfile, including the downgrade of the Python version and the switch from Poetry to PDM for package management, are consistent and well-structured.
.env.exp (1)
  • 6-18: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-23]

The updates to the .env.exp file, including the removal of commented-out configurations and updates to DSN configurations, are clear and should not affect existing functionality if the environment variables are set correctly.

tests/test_chain_box.py (1)
  • 7-25: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [10-37]

The changes in tests/test_chain_box.py, including the addition of a thead_uuid parameter in the test_schema function, are appropriate and align with the updates to the Chain class.

llmkira/sdk/cache/redis.py (2)
  • 38-40: The reformatting of the set method call in RedisClientWrapper improves readability and is consistent with best practices.
  • 75-77: The reformatting of the lrange method call is also an improvement for readability.
llmkira/error.py (2)
  • 62-62: The use of MappingDefault for safer string formatting in error messages is a good practice to avoid potential security issues with direct string interpolation.
  • 83-83: The update to the get_upload_error_message function to use MappingDefault for formatting is consistent with the changes made to get_request_error_message.
llmkira/middleware/chain_box/schema.py (1)
  • 15-27: The addition of the thead_uuid field and the updates to the descriptions of existing fields in the Chain class are clear and enhance the documentation of the class.
llmkira/middleware/chain_box/__init__.py (3)
  • 25-25: Updating the authentication schema version in the _prefix class method is a good practice for versioning and maintaining backward compatibility.
  • 70-70: The change in the _prefix instance method to reflect the new authentication schema version is consistent with the class method change.
  • 55-55: The addition of logging statements to indicate authentication and chain expiration helps with debugging and monitoring the system.
README.md (3)
  • 106-106: The update to the testing commands to use pdm reflects the switch to PDM for dependency management and is consistent with the changes in other files.
  • 154-157: The instructions for manual installation using pdm are clear and provide the necessary steps for setting up the project.
  • 165-165: The recommendation to use pdm for dependency management is well-justified and aligns with the project's move to PDM.
docs/app.md (1)
  • 375-447: The extensive changes in docs/app.md provide a comprehensive overview of the OpenAI Assistant implementation, including discussions on language model advantages, the necessity of strong matching in release chains, and platform-specific support for plugins and channels.
llmkira/extra/plugins/search.py (2)
  • 15-23: The addition of # noqa: E402 comments to the import statements is a common practice to tell linters to ignore certain rules, in this case, the rule that enforces imports to be at the top of the file. This is acceptable if there's a specific reason for imports to be placed after some initial code (e.g., to avoid circular imports or to set up some environment variables before importing).
  • 91-140: The update to the keywords list in the SearchTool class is a logical change that seems to be adding more terms to trigger the search functionality. This is a straightforward enhancement to the tool's capabilities.
llmkira/sdk/func_calling/schema.py (1)
  • 90-91: Converting the env_help_docs method from an instance method to a class method is a good practice when the method does not depend on the instance state. This allows the method to be called on the class itself rather than on an instance, which can be more convenient and appropriate for utility methods like this one.
llmkira/receiver/function.py (4)
  • 25-27: The reply_user method's signature has been updated to take keyword-only arguments, which is a good practice for clarity and to prevent errors when calling the method with multiple parameters.
  • 52-60: The auth_chain method's logic for handling chain registration and routing appears to be correct and follows the expected flow for an authentication chain within the application's context.
  • 66-97: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [94-106]

The resign_chain method's additional parameters and logic for chain resigning are appropriate for the context of the application. The method's logic is consistent with the expected behavior for resigning a chain.

  • 241-249: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [235-246]

The process_function_call method's logic for parsing and running functions based on incoming messages is well-structured and follows the expected flow for processing function calls within the application.

llmkira/task/schema.py (4)
  • 13-13: The addition of the shortuuid import is appropriate for generating unique identifiers.
  • 129-132: The task_uuid property correctly returns the UUID part of the sign_as tuple.
  • 249-249: The child method correctly increments the first element of the sign_as tuple to denote a child node.
  • 261-261: The chain method correctly increments the first element of the sign_as tuple and resets message routing flags.

@@ -110,7 +110,7 @@ Both the authentication component and the backend need to be implemented by your

Read the [🧀 Deployment Documentation](https://llmkira.github.io/Docs/) for more information.

Please use `python3 start_sender.py` `python3 start_receiver.py` to test whether it can run normally.
Please use `poetry run python3 start_sender.py` `poetry run python3 start_receiver.py` to test whether it can run normally.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command instructions for running the application have been updated to use poetry, but it's important to ensure that the poetry dependency management tool is mentioned in the prerequisites or installation instructions within the README. If it's not already included, users may encounter issues when trying to run the commands without having poetry installed.

)


@resign_plugin_executor(function=search)
def search_on_duckduckgo(search_sentence: str, key_words: str = None):
logger.debug(f"Plugin --search_on_duckduckgo {search_sentence}")
from duckduckgo_search import DDGS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out code related to NLP optimization and the Sublimate class should be removed if it's no longer needed. Leaving commented-out code can lead to confusion and clutter in the codebase.

-    # 内存优化抛弃 NLP
-    # from llmkira.sdk.filter import Sublimate

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change

Comment on lines +146 to +153
from duckduckgo_search import DDGS # noqa: F401

# from llmkira.sdk.filter import Sublimate
return True
except ImportError as e:
logger.warning(f"plugin:package <duckduckgo_search> not found,please install it first:{e}")
logger.warning(
f"plugin:package <duckduckgo_search> not found,please install it first:{e}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pre_check method is catching an ImportError and logging a warning, but it should also handle the error appropriately by either raising an exception or returning a value that indicates the check failed. This is important for the robustness of the application.

+            return False

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
from duckduckgo_search import DDGS # noqa: F401
# from llmkira.sdk.filter import Sublimate
return True
except ImportError as e:
logger.warning(f"plugin:package <duckduckgo_search> not found,please install it first:{e}")
logger.warning(
f"plugin:package <duckduckgo_search> not found,please install it first:{e}"
)
from duckduckgo_search import DDGS # noqa: F401
# from llmkira.sdk.filter import Sublimate
return True
except ImportError as e:
logger.warning(
f"plugin:package <duckduckgo_search> not found,please install it first:{e}"
)
return False

Comment on lines +170 to +180
async def failed(
self,
task: "TaskHeader",
receiver: "TaskHeader.Location",
exception,
env: dict,
arg: dict,
pending_task: "TaskBatch",
refer_llm_result: dict = None,
**kwargs,
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failed method is designed to handle task failures, but it currently does not seem to handle the exception in any meaningful way. It should at least log the exception or take some action to notify the system of the failure.

+            logger.error(f"Task failed due to exception: {exception}")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def failed(
self,
task: "TaskHeader",
receiver: "TaskHeader.Location",
exception,
env: dict,
arg: dict,
pending_task: "TaskBatch",
refer_llm_result: dict = None,
**kwargs,
):
async def failed(
self,
task: "TaskHeader",
receiver: "TaskHeader.Location",
exception,
env: dict,
arg: dict,
pending_task: "TaskBatch",
refer_llm_result: dict = None,
**kwargs,
):
logger.error(f"Task failed due to exception: {exception}")

Comment on lines +236 to +245
async def callback(
self,
task: "TaskHeader",
receiver: "TaskHeader.Location",
env: dict,
arg: dict,
pending_task: "TaskBatch",
refer_llm_result: dict = None,
**kwargs,
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback method is currently a stub that simply returns True. It would be beneficial to implement actual logic for the callback or remove it if it's not needed. If the method is required but not yet implemented, consider adding a TODO comment to indicate future work.

+            # TODO: Implement callback logic or remove if not needed

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def callback(
self,
task: "TaskHeader",
receiver: "TaskHeader.Location",
env: dict,
arg: dict,
pending_task: "TaskBatch",
refer_llm_result: dict = None,
**kwargs,
):
async def callback(
self,
task: "TaskHeader",
receiver: "TaskHeader.Location",
env: dict,
arg: dict,
pending_task: "TaskBatch",
refer_llm_result: dict = None,
**kwargs,
):
# TODO: Implement callback logic or remove if not needed

@@ -547,7 +556,7 @@
消息标准化
"""
if not _message:
raise ValueError(f"Message is empty")
raise ValueError("Message is empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "Message is empty" is repeated here for Discord messages. It should also be made more descriptive.

- raise ValueError("Message is empty")
+ raise ValueError("The provided Discord message is empty and cannot be processed.")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
raise ValueError("Message is empty")
raise ValueError("The provided Discord message is empty and cannot be processed.")

@@ -630,7 +639,7 @@
消息标准化
"""
if not _message:
raise ValueError(f"Message is empty")
raise ValueError("Message is empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, the error message "Message is empty" is used for Kook messages. It should be updated for consistency and clarity.

- raise ValueError("Message is empty")
+ raise ValueError("The provided Kook message is empty and cannot be processed.")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
raise ValueError("Message is empty")
raise ValueError("The provided Kook message is empty and cannot be processed.")

@@ -713,7 +722,7 @@
消息标准化
"""
if not _message:
raise ValueError(f"Message is empty")
raise ValueError("Message is empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "Message is empty" is used for Slack messages. Update it to be more descriptive and consistent with the other changes.

- raise ValueError("Message is empty")
+ raise ValueError("The provided Slack message is empty and cannot be processed.")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
raise ValueError("Message is empty")
raise ValueError("The provided Slack message is empty and cannot be processed.")

Comment on lines +12 to +25
def test_schema():
r1 = RouterCache(router=[])
print("\n")
print(r1)
try:
RouterCache(router=None)
except Exception:
pass
else:
assert False, "Should Raise Error"

r3 = Router(from_="from", to_="to", user_id=2200, rules="rule there", method="chat")
print("\n")
print(r3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the print statements from the test cases. Print statements are generally not used in tests as test runners will typically capture and display output from tests separately.

Comment on lines +56 to +57
if Exception in exclude_exceptions or BaseException in exclude_exceptions:
raise ValueError("Exception and BaseException cant be exclude")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for Exception and BaseException in the exclude_exceptions list is a good security practice to prevent broad exception handling, but the error message could be more descriptive.

- raise ValueError("Exception and BaseException cant be exclude")
+ raise ValueError("Exception and BaseException cannot be excluded from the exclude_exceptions list")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if Exception in exclude_exceptions or BaseException in exclude_exceptions:
raise ValueError("Exception and BaseException cant be exclude")
if Exception in exclude_exceptions or BaseException in exclude_exceptions:
raise ValueError("Exception and BaseException cannot be excluded from the exclude_exceptions list")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Features New feature or request
Projects
None yet
1 participant