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

feat: add missed app_id for workflow #180

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

wildfeds
Copy link
Contributor

@wildfeds wildfeds commented Jan 27, 2025

Pretty straight forward change. Currently the demo code (https://www.coze.com/open/playground/workflow_run), Python section, gives an error:

got error error_code=4000 error_message='App not found. Please verify the app_id is correct and ensure the app has been published.'

Summary by CodeRabbit

  • New Features
    • Added optional app_id parameter to workflow streaming methods, providing more flexibility in specifying application context for workflow execution.

Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces an optional app_id parameter to the stream methods in both WorkflowsRunsClient and AsyncWorkflowsRunsClient classes. This modification allows for more flexible specification of the application context during workflow execution. The change is implemented by adding the app_id parameter to the method signatures, with a default value of None, ensuring backward compatibility with existing code.

Changes

File Change Summary
cozepy/workflows/runs/__init__.py Added optional app_id parameter to stream methods in WorkflowsRunsClient and AsyncWorkflowsRunsClient classes

Possibly related issues

  • coze-dev/coze-py#179: Directly addresses the issue of adding app_id support to the WorkflowsRunClient.stream() method, resolving the error related to app identification

Poem

🐰 A Rabbit's Ode to App Context 🚀

In workflows where streams flow free,
An app_id joins the API spree
Flexibility leaps with grace so bright
Connecting contexts, pure delight!
Code hops forward, no more restraint

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

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

🔭 Outside diff range comments (1)
cozepy/workflows/runs/__init__.py (1)

Line range hint 332-337: Add app_id parameter to async stream method.

The async version of the stream method is missing the app_id parameter, which would cause it to fail with the same "App not found" error. The sync and async implementations should maintain parity.

Apply this diff to add the parameter and update the body:

    async def stream(
        self,
        *,
        workflow_id: str,
        parameters: Optional[Dict[str, Any]] = None,
        bot_id: Optional[str] = None,
+       app_id: Optional[str] = None,
        ext: Optional[Dict[str, Any]] = None,
    ) -> AsyncIterator[WorkflowEvent]:
        url = f"{self._base_url}/v1/workflow/stream_run"
        body = {
            "workflow_id": workflow_id,
            "parameters": parameters,
            "bot_id": bot_id,
+           "app_id": app_id,
            "ext": ext,
        }

Don't forget to add the parameter documentation to the docstring as well.

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

202-203: Add documentation for the app_id parameter.

The app_id parameter is missing from the method's docstring. Please add the parameter documentation to maintain consistency with other parameters.

Add this to the docstring:

        :param bot_id: The associated Bot ID required for some workflow executions,
        such as workflows with database nodes, variable nodes, etc.
+       :param app_id: The ID of the application to execute the workflow under.
        :param ext: Used to specify some additional fields in the format of Map[String][String].
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9c6b55 and 4077171.

📒 Files selected for processing (1)
  • cozepy/workflows/runs/__init__.py (2 hunks)
🔇 Additional comments (1)
cozepy/workflows/runs/__init__.py (1)

202-203: Verify app_id requirements from API documentation.

Please verify the following from the API documentation:

  1. Are there any specific format requirements for app_id?
  2. Is app_id required for specific workflow types?
  3. Are there any constraints or limitations when using app_id?

This information would be valuable for adding proper validation and documentation.

Also applies to: 223-223

✅ Verification successful

The app_id parameter is properly documented and implemented

The codebase shows consistent usage of app_id:

  • It's documented as "The ID of the app that the API interacts with"
  • Implementation accepts hex string values (as shown in tests)
  • Type hints are correctly used (Optional[str] for workflows)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if app_id requirements are documented in README or API docs

# Look for app_id documentation in markdown files
echo "Searching for app_id documentation..."
rg -i "app.?id" --type md -C 3

# Look for app_id validation in Python files
echo "Checking for existing app_id validation..."
rg -i "app.?id.*validation|validate.*app.?id" --type py -C 3

Length of output: 275


Script:

#!/bin/bash
# Search for app_id usage patterns in Python files
echo "Searching for app_id usage in Python files..."
rg -i "app_id" --type py -C 2

# Search for test files containing app_id
echo "Searching for app_id in test files..."
rg -i "app_id" -g "*test*.py" -C 2

# Search for function definitions with app_id parameter
echo "Searching for function definitions with app_id..."
ast-grep --pattern 'def $_(self, $$$, app_id: $_,$$$):'

Length of output: 7289

@chyroc chyroc added the bug Something isn't working label Jan 28, 2025
Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.01%. Comparing base (c9c6b55) to head (4077171).
Report is 1 commits behind head on main.

@@           Coverage Diff           @@
##             main     #180   +/-   ##
=======================================
  Coverage   90.01%   90.01%           
=======================================
  Files          65       65           
  Lines        5840     5840           
=======================================
  Hits         5257     5257           
  Misses        583      583           
Files with missing lines Coverage Δ
cozepy/workflows/runs/__init__.py 100.00% <ø> (ø)

@chyroc chyroc changed the title Fix the Python SDK for WorkflowsRunsClient to pass app_id in the body fix: add missed app_id for workflow Jan 28, 2025
@chyroc chyroc added feature and removed bug Something isn't working labels Jan 28, 2025
@chyroc chyroc changed the title fix: add missed app_id for workflow feat: add missed app_id for workflow Jan 28, 2025
@chyroc chyroc merged commit 86956f9 into coze-dev:main Jan 28, 2025
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants