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

Added code to change loop input to jinja input #171

Merged
merged 2 commits into from
Feb 13, 2025

Conversation

Akhilathina
Copy link
Contributor

@Akhilathina Akhilathina commented Feb 13, 2025

Summary by CodeRabbit

  • New Features

    • Introduced dynamic templating for processing input data, allowing for flexible configuration and improved handling of complex, user-defined inputs. These enhancements pave the way for more adaptive and consistent processing in iterative operations, streamlining workflows and bolstering system reliability.
  • Chores

    • Upgraded the application version to 1.7.14, ensuring better performance, improved error handling, and overall system stability.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new class StepHelper with a static method prepare_input_data for processing input data in JSON format. Additionally, the Loop class in athina/steps/loop.py has been modified to incorporate Jinja2 templating for dynamic input handling, utilizing the new helper method. The project version has been updated from "1.7.13" to "1.7.14" in the pyproject.toml file.

Changes

File Change Summary
athina/helpers/step_helper.py Added class StepHelper with static method prepare_input_data(data) for processing input dictionaries.
athina/steps/loop.py Modified _execute_loop method to use Jinja2 templating for loop_input, incorporating StepHelper.prepare_input_data. Updated logic for retrieving items based on rendered input.
pyproject.toml Updated project version from "1.7.13" to "1.7.14".

Poem

In the garden of code, a helper was born,
With steps to prepare, no data forlorn.
Loops dance with templates, so fresh and so bright,
A version updated, all feels just right!
Hopping through changes, we celebrate cheer,
For every new feature, we hold dear! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb8b09b and fcbf9cb.

📒 Files selected for processing (1)
  • athina/steps/loop.py (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
athina/helpers/step_helper.py (1)

1-10: Add a newline at the end of the file and consider adding docstrings or type annotations.

  1. The linter warns about the missing newline at the end of the file.
  2. Optional but recommended: add docstrings and type hints to clarify this helper function’s purpose and return type.

Proposed fix to address the newline issue:

         }
+ 
🧰 Tools
🪛 GitHub Actions: Python Linter

[warning] 10-10: no newline at end of file

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 03d7df1 and cb8b09b.

📒 Files selected for processing (3)
  • athina/helpers/step_helper.py (1 hunks)
  • athina/steps/loop.py (2 hunks)
  • pyproject.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pyproject.toml
🧰 Additional context used
🪛 GitHub Actions: Python Linter
athina/helpers/step_helper.py

[warning] 10-10: no newline at end of file

athina/steps/loop.py

[error] 60-60: closing bracket does not match indentation of opening bracket's line

🪛 Ruff (0.8.2)
athina/steps/loop.py

3-3: typing.Any imported but unused

Remove unused import: typing.Any

(F401)

🔇 Additional comments (2)
athina/steps/loop.py (2)

2-2: Importing json is appropriate for parsing rendered templates.


6-8: New imports for Jinja templating look good.

These lines correctly introduce Jinja2 and the relevant helper classes for dynamic loop inputs.

@@ -1,8 +1,11 @@
import asyncio
import json
from typing import Dict, List, Any, Optional
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused Any import to comply with linting rules.

Pipeline logs indicate that Any is not used in this file. Removing it will resolve the F401 lint error.

Apply this diff to remove the unused import:

-from typing import Dict, List, Any, Optional
+from typing import Dict, List, Optional
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from typing import Dict, List, Any, Optional
from typing import Dict, List, Optional
🧰 Tools
🪛 Ruff (0.8.2)

3-3: typing.Any imported but unused

Remove unused import: typing.Any

(F401)

Comment on lines 55 to 65
if self.loop_type == "map":
items = inputs.get(self.loop_input, [])
env = Environment(
variable_start_string="{{",
variable_end_string="}}",
undefined=PreserveUndefined,
)

loop_input_template = env.from_string(self.loop_input)
prepared_input_data = StepHelper.prepare_input_data(inputs)
loop_input = loop_input_template.render(**prepared_input_data)
items = json.loads(loop_input, strict=False) if loop_input else None
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix indentation to resolve pipeline failure and handle JSON parsing errors gracefully.

  1. The pipeline complains that the closing bracket on line 60 is incorrectly indented.
  2. Consider wrapping json.loads in a try/except block to provide user-friendly error messages if rendering produces invalid JSON.

Proposed fix:

             if self.loop_type == "map":
-                env = Environment(
-                    variable_start_string="{{",
-                    variable_end_string="}}",
-                    undefined=PreserveUndefined,
-                    )
+                env = Environment(
+                    variable_start_string="{{",
+                    variable_end_string="}}",
+                    undefined=PreserveUndefined,
+                )

                 loop_input_template = env.from_string(self.loop_input)
                 prepared_input_data = StepHelper.prepare_input_data(inputs)
                 loop_input = loop_input_template.render(**prepared_input_data)
-                items = json.loads(loop_input, strict=False) if loop_input else None
+                try:
+                    items = json.loads(loop_input, strict=False) if loop_input else []
+                except json.JSONDecodeError:
+                    return {
+                        "status": "error",
+                        "data": "Invalid JSON format in loop_input",
+                        "metadata": {}
+                    }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if self.loop_type == "map":
items = inputs.get(self.loop_input, [])
env = Environment(
variable_start_string="{{",
variable_end_string="}}",
undefined=PreserveUndefined,
)
loop_input_template = env.from_string(self.loop_input)
prepared_input_data = StepHelper.prepare_input_data(inputs)
loop_input = loop_input_template.render(**prepared_input_data)
items = json.loads(loop_input, strict=False) if loop_input else None
if self.loop_type == "map":
env = Environment(
variable_start_string="{{",
variable_end_string="}}",
undefined=PreserveUndefined,
)
loop_input_template = env.from_string(self.loop_input)
prepared_input_data = StepHelper.prepare_input_data(inputs)
loop_input = loop_input_template.render(**prepared_input_data)
try:
items = json.loads(loop_input, strict=False) if loop_input else []
except json.JSONDecodeError:
return {
"status": "error",
"data": "Invalid JSON format in loop_input",
"metadata": {}
}
🧰 Tools
🪛 GitHub Actions: Python Linter

[error] 60-60: closing bracket does not match indentation of opening bracket's line

@vivek-athina vivek-athina merged commit c6dc99e into main Feb 13, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants