Skip to content

Commit

Permalink
fix(code_executor): surrogates not allowed error in jinja2 template (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lroolle committed Apr 9, 2024
1 parent 337899a commit 3c3fb3c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions api/core/helper/code_executor/javascript_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def transform_caller(cls, code: str, inputs: dict) -> tuple[str, str]:
:param inputs: inputs
:return:
"""

# transform inputs to json string
inputs_str = json.dumps(inputs, indent=4)
inputs_str = json.dumps(inputs, indent=4, ensure_ascii=False)

# replace code and inputs
runner = NODEJS_RUNNER.replace('{{code}}', code)
runner = runner.replace('{{inputs}}', inputs_str)

return runner, NODEJS_PRELOAD

@classmethod
def transform_response(cls, response: str) -> dict:
"""
Expand Down
6 changes: 3 additions & 3 deletions api/core/helper/code_executor/jina2_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def transform_caller(cls, code: str, inputs: dict) -> tuple[str, str]:

# transform jinja2 template to python code
runner = PYTHON_RUNNER.replace('{{code}}', code)
runner = runner.replace('{{inputs}}', json.dumps(inputs, indent=4))
runner = runner.replace('{{inputs}}', json.dumps(inputs, indent=4, ensure_ascii=False))

return runner, JINJA2_PRELOAD

@classmethod
def transform_response(cls, response: str) -> dict:
"""
Expand All @@ -81,4 +81,4 @@ def transform_response(cls, response: str) -> dict:

return {
'result': result
}
}
2 changes: 1 addition & 1 deletion api/core/helper/code_executor/python_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def transform_caller(cls, code: str, inputs: dict) -> tuple[str, str]:
"""

# transform inputs to json string
inputs_str = json.dumps(inputs, indent=4)
inputs_str = json.dumps(inputs, indent=4, ensure_ascii=False)

# replace code and inputs
runner = PYTHON_RUNNER.replace('{{code}}', code)
Expand Down

0 comments on commit 3c3fb3c

Please sign in to comment.