Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: Add app_id support to workflow #181

Merged
merged 1 commit into from
Feb 6, 2025
Merged

feat: Add app_id support to workflow #181

merged 1 commit into from
Feb 6, 2025

Conversation

chyroc
Copy link
Collaborator

@chyroc chyroc commented Feb 6, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an optional application identifier for workflow executions, providing greater flexibility.
    • Enhanced request handling by automatically excluding empty values, ensuring smoother operations.
    • Improved examples to dynamically retrieve workflow ID and parameters from environment variables, allowing for external configuration.
  • Bug Fixes
    • Simplified the mock request structure in tests to better simulate API behavior.

Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

The changes update the cozepy/workflows/runs/__init__.py file by adding an app_id parameter to the create methods in both WorkflowsRunsClient and AsyncWorkflowsRunsClient classes. The modification includes updating method signatures, docstrings, and request payloads. The payload now filters out None values using the remove_none_values utility function. An import statement for this utility function has also been added. Additionally, the test file tests/test_workflows.py has been simplified by removing certain parameters from the mock request structure.

Changes

File Path Change Summary
cozepy/workflows/runs/init.py - Added app_id parameter to create methods in both WorkflowsRunsClient and AsyncWorkflowsRunsClient.
- Updated docstrings accordingly.
- Modified request payload processing to use remove_none_values to filter out None values.
- Added import for remove_none_values from cozepy/util.
tests/test_workflows.py - Removed parameters, bot_id, and ext from the JSON payload in mock_create_workflows_runs function, simplifying the mock request structure.
examples/workflow_async.py - Consolidated import statements by adding Coze and TokenAuth from cozepy.
examples/workflow_stream.py - Updated workflow_id to be retrieved from the environment variable COZE_WORKFLOW_ID with a fallback value.
- Introduced parameters variable from COZE_PARAMETERS environment variable.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant SyncClient as WorkflowsRunsClient
    participant AsyncClient as AsyncWorkflowsRunsClient
    participant Util as remove_none_values
    participant Server

    Note over User: Synchronous flow
    User->>SyncClient: create(workflow_id, parameters, bot_id, app_id)
    SyncClient->>Util: remove_none_values(payload)
    Util-->>SyncClient: cleansed payload
    SyncClient->>Server: send request with cleansed payload

    Note over User: Asynchronous flow
    User->>AsyncClient: create(workflow_id, parameters, bot_id, app_id)
    AsyncClient->>Util: remove_none_values(payload)
    Util-->>AsyncClient: cleansed payload
    AsyncClient->>Server: send async request with cleansed payload
Loading

Possibly related PRs

Poem

Hoppin' through the code, I found a change so bright,
A little app_id scurries in, making workflows light.
With clean payloads and rabbits in the mix,
We trim the None values with our neat tricks.
CodeRabbit hops on, with whiskers at full swing!
🐇💻

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@chyroc chyroc added the feature label Feb 6, 2025
Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cozepy/workflows/runs/__init__.py (1)

183-184: Enhance the docstring for app_id parameter.

The docstring for app_id is incomplete. Please provide more details about:

  • What types of workflow executions require an app_id
  • Whether it's optional or required for specific scenarios
  • Any constraints or format requirements for the app_id value
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03e5312 and dd640e7.

📒 Files selected for processing (1)
  • cozepy/workflows/runs/__init__.py (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (Python 3.8 on macOS)
🔇 Additional comments (4)
cozepy/workflows/runs/__init__.py (4)

9-9: LGTM!

The import of remove_none_values is correctly placed and consistently used throughout the code to clean up request payloads.


166-166: LGTM!

The implementation of app_id support is consistent across methods and includes proper payload cleaning using remove_none_values.

Also applies to: 193-193, 197-197, 205-205, 228-228, 236-236


317-317: Enhance the docstring for app_id parameter.

The docstring for app_id in the async methods is incomplete. Please provide more details about:

  • What types of workflow executions require an app_id
  • Whether it's optional or required for specific scenarios
  • Any constraints or format requirements for the app_id value

Also applies to: 353-353


300-300: LGTM!

The implementation of app_id support in async methods mirrors the synchronous implementation, maintaining consistency across the codebase.

Also applies to: 327-327, 331-331, 339-339, 362-362, 370-370

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.02%. Comparing base (03e5312) to head (5ce228b).
Report is 1 commits behind head on main.

@@           Coverage Diff           @@
##             main     #181   +/-   ##
=======================================
  Coverage   90.02%   90.02%           
=======================================
  Files          65       65           
  Lines        5845     5845           
=======================================
  Hits         5262     5262           
  Misses        583      583           
Files with missing lines Coverage Δ
cozepy/workflows/runs/__init__.py 100.00% <100.00%> (ø)
tests/test_workflows.py 100.00% <ø> (ø)

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
examples/workflow_stream.py (1)

22-24: Consider adding error handling for JSON parsing.

While the default empty object fallback is good, invalid JSON in COZE_PARAMETERS would raise a JSONDecodeError.

-parameters = json.loads(os.getenv("COZE_PARAMETERS") or "{}")
+try:
+    parameters = json.loads(os.getenv("COZE_PARAMETERS") or "{}")
+except json.JSONDecodeError:
+    print("Warning: Invalid JSON in COZE_PARAMETERS, using empty object")
+    parameters = {}
cozepy/workflows/runs/__init__.py (2)

166-166: Add more details to the app_id parameter documentation.

The current documentation is incomplete. Consider adding information about when app_id is required and its purpose.

-        :param app_id: The app_id is required for some workflow executions,
+        :param app_id: The application ID required for workflow executions that interact with specific
+        application resources or require application-level context. This is typically needed for workflows
+        that access application-specific data or integrate with application-specific services.

Also applies to: 183-183


219-219: Add more details to the stream method's app_id documentation.

The app_id documentation in the stream methods should be as detailed as the create methods.

-        :param app_id: The app_id is required for some workflow executions,
+        :param app_id: The application ID required for workflow executions that interact with specific
+        application resources or require application-level context. This is typically needed for workflows
+        that access application-specific data or integrate with application-specific services.

Also applies to: 353-353

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f730696 and 5ce228b.

📒 Files selected for processing (4)
  • cozepy/workflows/runs/__init__.py (10 hunks)
  • examples/workflow_async.py (1 hunks)
  • examples/workflow_stream.py (3 hunks)
  • tests/test_workflows.py (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/test_workflows.py
✅ Files skipped from review due to trivial changes (1)
  • examples/workflow_async.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (Python 3.8 on Windows)
🔇 Additional comments (5)
examples/workflow_stream.py (2)

5-5: LGTM!

The json import is correctly added to support JSON parsing of parameters.


50-50: LGTM!

The parameters are correctly passed to the stream method.

cozepy/workflows/runs/__init__.py (3)

9-9: LGTM!

The remove_none_values utility is correctly imported for payload sanitization.


197-197: LGTM!

The remove_none_values utility is correctly used to sanitize request payloads, ensuring no None values are sent to the API.

Also applies to: 236-237, 370-371


193-194: LGTM!

The app_id parameter is consistently added to all relevant request payloads across both synchronous and asynchronous implementations.

Also applies to: 227-229, 327-328, 362-363

@chyroc chyroc merged commit d4a6995 into main Feb 6, 2025
14 checks passed
@chyroc chyroc deleted the add-miss-app-id branch February 6, 2025 06:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant