Dynamic script generation method and device, equipment and storage medium
By generating prompt content and evaluating candidate dynamic scripts, the problem of inefficient script writing in multilingual development environments is solved, and the generation efficiency and accuracy are improved, cost and security risks are reduced, and performance is improved.
Patent Information
- Application Number
- CN202411428009.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-14
- Publication Date
- 2025-01-14
AI Technical Summary
In a multilingual development environment, developers are not familiar with specific programming languages, which leads to inefficient script writing, which is prone to introduce syntax errors and logic vulnerabilities, and manually writing SQL statements is time-consuming and labor-intensive, affecting project progress and increasing labor costs, and poses security risks. and performance bottlenecks.
By obtaining the script templates of SQL statements and target programming languages, generating prompt content, inputting script generation models to generate candidate dynamic scripts, and determining target dynamic scripts based on the evaluation results, improving generation efficiency and accuracy and reducing costs.
Improves the generation efficiency and accuracy of dynamic scripts, reduces the generation cost, reduces the risk of syntax errors and security vulnerabilities, and improves performance and project progress.
Smart Images

Figure CN119311327A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a method, device, equipment and storage medium for generating a dynamic script. Background Art
[0002] In modern enterprises, rapid development and high-quality delivery are critical business requirements. Development teams need to be able to respond quickly to business needs, generate efficient and secure code, and ensure that the performance of the code can meet the requirements of large-scale production environments. Therefore, the demand for automated code generation tools is becoming more and more urgent. Such tools can not only improve development efficiency, but also ensure that the generated code complies with industry best practices and reduces potential risks through integrated security checks and performance optimization functions.
[0003] Currently, many developers, especially those working in a multi-language development environment, may not be familiar with certain specific programming languages, which can lead to inefficiencies in script writing and may even introduce syntax errors and logic loopholes. In addition, manually writing complex structured query language (SQL) statements and scripts is often time-consuming and labor-intensive, and developers need to spend a lot of time debugging and optimizing, which not only affects project progress, but also increases labor costs. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, equipment and storage medium for generating a dynamic script, which can not only improve the generation efficiency and accuracy of the dynamic script, but also reduce the generation cost of the dynamic script.
[0005] In a first aspect, an embodiment of the present invention provides a method for generating a dynamic script, comprising:
[0006] Acquire a first SQL statement and a script template of a target programming language, and generate prompt content based on the first SQL statement and the script template of the target programming language; wherein the first SQL statement is generated based on table field information in a database;
[0007] Inputting the prompt content into multiple script generation models, and outputting multiple candidate dynamic scripts;
[0008] Evaluate multiple candidate dynamic scripts based on the multiple script generation models to obtain evaluation results;
[0009] A target dynamic script is determined from a plurality of candidate dynamic scripts based on the evaluation result.
[0010] In a second aspect, an embodiment of the present invention further provides a device for generating a dynamic script, comprising:
[0011] A prompt content generation module, used to obtain a first SQL statement and a script template of a target programming language, and generate prompt content based on the first SQL statement and the script template of the target programming language; wherein the first SQL statement is generated based on table field information in a database;
[0012] A candidate dynamic script acquisition module, used for inputting the prompt content into multiple script generation models and outputting multiple candidate dynamic scripts;
[0013] An evaluation result acquisition module, used to evaluate multiple candidate dynamic scripts based on the multiple script generation models to obtain evaluation results;
[0014] The target dynamic script determination module is used to determine a target dynamic script from multiple candidate dynamic scripts based on the evaluation result.
[0015] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0016] at least one processor; and
[0017] a memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method for generating a dynamic script described in an embodiment of the present invention.
[0019] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method for generating a dynamic script described in the embodiment of the present invention when executed.
[0020] The embodiment of the present invention discloses a method, device, equipment and storage medium for generating a dynamic script. A first SQL statement and a script template of a target programming language are obtained, and prompt content is generated based on the first SQL statement and the script template of the target programming language; wherein the first SQL statement is generated based on the table field information in the database; the prompt content is input into multiple script generation models, and multiple candidate dynamic scripts are output; multiple candidate dynamic scripts are evaluated based on multiple script generation models to obtain evaluation results; and a target dynamic script is determined from multiple candidate dynamic scripts based on the evaluation results. The method for generating a dynamic script provided by the embodiment of the present invention generates multiple candidate dynamic scripts by multiple script generation modules, and then determines the target dynamic script from multiple candidate dynamic scripts, which can not only improve the generation efficiency and accuracy of the dynamic script, but also reduce the generation cost of the dynamic script. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a flow chart of a method for generating a dynamic script in Embodiment 1 of the present invention;
[0022] Figure 2 It is a structural schematic diagram of a dynamic script generation device in Embodiment 2 of the present invention;
[0023] Figure 3 It is a structural schematic diagram of an electronic device in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0024] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0025] The current development process often requires developers to be familiar with multiple programming languages and be able to manually write complex SQL queries and corresponding script codes. This approach is not only time-consuming and labor-intensive, but also prone to various problems.
[0026] The first problem is low efficiency. Developers need to spend a lot of time writing and debugging codes, especially in unfamiliar programming languages, which will seriously delay project progress.
[0027] The second question is: How to generate script content with SQL statements of the same semantics and respond more quickly.
[0028] The third problem: Even if it is written manually, syntax errors or logical loopholes are inevitable, which will affect the correctness of the code.
[0029] The fourth problem: security issues. Manually written code may contain security vulnerabilities such as SQL injection. Code that has not been strictly checked may bring serious security risks in the production environment.
[0030] The fifth question: The performance of SQL queries directly affects the system's response speed and resource consumption. Especially in a big data environment, performance bottlenecks may lead to inefficient queries.
[0031] Embodiment 1
[0032] Figure 1 This is a flow chart of a method for generating a dynamic script provided in the first embodiment of the present invention. This embodiment is applicable to the case of automatically generating a dynamic script. The method can be executed by a dynamic script generation device, which can be implemented in the form of software and / or hardware. Optionally, it can be implemented by an electronic device, which can be a mobile terminal, a PC or a server, etc. Specifically, it includes the following steps:
[0033] S110, obtaining a first SQL statement and a script template of a target programming language, and generating prompt content based on the first SQL statement and the script template of the target programming language.
[0034] The first SQL statement is generated based on the table field information in the database. The target programming language can be any commonly used programming language, which is not limited here, for example: C++, C language, Java, etc. The script template of the target programming language can be understood as a dynamic script example edited by the target programming language, which is used for the script generation model to learn the structure and format of the dynamic script.
[0035] In this embodiment, the first SQL statement may be written by a developer based on table field information in a database. Optionally, the written first SQL statement may be further optimized.
[0036] Specifically, the process of obtaining the first SQL statement can be: obtaining database table field information based on a database table identifier input by a user; receiving an initial SQL statement edited by a user based on the database table field information; inputting the initial SQL statement into a SQL adjustment model, outputting an adjusted SQL statement and an adjustment method; receiving a SQL statement adjusted by the user based on the adjustment method to obtain a first SQL statement.
[0037] The database table identifier may be a database table name. In this embodiment, the user inputs the database table name in the front-end interface, the back-end parses the table name, queries the table field information in the database based on the parsing result, and returns the table field information to the front-end (for example, returns to the front-end in the form of a Map), so that the user edits the initial SQL statement based on the database table field information.
[0038] Among them, the SQL adjustment model can be an AI large model. In this embodiment, the process of inputting the initial SQL statement into the SQL adjustment model and outputting the adjusted SQL statement and the adjustment method can be: the user inputs the edited initial SQL statement through the front-end interface and initiates an adjustment request, and the back-end inputs the initial SQL statement into the SQL adjustment model based on the adjustment request, so that the SQL adjustment model optimizes and adjusts the input initial SQL statement, outputs the adjusted SQL statement and the adjustment method, and returns the adjusted SQL statement and the adjustment method to the front-end. The user continues to optimize and adjust the adjusted SQL statement based on the adjustment method output by the SQL adjustment model in the front-end interface to obtain the first SQL statement. In this embodiment, if the number of times the user initiates an adjustment request does not reach the set threshold (such as 3 times), the adjustment request can continue to be initiated, so that the first SQL statement continues to be optimized and adjusted. In this embodiment, the first SQL statement is optimized and adjusted, which is conducive to the accuracy of the dynamic script generated subsequently.
[0039] The prompt content is used to guide and prompt the script model to generate a dynamic script in a certain programming language.
[0040] Specifically, the process of generating prompt content based on the first SQL statement and the script template of the target programming language may be: obtaining a pre-edited prompt template, and then adding the first SQL statement and the script template of the target programming language to the prompt template to obtain the prompt content.
[0041] The prompt template includes instructions for generating scripts. For example, the following is a prompt template: "From now on, you are a development engineer specializing in <programming language>. The following is a script template for <programming language>: ... <script>…;根据脚本模版,基于下述的SQL语句生成类似脚本模版的动态脚本,SQL语句如下:…<SQL>…;你的任务是根据该SQL语句生成<编程语言>对应的动态脚本”。在该提示模版中,将<编程语言>替换为目标编程语言,将…<Script>…替换为目标编程语言的脚本模版,将…<SQL>…替换为第一SQL语句,即可以获得提示内容。
[0042] S120,将提示内容输入多个脚本生成模型中,输出多个候选动态脚本。
[0043] 其中,脚本生成模块可以是人工智能(Artificial Intelligence,AI)大模型,可以是目前开源的任意AI大模型。
[0044] 本实施例中,将提示内容分别输入多个脚本生成模型中,各脚本生成模型对提示内容进行分析,输出候选动态脚本。示例性的,假设采用了四个脚本生成模型,分别为模型A、模型B、模型C及模型D,则得到的候选动态脚本分别为动态脚本a、动态脚本b、动态脚本c及动态脚本d。
[0045] S130,基于多个脚本生成模型对多个候选动态脚本进行评估,获得评估结果。
[0046] 其中,评估结果可以由评分表征,该评估结果可以用于反映动态脚本与脚本模本的结构及格式的匹配程度,动态脚本是否包含所有重要元素,动态脚本的逻辑是否情绪、易于理解,动态脚本代码的准确性和可执行性。
[0047] 本实施例中,对于每个候选动态脚本,分别输入多个脚本生成模型进行评估,获得该候选动态脚本的多个评分,然后将多个评分进行累加,获得该候选动态脚本的评估结果。
[0048] 具体的,基于多个脚本生成模型对多个候选动态脚本进行评估,获得评估结果的方式可以是:获取脚本评估规则;对于每个脚本生成模型,将脚本评估规则及多个候选动态脚本输入脚本生成模型中,输出多个候选动态脚本的评分;对于每个候选动态脚本,将多个脚本生成模型输出的评分进行累加,获得候选动态脚本的评估结果。
[0049] 其中,脚本评估规则可以是预先配置好的用于引导脚本生成模型对动态脚本进行评估的规则。示例性的,下述是一种脚本评估规则"1、相关性:与脚本模本的结构及格式的匹配程度的匹配程度,占25分;2、完整性:动态脚本是否包含所有重要元素,占25分;3、流畅性:动态脚本的逻辑是否情绪、易于理解,占25分;可信度:动态脚本代码的准确性和可执行性,占25分;5、满分一百分”。将脚本评估规则及多个候选动态脚本输入脚本生成模型中的方式可以是:将多个候选动态脚本、脚本评估规则与评估指令合并为评估提示内容,将该评估提示内容输入脚本生成模型,输出各候选动态脚本的评分。
[0050] S140,基于评估结果从多个候选动态脚本中确定出目标动态脚本。
[0051] 本实施例中,在获得各候选动态脚本的由评分表示的评估结果之后,将评分最高的候选动态脚本确定为目标动态脚本。
[0052] 可选的,在基于第一SQL语句及目标编程语言的脚本模版生成提示内容之前,还包括如下步骤:确定第一SQL语句的语义关键信息;基于语义关键信息从预设缓存中查找对应的动态脚本;若查找到语义关键信息对应的动态脚本,则将动态脚本确定为目标动态脚本。
[0053] 其中,第一SQL语句的语义关键信息(key)可以表示第一SQL语句的唯一语义信息。预设缓存可以是Redis缓存。基于语义关键信息从预设缓存中查找对应的动态脚本的过程可以是:将第一SQL语句的语义关键信息与预设缓存中的语义关键信息进行比对,若查找到与第一SQL语句的语义关键信息相匹配的语义关键信息,则将相匹配的语义关键信息对应的动态脚本确定为目标动态脚本。即无需再执行S120-S140的操作。若未查找到与第一SQL语句的语义关键信息相匹配的语义关键信息,则在执行S120-S140的操作。本实施例中,若缓存中存储有第一SQL语句对应的脚本代码,则可以快速从缓存中检索到已生成的脚本代码,从而节省计算资源,提升用户体验。
[0054] 可选的,基于所述评估结果从多个候选动态脚本中确定出目标动态脚本之后,还包括:将目标动态脚本与第一SQL语句的语义关键信息存储至预设缓存中,利于后续的对目标动态脚本的重复使用。本实施例通过预设缓存存储目标脚本代码,减少了重复计算的成本,并提高了系统的响应速度。
[0055] 具体的,确定第一SQL语句的语义关键信息的方式可以是:对第一SQL语句进行解析,获得抽象语法树;从抽象语法树中提取第一SQL语句的结构化信息;对结构化信息进行标准化处理;采用哈希算法对标准化处理后的结构化信息进行处理,获得语义关键信息。
[0056] 其中,标准化处理包括如下至少一种处理方式:按照预设顺序排序、去除冗余信息及字段参数化处理。本实施例中,可以利用SQL解析器库对第一SQL语句进行解析,获得抽象语法树。结构化信息可以包括:SELECT、FROM、WHERE、GROUP BY、ORDER BY等信息。按照预设顺序排序可以是对各结构化信息按照字典序进行排序。去除冗余信息可以是删除不必要的空格、注释以及规范化SQL关键字的大小写。字段参数化处理可以是:对各结构化信息中的字段参数按照预设顺序进行排序。哈希算法可以是SHA-256。
[0057] 本实施例中,使用一个SQL解析器库(例如:Apache Calcite)将第一SQL语句解析成抽象语法树,然后通过解析器从抽象语法树中提取包括SELECT、FROM、WHERE、GROUP BY、ORDER BY等的结构化信息;再然后对结构化信息执行按照字典序排序、去除冗余、参数化处理等的标准化处理;最后对标准化处理后的结构化信息利用哈希算法进行处理,获得第一SQL语句的语义关键信息。
[0058] 本实施例中,在生成目标动态脚本之后,需要对目标动态脚本的语义一致性进行分析,以进一步验证目标动态脚本的准确性。
[0059] 具体的,分析目标动态脚本的语义一致性的方式可以是:基于目标动态脚本生成第二SQL语句;对第二SQL语句和第一SQL语句进行语义一致性检测,获得语义一致性检测结果。
[0060] 其中,基于目标动态脚本生成第二SQL语句的过程可以是:从目标动态脚本中提取查询函数,其中,查询函数包括数据查询函数及数据统计函数;然后基于查询函数生成第二SQL语句。
[0061] 可选的,对第二SQL语句和第一SQL语句进行语义一致性检测,获得语义一致性检测结果的方式可以是:获取标准化处理后的第二SQL语句的结构化信息;将标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息进行比对,获得比对结果;若比对结果为标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息相同,则确定第一SQL语句与第二SQL语句间的语义相似度;若语义相似度大于或等于设定阈值,则语义一致性检测结果为通过,若语义相似度小于设定阈值,则语义一致性结果为不通过。
[0062] 其中,获取标准化处理后的第二SQL语句的结构化信息的方式可以是:对第二SQL语句进行解析,获得抽象语法树;从抽象语法树中提取第二QL语句的结构化信息;对结构化信息进行按照预设顺序排序、去除冗余信息及字段参数化处理的至少一项的标准化处理,获得标准化处理后的第二SQL语句的结构化信息。比对结果为标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息相同可以理解为:标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息完全相同。若标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息存在差异,则表明语义一致性检测结果为不通过,需要提示用户以进行审核。
[0063] 其中,确定第一SQL语句与第二SQL语句间的语义相似度的方式可以是采用预设语义相似度算法确定第一SQL语句与第二SQL语句间的语义相似度的得分。若该得分大于或等于设定阈值(例如设置为95),则语义一致性检测结果为通过,若该得分小于设定阈值,则语义一致性结果为不通过。其中,预设语义相似度算法可以是词频-逆文本频率指数(termfrequency–inverse document frequency,TF-IDF)算法。
[0064] 可选的,还可以对第二SQL语句进行安全性检查,可以利用开源的静态分析工具进行安全性检查。这些静态分析工具能够自动检测代码中的常见安全漏洞,包括SQL注入、跨站脚本攻击、不安全的依赖库使用等。在静态分析工具的基础上,定义一系列特定的安全性检查规则。例如,对于SQL语句中的用户输入部分,确保所有输入均已通过参数化查询处理。对于可能存在SQL注入风险的部分,系统会自动标记并返回给用户进行手动审查或重新生成。在生成第二SQL语句时,自动插入防御性编码模式(Defensive Programming)。例如,生成第二SQL语句时会自动添加对输入参数的类型检查和长度验证,避免由于参数输入不规范导致的漏洞。此外,系统还会自动检查SQL中的WHERE子句,确保必要的条件已被检查,避免由于逻辑漏洞导致的数据泄露。结合网站应用级入侵防御系统(Web ApplicationFirewall,WAF)技术,系统可以在生成第二SQL语句后进行实时的威胁检测,确保第二SQL语句在运行过程中不会被利用进行攻击。WAF可以检测并防御常见的攻击模式,并提供进一步的安全建议。这样做的好吃是可以自动检测生成的SQL语句潜在的安全问题,防止数据泄露或系统被攻击。
[0065] 本实施例的技术方案,获取第一SQL语句及目标编程语言的脚本模版,并基于第一SQL语句及目标编程语言的脚本模版生成提示内容;其中,第一SQL语句基于数据库中的表字段信息生成;将提示内容输入多个脚本生成模型中,输出多个候选动态脚本;基于多个脚本生成模型对多个候选动态脚本进行评估,获得评估结果;基于评估结果从多个候选动态脚本中确定出目标动态脚本。本发明实施例提供的动态脚本的生成方法,由多个脚本生成模块生成多个候选动态脚本,再从多个候选动态脚本中确定目标动态脚本,不仅可以提高动态脚本的生成效率及准确率,且可以降低动态脚本的生成成本。
[0066] 实施例二
[0067] 图2是本发明实施例二提供的一种动态脚本的生成装置的结构示意图,如图2所示,该装置包括:
[0068] 提示内容生成模块210,用于获取第一SQL语句及目标编程语言的脚本模版,并基于第一SQL语句及目标编程语言的脚本模版生成提示内容;其中,第一SQL语句基于数据库中的表字段信息生成;
[0069] 候选动态脚本获取模块220,用于将提示内容输入多个脚本生成模型中,输出多个候选动态脚本;
[0070] 评估结果获取模块230,用于基于多个脚本生成模型对多个候选动态脚本进行评估,获得评估结果;
[0071] 目标动态脚本确定模块240,用于基于评估结果从多个候选动态脚本中确定出目标动态脚本。
[0072] 可选的,还包括:语义关键信息确定模块,用于:
[0073] 确定第一SQL语句的语义关键信息;
[0074] 基于语义关键信息从预设缓存中查找对应的动态脚本;
[0075] 若查找到语义关键信息对应的动态脚本,则将动态脚本确定为目标动态脚本。
[0076] 可选的,语义关键信息确定模块,还用于::
[0077] 对第一SQL语句进行解析,获得抽象语法树;
[0078] 从抽象语法树中提取第一SQL语句的结构化信息;
[0079] 对结构化信息进行标准化处理;其中,标准化处理包括如下至少一种处理方式:按照预设顺序排序、去除冗余信息及字段参数化处理;
[0080] 采用哈希算法对标准化处理后的结构化信息进行处理,获得语义关键信息。
[0081] 可选的,评估结果获取模块230,还用于:
[0082] 获取脚本评估规则;
[0083] 对于每个脚本生成模型,将脚本评估规则及多个候选动态脚本输入脚本生成模型中,输出多个候选动态脚本的评分;
[0084] 对于每个候选动态脚本,将多个脚本生成模型输出的评分进行累加,获得候选动态脚本的评估结果;其中,评估结果由评分表示;
[0085] 可选的,目标动态脚本确定模块240,还用于:
[0086] 将评分最高的候选动态脚本确定为目标动态脚本。
[0087] 可选的,还包括:语义一致性检测模块,用于:
[0088] 基于目标动态脚本生成第二SQL语句;
[0089] 对第二SQL语句和第一SQL语句进行语义一致性检测,获得语义一致性检测结果。
[0090] 可选的,语义一致性检测模块,还用于::
[0091] 获取标准化处理后的第二SQL语句的结构化信息;
[0092] 将标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息进行比对,获得比对结果;
[0093] 若比对结果为标准化处理后的第二SQL语句的结构化信息与标准化处理后的第一SQL语句的结构化信息相同,则确定第一SQL语句与第二SQL语句间的语义相似度;
[0094] 若语义相似度大于或等于设定阈值,则语义一致性检测结果为通过,若语义相似度小于设定阈值,则语义一致性结果为不通过。
[0095] 可选的,提示内容生成模块210,还用于:
[0096] 基于用户输入的数据库表标识获取数据库表字段信息;
[0097] 接收用户基于数据库表字段信息编辑的初始SQL语句;
[0098] 将初始SQL语句输入SQL调整模型中,输出调整后的SQL语句及调整方式;
[0099] 接收用户基于调整方式对调整后的SQL语句再次调整后的SQL语句,获得第一SQL语句。
[0100] 上述装置可执行本发明前述所有实施例所提供的方法,具备执行上述方法相应的功能模块和有益效果。未在本实施例中详尽描述的技术细节,可参见本发明前述所有实施例所提供的方法。
[0101] 实施例三
[0102] 图3示出了可以用来实施本发明的实施例的电子设备10的结构示意图。电子设备旨在表示各种形式的数字计算机,诸如,膝上型计算机、台式计算机、工作台、个人数字助理、服务器、刀片式服务器、大型计算机、和其它适合的计算机。电子设备还可以表示各种形式的移动装置,诸如,个人数字处理、蜂窝电话、智能电话、可穿戴设备(如头盔、眼镜、手表等)和其它类似的计算装置。本文所示的部件、部件间的连接和关系、及其功能仅仅作为示例,并且不意在限制本文中描述的和 / 或者要求的本发明的实现。
[0103] 如图3所示,电子设备10包括至少一个处理器11,以及与至少一个处理器11通信连接的存储器,如只读存储器(ROM)12、随机访问存储器(RAM)13等,其中,存储器存储有可被至少一个处理器执行的计算机程序,处理器11可以根据存储在只读存储器(ROM)12中的计算机程序或者从存储单元18加载到随机访问存储器(RAM)13中的计算机程序,来执行各种适当的动作和处理。在RAM 13中,还可存储电子设备10操作所需的各种程序和数据。处理器11、ROM 12以及RAM 13通过总线14彼此相连。输入 / 输出(I / O)接口15也连接至总线14。
[0104] 电子设备10中的多个部件连接至I / O接口15,包括:输入单元16,例如键盘、鼠标等;输出单元17,例如各种类型的显示器、扬声器等;存储单元18,例如磁盘、光盘等;以及通信单元19,例如网卡、调制解调器、无线通信收发机等。通信单元19允许电子设备10通过诸如因特网的计算机网络和 / 或各种电信网络与其他设备交换信息 / 数据。
[0105] 处理器11可以是各种具有处理和计算能力的通用和 / 或专用处理组件。处理器11的一些示例包括但不限于中央处理单元(CPU)、图形处理单元(GPU)、各种专用的人工智能(AI)计算芯片、各种运行机器学习模型算法的处理器、数字信号处理器(DSP)、以及任何适当的处理器、控制器、微控制器等。处理器11执行上文所描述的各个方法和处理,例如动态脚本的生成方法。
[0106] 在一些实施例中,动态脚本的生成方法可被实现为计算机程序,其被有形地包含于计算机可读存储介质,例如存储单元18。在一些实施例中,计算机程序的部分或者全部可以经由ROM 12和 / 或通信单元19而被载入和 / 或安装到电子设备10上。当计算机程序加载到RAM 13并由处理器11执行时,可以执行上文描述的动态脚本的生成方法的一个或多个步骤。备选地,在其他实施例中,处理器11可以通过其他任何适当的方式(例如,借助于固件)而被配置为执行动态脚本的生成方法。
[0107] 本文中以上描述的系统和技术的各种实施方式可以在数字电子电路系统、集成电路系统、场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、芯片上系统的系统(SOC)、负载可编程逻辑设备(CPLD)、计算机硬件、固件、软件、和 / 或其组合中实现。这些各种实施方式可以包括:实施在一个或者多个计算机程序中,该一个或者多个计算机程序可在包括至少一个可编程处理器的可编程系统上执行和 / 或解释,该可编程处理器可以是专用或者通用可编程处理器,可以从存储系统、至少一个输入装置、和至少一个输出装置接收数据和指令,并且将数据和指令传输至该存储系统、该至少一个输入装置、和该至少一个输出装置。
[0108] 用于实施本发明的方法的计算机程序可以采用一个或多个编程语言的任何组合来编写。这些计算机程序可以提供给通用计算机、专用计算机或其他可编程数据处理装置的处理器,使得计算机程序当由处理器执行时使流程图和 / 或框图中所规定的功能 / 操作被实施。计算机程序可以完全在机器上执行、部分地在机器上执行,作为独立软件包部分地在机器上执行且部分地在远程机器上执行或完全在远程机器或服务器上执行。
[0109] 在本发明的上下文中,计算机可读存储介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的计算机程序。计算机可读存储介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或半导体系统、装置或设备,或者上述内容的任何合适组合。备选地,计算机可读存储介质可以是机器可读信号介质。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。
[0110] 为了提供与用户的交互,可以在电子设备上实施此处描述的系统和技术,该电子设备具有:用于向用户显示信息的显示装置(例如,CRT(阴极射线管)或者LCD(液晶显示器)监视器);以及键盘和指向装置(例如,鼠标或者轨迹球),用户可以通过该键盘和该指向装置来将输入提供给电子设备。其它种类的装置还可以用于提供与用户的交互;例如,提供给用户的反馈可以是任何形式的传感反馈(例如,视觉反馈、听觉反馈、或者触觉反馈);并且可以用任何形式(包括声输入、语音输入或者、触觉输入)来接收来自用户的输入。
[0111] 可以将此处描述的系统和技术实施在包括后台部件的计算系统(例如,作为数据服务器)、或者包括中间件部件的计算系统(例如,应用服务器)、或者包括前端部件的计算系统(例如,具有图形用户界面或者网络浏览器的用户计算机,用户可以通过该图形用户界面或者该网络浏览器来与此处描述的系统和技术的实施方式交互)、或者包括这种后台部件、中间件部件、或者前端部件的任何组合的计算系统中。可以通过任何形式或者介质的数字数据通信(例如,通信网络)来将系统的部件相互连接。通信网络的示例包括:局域网(LAN)、广域网(WAN)、区块链网络和互联网。
[0112] 计算系统可以包括客户端和服务器。客户端和服务器一般远离彼此并且通常通过通信网络进行交互。通过在相应的计算机上运行并且彼此具有客户端-服务器关系的计算机程序来产生客户端和服务器的关系。服务器可以是云服务器,又称为云计算服务器或云主机,是云计算服务体系中的一项主机产品,以解决了传统物理主机与VPS服务中,存在的管理难度大,业务扩展性弱的缺陷。
[0113] 应该理解,可以使用上面所示的各种形式的流程,重新排序、增加或删除步骤。例如,本发明中记载的各步骤可以并行地执行也可以顺序地执行也可以不同的次序执行,只要能够实现本发明的技术方案所期望的结果,本文在此不进行限制。
[0114] 上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,根据设计要求和其他因素,可以进行各种修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。< / script>
Claims
1. A method for generating a dynamic script, characterized in that: include: Acquire a first SQL statement and a script template of a target programming language, and generate prompt content based on the first SQL statement and the script template of the target programming language; wherein the first SQL statement is generated based on table field information in a database; Inputting the prompt content into multiple script models, and outputting multiple candidate dynamic scripts; Evaluate multiple candidate dynamic scripts based on multiple script generation models to obtain evaluation results; A target dynamic script is determined from a plurality of candidate dynamic scripts based on the evaluation result.
2. The method according to claim 1, characterized in that Before generating prompt content based on the first SQL statement and the script template of the target programming language, the method further includes: Determining semantic key information of the first SQL statement; Searching for a corresponding dynamic script from a preset cache based on the semantic key information; If a dynamic script corresponding to the semantic key information is found, the dynamic script is determined as a target dynamic script.
3. The method according to claim 2, characterized in that Determining the semantic key information of the first SQL statement includes: Parsing the first SQL statement to obtain an abstract syntax tree; Extracting structural information of the first SQL statement from the abstract syntax tree; Standardizing the structured information; wherein the standardization includes at least one of the following processing methods: sorting in a preset order, removing redundant information, and field parameterization; The hash algorithm is used to process the standardized structured information to obtain semantic key information.
4. The method according to claim 1, characterized in that: Evaluating multiple candidate dynamic scripts based on the multiple script generation models to obtain evaluation results includes: Get script evaluation rules; For each script generation model, the script evaluation rule and the multiple candidate dynamic scripts are input into the script generation model, and scores of the multiple candidate dynamic scripts are output; For each candidate dynamic script, the scores output by multiple script generation models are accumulated to obtain an evaluation result of the candidate dynamic script; wherein the evaluation result is represented by a score; Accordingly, determining a target dynamic script from a plurality of candidate dynamic scripts based on the evaluation result includes: The candidate dynamic script with the highest score is determined as the target dynamic script.
5. The method according to claim 3, characterized in that: After determining a target dynamic script from a plurality of candidate dynamic scripts based on the evaluation result, the method further includes: Generate a second SQL statement based on the target dynamic script; A semantic consistency check is performed on the second SQL statement and the first SQL statement to obtain a semantic consistency check result.
6. The method according to claim 5, characterized in that Performing a semantic consistency check on the second SQL statement and the first SQL statement to obtain a semantic consistency check result includes: Obtaining structured information of the second SQL statement after standardization; Comparing the structured information of the second SQL statement after the standardization processing with the structured information of the first SQL statement after the standardization processing to obtain a comparison result; If the comparison result is that the structured information of the second SQL statement after the standardization processing is the same as the structured information of the first SQL statement after the standardization processing, determining the semantic similarity between the first SQL statement and the second SQL statement; If the semantic similarity is greater than or equal to the set threshold, the semantic consistency detection result is passed; if the semantic similarity is less than the set threshold, the semantic consistency result is failed.
7. The method according to claim 1, characterized in that Get the first SQL statement, including: Obtain database table field information based on the database table identifier input by the user; Receiving an initial SQL statement edited by a user based on the database table field information; Input the initial SQL statement into the SQL adjustment model, and output the adjusted SQL statement and adjustment method; A SQL statement adjusted again by the user based on the adjustment method is received to obtain a first SQL statement.
8. A device for generating a dynamic script, characterized in that: include: A prompt content generation module, used to obtain a first SQL statement and a script template of a target programming language, and generate prompt content based on the first SQL statement and the script template of the target programming language; wherein the first SQL statement is generated based on table field information in a database; A candidate dynamic script acquisition module, used for inputting the prompt content into multiple script generation models and outputting multiple candidate dynamic scripts; An evaluation result acquisition module, used to evaluate multiple candidate dynamic scripts based on the multiple script generation models to obtain evaluation results; The target dynamic script determination module is used to determine a target dynamic script from multiple candidate dynamic scripts based on the evaluation result.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method for generating a dynamic script according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method for generating a dynamic script according to any one of claims 1 to 7 when executed.
Citation Information
Cited By
Script generation model optimization method and device, equipment and storage medium
CN121280832A