Skip to content

Commit

Permalink
支持opencv & code 结果长度
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorpion1221 committed Dec 25, 2024
1 parent d26836d commit 7be509f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
9 changes: 5 additions & 4 deletions api/configs/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ class CodeExecutionSandboxConfig(BaseSettings):
default=20,
)

CODE_MAX_STRING_LENGTH: PositiveInt = Field(
description="Maximum allowed length for strings in code execution",
default=80000,
)
CODE_MAX_STRING_LENGTH: PositiveInt = 80000000
# CODE_MAX_STRING_LENGTH: PositiveInt = Field(
# description="Maximum allowed length for strings in code execution",
# default=80000000,
# )

CODE_MAX_STRING_ARRAY_LENGTH: PositiveInt = Field(
description="Maximum allowed length for string arrays in code execution",
Expand Down
4 changes: 2 additions & 2 deletions api/core/helper/code_executor/code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def exec_code(code):
exec_result['output'] = observation
return exec_result

exec_result = ""
exec_result = {}
try:
exec_result = exec_code(code)
except Exception as e:
exec_result = traceback.format_exc()
exec_result['error'] = traceback.format_exc()

json_string = json.dumps(exec_result, indent=4)

Expand Down
2 changes: 2 additions & 0 deletions api/core/helper/code_executor/template_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def transform_response(cls, response: str) -> Mapping[str, Any]:
"""
try:
result = json.loads(cls.extract_result_str_from_response(response))
if 'error' in result:
raise ValueError(result['error'])
except json.JSONDecodeError:
raise ValueError("failed to parse response")
if not isinstance(result, dict):
Expand Down
30 changes: 25 additions & 5 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ twilio = "~9.0.4"
vanna = { version = "0.7.5", extras = ["postgres", "mysql", "clickhouse", "duckdb", "oracle"] }
wikipedia = "1.4.0"
yfinance = "~0.2.40"
opencv-python = "4.10.0.84"

############################################################
# [ Storage ] dependency group
Expand Down
1 change: 1 addition & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ tencentcloud-sdk-python-hunyuan~=3.0.1158
chromadb~=0.5.0
antlr4-python3-runtime==4.11
antlr4-tools==0.2.1
opencv-python

0 comments on commit 7be509f

Please sign in to comment.