Skip to content

Commit

Permalink
fix: Fixed merge conflicts again
Browse files Browse the repository at this point in the history
  • Loading branch information
RamiAwar committed Jan 23, 2025
2 parents dd95405 + 393fc16 commit d48c993
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions backend/dataline/services/llm_flow/llm_calls/chart_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import StrEnum

from mirascope.core import prompt_template
from pydantic import BaseModel, ValidationInfo, field_validator
from pydantic import BaseModel, model_validator


class ChartType(StrEnum):
Expand Down Expand Up @@ -201,22 +201,27 @@ class ChartType(StrEnum):


class GeneratedChart(BaseModel):
chart_type: ChartType
chartjs_json: str

@field_validator("chartjs_json", mode="before")
@model_validator(mode="before")
@classmethod
def check_alphanumeric(cls, v: str | dict, info: ValidationInfo) -> str:
def check_json(cls, data: dict):
v = data["chartjs_json"]
if isinstance(v, dict):
# check chart type - fails if not in valid types
v["type"] = ChartType[v["type"]]
v["type"] = ChartType[data["chart_type"]]
# convert to json str
v = json.dumps(v)

elif isinstance(v, str):
v_dict = json.loads(v)
# check chart type - this fails if not in valid types
v_dict["type"] = ChartType[v_dict["type"]]
return v
v_dict["type"] = ChartType[data["chart_type"]]
# convert back to json str
v = json.dumps(v_dict)
data["chartjs_json"] = v
return data


@prompt_template()
Expand Down

0 comments on commit d48c993

Please sign in to comment.