Closed MisterSun-git closed 5 months ago
what's your llm, maybe you should parse it compatible with your llm response
what's your llm, maybe you should parse it compatible with your llm response I'am used Xunfei Spark llm.The problem is incidental.
同样也是这个问题,我是用的qwen 7b chat的模型,生成的sql无法被json load解析出来会在服务端报错,导致前端没法查询出mysql数据库中的数据
This issue has been marked as stale
, because it has been over 30 days without any activity.
This issue bas been closed, because it has been marked as stale
and there has been no activity for over 7 days.
Search before asking
Operating system information
Windows
Python version information
3.10
DB-GPT version
main
Related scenes
Installation Information
[X] Installation From Source
[ ] Docker Installation
[ ] Docker Compose Installation
[ ] Cluster Installation
[ ] AutoDL Image
[ ] Other
Device information
Device:CPU
Models information
LLM:
What happened
LLM返回数据可能是单引号字符串,json不能解析直接抛出异常。
What you expected to happen
"""The output parser is used to parse the output of an LLM call.
TODO: Make this more general and clear. """
from future import annotations
import json import logging from abc import ABC from dataclasses import asdict from typing import Any, TypeVar, Union
from dbgpt.core import ModelOutput from dbgpt.core.awel import MapOperator from dbgpt.core.awel.flow import IOField, OperatorCategory, OperatorType, ViewMetadata from dbgpt.util.i18nutils import
T = TypeVar("T") ResponseTye = Union[str, bytes, ModelOutput]
logger = logging.getLogger(name)
class BaseOutputParser(MapOperator[ModelOutput, Any], ABC): """Class to parse the output of an LLM call.
def _parse_model_response(response: ResponseTye): if response is None: resp_obj_ex = "" elif isinstance(response, ModelOutput): resp_obj_ex = asdict(response) elif isinstance(response, str): resp_obj_ex = json.loads(response) elif isinstance(response, bytes): if b"\0" in response: response = response.replace(b"\0", b"") resp_obj_ex = json.loads(response.decode()) else: raise ValueError(f"Unsupported response type {type(response)}") return resp_obj_ex
class SQLOutputParser(BaseOutputParser): """Parse the SQL output of an LLM call."""
How to reproduce
\dbgpt\core\interface\output_parser.py 237行
cleaned_output = ( cleanedoutput.strip() .replace("\n", " ") .replace("\n", " ") .replace("\", " ") .replace("_", "") .replace("\'","\"") #此处需要添加替换 )
Additional context
No response
Are you willing to submit PR?