-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import json | ||
|
||
class StepHelper: | ||
|
||
@staticmethod | ||
def prepare_input_data(data): | ||
return { | ||
key: json.dumps(value) if isinstance(value, (list, dict)) else value | ||
for key, value in data.items() | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,11 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import asyncio | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from typing import Dict, List, Any, Optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from athina.steps.base import Step | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from concurrent.futures import ThreadPoolExecutor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from jinja2 import Environment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from athina.helpers.jinja_helper import PreserveUndefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from athina.helpers.step_helper import StepHelper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class Loop(Step): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
loop_type: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -50,7 +53,16 @@ async def _execute_loop(self, inputs: Dict) -> Dict: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
results = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation to resolve pipeline failure and handle JSON parsing errors gracefully.
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
Suggested change
🧰 Tools🪛 GitHub Actions: Python Linter[error] 60-60: closing bracket does not match indentation of opening bracket's line |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not isinstance(items, list): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return {"status": "error", "data": "Input not of type list", "metadata": {}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "athina" | ||
version = "1.7.13" | ||
version = "1.7.14" | ||
description = "Python SDK to configure and run evaluations for your LLM-based application" | ||
authors = ["Shiv Sakhuja <[email protected]>", "Akshat Gupta <[email protected]>", "Vivek Aditya <[email protected]>", "Akhil Bisht <[email protected]>"] | ||
readme = "README.md" | ||
|
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:
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.8.2)
3-3:
typing.Any
imported but unusedRemove unused import:
typing.Any
(F401)