Skip to content
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

数据库对话功能 可以规范一下生成的sql语句 #5092

Open
CRIOWN opened this issue Nov 19, 2024 · 1 comment
Open

数据库对话功能 可以规范一下生成的sql语句 #5092

CRIOWN opened this issue Nov 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@CRIOWN
Copy link

CRIOWN commented Nov 19, 2024

功能描述 / Feature Description
基于xf 部署的qwen2.5-instruct-7b 使用 数据库对话 功能时报错
看报错是因为 执行的sql语句是md格式(前缀有 ```sql 后缀有``` )
不清楚是qwen系列的问题还是别的也有 没测

解决的问题 / Problem Solved
通过一个监听来规范sql语句
通过提示词规范sql语句生成

实现建议 / Implementation Suggestions
监听

def detect_sql(conn, cursor, statement, parameters, context, executemany):
    sql = statement.lower()
    if sql.startswith("```sql"):
        statement = statement[6:].strip()
    if sql.endswith("```"):
        statement = statement[:-3].strip()
    statement = statement.replace("\n", " ")
    # print("SQL Statement:", statement)
    return statement, parameters
event.listen(db._engine, "before_cursor_execute", detect_sql, retval=True ) 

替代方案 / Alternative Solutions
通过提示词让AI自检 但是没成功

@CRIOWN CRIOWN added the enhancement New feature or request label Nov 19, 2024
@Alan-zhong
Copy link

我也是qwen生成的sql有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants