-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes introduce a new class Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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.
- The linter warns about the missing newline at the end of the file.
- 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
📒 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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)
athina/steps/loop.py
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation to resolve pipeline failure and handle JSON parsing errors gracefully.
- The pipeline complains that the closing bracket on line 60 is incorrectly indented.
- Consider wrapping
json.loads
in atry/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.
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
Summary by CodeRabbit
New Features
Chores