Method, device, electronic device and computer program product for SQL assistant

By obtaining user input and splitting it into multiple tasks, combining reference prompt words and thinking chain prompt words, the problem of poor SQL code processing in the existing technology is solved, and the efficient and accurate processing of SQL assistants and the improvement of user experience is achieved. .

CN119149578BActive Publication Date: 2025-02-21BEIJING VOLCANO ENGINE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411658083.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-02-21
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

Existing code assistants cannot provide the same high-quality suggestions and optimizations when processing SQL code. There are problems such as irregular naming, syntax errors, and incorrect code interpretation, which leads users to rely on their own SQL knowledge when writing and optimizing SQL queries. and experience, unable to take full advantage of the intelligent capabilities of the code assistant.

Method used

By obtaining user input, determining the target function, and obtaining reference prompt words and thinking chain prompt words based on the target function, splitting the user input into multiple tasks, performing these tasks in turn, and finally generating a function output corresponding to the target function.

Benefits of technology

Significantly improve the intelligence level of SQL assistants, so that they can handle SQL-related tasks efficiently and accurately, improve user experience, and reduce human intervention and bias.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149578B_ABST
    Figure CN119149578B_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure relate to methods, devices, electronic devices, and computer program products for SQL assistants. The method includes obtaining user input and determining the indicated target function based on the user input. The method also includes obtaining corresponding reference prompt words and thinking chain prompt words based on the target function, and splitting the user input into multiple tasks based on the user input, reference prompt words, thinking chain prompt words, and basic prompt words. The method also includes executing multiple tasks in sequence and determining the task output of the final task as the function output corresponding to the target function in response to the final task of the multiple tasks being executed. Therefore, according to the solution provided by the embodiments of the present disclosure, the intelligence level of the SQL assistant can be significantly improved, so that it can handle SQL-related tasks more efficiently and accurately, and improve the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more particularly to a method, an apparatus, an electronic device, and a computer program product for generating a functional output of a structured query language (SQL) assistant. Background Art

[0002] The application of language models is rapidly expanding, covering a wide range of fields from natural language processing to data analysis and automated customer service. Driven by generative artificial intelligence, these models can understand and generate high-quality text that conforms to the context through massive data training, greatly improving work efficiency. With the advancement of technology, language models will play an important role in more industries and scenarios, promoting the intelligent development of various businesses.

[0003] Language models are increasingly used in code writing and are gradually becoming an important tool for developers. By training on the code and documents of a large number of programming languages, language models can understand code structure, optimize code snippets, automatically generate functions, and even fix code errors. The application of language models has greatly reduced the workload of manual coding and promoted the development of programming automation. Summary of the invention

[0004] Embodiments of the present disclosure provide a method, an apparatus, an electronic device, and a computer program product for generating a functional output of a SQL assistant.

[0005] According to a first aspect of the present disclosure, a method for generating a functional output of a SQL assistant is provided. The method includes obtaining user input, the user input indicates the SQL assistant to perform a function related to SQL processing in a natural language form, and the SQL assistant is constructed based on a language model. The method also includes determining a target function indicated by the user input based on the user input. The method also includes obtaining a reference prompt word and a thinking chain prompt word corresponding to the target function based on the target function, the reference prompt word includes a plurality of question and answer instances corresponding to the target function, and the thinking chain prompt word includes a reasoning step corresponding to the target function. The method also includes splitting the user input into a plurality of tasks corresponding to the target function based on the user input, the reference prompt word, the thinking chain prompt word, and the basic prompt word, the basic prompt word indicates at least one of the role setting, the function setting, and the output setting of the SQL assistant. The method also includes executing a plurality of tasks in sequence, and the task output of each task in the plurality of tasks is added to the input prompt word of the next task. In addition, the method also includes determining the task output of the final task as the functional output corresponding to the target function in response to the execution of the final task in the plurality of tasks.

[0006] According to a second aspect of the present disclosure, a device for generating a functional output of a SQL assistant is provided. The device includes a user input acquisition module configured to acquire user input, the user input indicates the SQL assistant to perform a function related to SQL processing in a natural language form, and the SQL assistant is constructed based on a language model. The device also includes a target function determination module configured to determine the target function indicated by the user input based on the user input. The device also includes a function prompt acquisition module configured to acquire reference prompt words and thinking chain prompt words corresponding to the target function based on the target function, the reference prompt words include multiple question and answer instances corresponding to the target function, and the thinking chain prompt words include reasoning steps corresponding to the target function. The device also includes an input task splitting module configured to split the user input into multiple tasks corresponding to the target function based on the user input, the reference prompt words, the thinking chain prompt words and the basic prompt words, the basic prompt words indicate at least one of the role setting, function setting and output setting of the SQL assistant. The device also includes a task sequence execution module configured to execute multiple tasks in sequence, and the task output of each task in the multiple tasks is added to the input prompt words of the next task. In addition, the apparatus further includes a function output determination module configured to determine, in response to a final task among the plurality of tasks being executed, a task output of the final task as a function output corresponding to the target function.

[0007] According to a third aspect of the present disclosure, an electronic device is provided, comprising a processor and a memory coupled to the processor, wherein the memory has instructions stored therein, and when the instructions are executed by the processor, the electronic device executes the method according to the first aspect.

[0008] In a fourth aspect of the present disclosure, a computer program product is provided. The computer program product is tangibly stored on a non-transitory computer readable medium and comprises computer executable instructions, which when executed cause a computer to perform the steps of the method of the first aspect of the present disclosure.

[0009] The purpose of this Summary is to introduce a selection of concepts in a simplified form that are further described in the Detailed Description below. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to limit the scope of the claimed subject matter. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0011] Figure 1A schematic diagram showing an example environment in which devices and / or methods according to embodiments of the present disclosure may be implemented;

[0012] Figure 2 A flowchart of a method for generating a functional output of a SQL assistant according to an embodiment of the present disclosure is shown;

[0013] Figure 3A A schematic diagram showing a process of using a SQL assistant according to an embodiment of the present disclosure is shown;

[0014] Figure 3B A schematic diagram showing structured table information according to an embodiment of the present disclosure is shown;

[0015] Figure 3C A schematic diagram showing a reference prompt word according to an embodiment of the present disclosure;

[0016] Figure 3D A schematic diagram showing a process of executing multiple rounds of tasks according to an embodiment of the present disclosure;

[0017] Figure 4A-4C A schematic diagram showing reference hint words for SQL code optimization function according to an embodiment of the present disclosure is shown;

[0018] Figure 5 A schematic diagram showing a process of generating knowledge hints for a SQL code repair function according to an embodiment of the present disclosure;

[0019] Figure 6 A block diagram showing an apparatus for generating a functional output of a SQL assistant according to an embodiment of the present disclosure; and

[0020] Figure 7 A block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0021] Throughout the drawings, the same or similar reference numbers denote the same or similar elements. DETAILED DESCRIPTION

[0022] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the type, scope of use, usage scenarios, etc. of the personal information (such as voice) involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0023] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0024] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects, unless explicitly stated. Other explicit and implicit definitions may also be included below.

[0025] As mentioned above, language models are becoming increasingly important in code writing. For example, general code assistants (such as Python, Java, etc.) built based on language models can not only help users write general programming languages, but also help users write SQL, such as SQL code generation, SQL optimization, and SQL completion. However, these general code assistants still have some shortcomings when processing SQL code.

[0026] Existing code assistants are mainly optimized for general programming languages, while their support for SQL, a special language used specifically for database queries, is relatively weak. The syntax and structure of SQL are significantly different from general programming languages. Existing code assistants often fail to provide the same high-quality suggestions and optimizations when processing SQL code, and there are problems such as irregular naming, syntax errors, and incorrect code interpretation. This results in users still having to rely on their own SQL knowledge and experience when writing and optimizing SQL queries, and they are unable to fully utilize the intelligent functions of the code assistant. In addition, although language models perform well in natural language processing and generation, they often lack a deep understanding of database structure and query optimization when understanding and generating SQL queries. This causes the language model to generate inefficient queries when generating SQL queries, which cannot meet users' needs for efficient and accurate queries.

[0027] To this end, an embodiment of the present disclosure proposes a solution for generating the functional output of a SQL assistant built based on a language model, which enhances the capabilities of the SQL assistant through prompt engineering technology, thereby improving its effect in processing SQL tasks, and enabling the SQL assistant to more accurately understand the user's intentions and generate expected results. First, the target function that the user wants the SQL assistant to perform is determined based on the user input. Then, corresponding reference prompt words and thinking chain prompt words are obtained for the target function. Next, the user input is split into multiple tasks based on the user input, reference prompt words, thinking chain prompt words, and basic prompt words, where the basic prompt words are used to indicate the role setting, function setting, output setting, and other contents of the SQL assistant. Finally, these tasks are executed in sequence, and the output of the last task is used as the final output result of the target function.

[0028] Therefore, according to the embodiments of the present disclosure, the intelligence level of the SQL assistant can be significantly improved, so that it can handle SQL-related tasks more efficiently and accurately, and improve the user experience. Specifically, the reference prompt words help the SQL assistant better understand the structure and pattern of user input and tasks by providing multiple question-and-answer examples, thereby generating more expected outputs, and there is no need to rely on a large amount of training data related to SQL processing, thereby saving computing resources. The thinking chain prompt words gradually guide the SQL assistant to reason, so that it can respond to different task scenarios more intelligently, improve reasoning efficiency and adaptability, and reduce human intervention and deviations. When the reference prompt words are combined with the thinking chain prompt words, the SQL assistant can also be inspired to perform effective task splitting. Through this task splitting, complex SQL tasks are broken down into multiple small tasks, and the SQL assistant can gradually execute each subtask to ensure that each step is accurately processed. The application of task splitting enables the SQL assistant to maintain higher stability and efficiency when processing complex tasks, reducing the occurrence of errors and omissions.

[0029] Figure 1 Schematic diagram of an example environment in which the device and / or method according to an embodiment of the present disclosure may be implemented. Figure 1As shown, the example environment 100 may include a SQL assistant 110, which may be deployed on a computing device, which may be a user terminal, a mobile device, a computer, etc., or a computing system, a single server, a distributed server, or a cloud-based server. The SQL assistant 110 may receive a user input 120, which instructs the SQL assistant 110 to perform a function related to SQL processing in a natural language form, and the SQL assistant 110 is constructed based on a language model 170. The SQL assistant 110 may determine the target function 130 indicated by the user based on the user input 120. For example, the SQL assistant 110 may process the user input 120 using the language model 170 to determine the specific function indicated by the user. In some embodiments, the SQL assistant 110 may determine the target function 130 indicated by the user based on the user's selection at the front end (e.g., selecting the SQL code completion function).

[0030] The SQL assistant 110 can obtain the corresponding reference prompt words 140 and thinking chain prompt words 150 according to the target function 130. For example, the reference prompt words 140 may include multiple question and answer instances corresponding to the target function 130, and the thinking chain prompt words 150 may include reasoning steps corresponding to the target function 130. For example, when the target function 130 is the SQL code completion function, the thinking chain prompt words 150 may include multiple SQL code completion questions and corresponding question reasoning steps. The SQL assistant 110 can split the user input 120 into multiple tasks 180 corresponding to the target function 130 according to the user input 120, the reference prompt words 140, the thinking chain prompt words 150 and the basic prompt words 160, wherein the basic prompt words 160 can indicate the role setting, function setting and output setting of the SQL assistant.

[0031] The SQL assistant 110 can execute multiple tasks 180 in sequence, and the task output of each task can be added to the input prompt word of the next task. For example, the output of task 1 can be used as the input prompt word of task 2 for further processing by the language model 170. When the final task in the multiple tasks 180 is completed, the task output of the final task can be used as the target output. For example, when the target function 130 is the SQL code completion function, the function output 190 is the completed SQL code; or when the target function 130 is the SQL code repair function, the function output 190 is the repaired SQL code, and so on.

[0032] Therefore, the solution provided according to the embodiments of the present disclosure can significantly improve the intelligence level of the SQL assistant, enable it to handle SQL-related tasks more efficiently and accurately, and improve the user experience.

[0033] It should be understood that the architecture and functions in the example environment 100 are described for exemplary purposes only and do not imply any limitation on the scope of the present disclosure. Embodiments of the present disclosure may also be applied to other environments with different structures and / or functions.

[0034] The following will combine Figures 2 to 7 The process according to the embodiment of the present disclosure is described in detail. For ease of understanding, the specific data mentioned in the following description are exemplary and are not intended to limit the scope of protection of the present disclosure. It is understood that the embodiments described below may also include additional actions not shown and / or the actions shown may be omitted, and the scope of the present disclosure is not limited in this respect.

[0035] Figure 2 A flowchart of a method 200 for generating a functional output of a SQL assistant according to an embodiment of the present disclosure is shown. The method can be executed by a SQL assistant deployed on a computing device, which can be a user terminal, a mobile device, a computer, etc., or a computing system, a single server, a distributed server, or a cloud-based server. At box 202, user input can be obtained, which instructs the SQL assistant to perform functions related to SQL processing in a natural language form, and the SQL assistant is constructed based on a language model. For example, referring to Figure 1 The SQL assistant 110 may obtain a user input 120 , which instructs the SQL assistant 110 to perform a function related to SQL processing in a natural language form, and the SQL assistant 110 is constructed based on a language model 170 .

[0036] At block 204, a target function indicated by the user input may be determined based on the user input. Figure 1 , the SQL assistant 110 can determine the target function 130 indicated by the user input 120 based on the user input 120. At block 206, a reference prompt word and a thinking chain prompt word corresponding to the target function can be obtained based on the target function, wherein the reference prompt word includes a plurality of question-answer instances corresponding to the target function, and the thinking chain prompt word includes a reasoning step corresponding to the target function. Figure 1 Based on the target function 130, the SQL assistant 110 can obtain the reference prompt words 140 and the thinking chain prompt words 150 corresponding to the target function 130, the reference prompt words 140 include multiple question and answer instances corresponding to the target function 130, and the thinking chain prompt words 150 include reasoning steps corresponding to the target function 130.

[0037] At block 208, based on the user input, reference prompt words, thought chain prompt words, and basic prompt words, the user input is split into multiple tasks corresponding to the target function, and the basic prompt words indicate at least one of the role setting, function setting, and output setting of the SQL assistant. Figure 1 The SQL assistant 110 can split the user input 120 into multiple tasks 180 corresponding to the target function 130 based on the user input 120, the reference prompt words 140, the thought chain prompt words 150 and the basic prompt words 160, and the basic prompt words 160 indicate at least one of the role setting, function setting and output setting of the SQL assistant 110.

[0038] At block 210, multiple tasks are executed sequentially, and the task output of each task in the multiple tasks is added to the input prompt word of the next task. Figure 1 , the SQL assistant 110 can execute multiple tasks 180 in sequence, and the task output of each task in the multiple tasks 180 is added to the input prompt word of the next task

[0039] At block 212, in response to a final task among the plurality of tasks being executed, a task output of the final task is determined as a target output corresponding to the target function. Figure 1 In response to a final task among the plurality of tasks 180 being executed, the SQL assistant 110 may determine a task output of the final task as a function output 190 corresponding to the target function 130 .

[0040] Therefore, according to the method 200 of the embodiment of the present disclosure, the intelligence level of the SQL assistant can be significantly improved through the use of multiple prompt words and task splitting of user input, so that it can handle SQL-related tasks more efficiently and accurately, and improve the user experience.

[0041] FIG3 shows a schematic diagram of a process 300A of using a SQL assistant according to an embodiment of the present disclosure. As shown in FIG3, when using a SQL assistant 302, the SQL assistant can input a combination prompt word 304 into and generate a corresponding output 314, wherein the combination prompt word 304 includes a user input 308, a basic prompt word 310, and a function prompt word 312. For example, the SQL assistant 302 can determine the target function according to the user input 308, and then obtain the corresponding function prompt word 312, and can combine the user input 308, the basic prompt word 310, and the function prompt word 312 to obtain the combination prompt word 304.

[0042] For example, user input 308 may be a specific demand or question input by the user in natural language form, such as "I want to query the database for all records that used product id 123 in 2022", which indicates that the user wants SQL assistant 302 to generate SQL code for querying the target. In some embodiments, SQL assistant 302 may determine the function of executing natural language generation SQL indicated by user input 308 through a language model based on the content of user input 308, thereby generating the corresponding SQL code. In some embodiments, SQL assistant 302 may execute the corresponding function based on the user's selection on the front end (e.g., selecting the function of generating SQL code).

[0043] As mentioned above, SQL assistant 302 is built based on language model. In other words, SQL assistant 302 may include language model 306, which can understand user input 308 in natural language form, and combine user input 308 with preset basic prompt words 310 and corresponding functional prompt words 312, and then perform corresponding SQL query, optimization or interpretation tasks. Language model 306 has context understanding and reasoning capabilities, so that SQL assistant 302 can efficiently handle complex SQL generation, optimization and analysis tasks and provide accurate output results. Prompt words are a technical means for guiding language models to generate specific outputs, which help the model understand the context of input content and respond to user needs by providing context information or specific instructions. In the working process of SQL assistant 302, the role of prompt words is to provide the necessary context and guidance for the language model, so that it can accurately understand the user's intentions and generate the required SQL code or other related outputs.

[0044] In some embodiments, the SQL assistant 302 may support, but is not limited to, a natural language SQL generation function, a SQL code naming function, a SQL code optimization function, a SQL code interpretation function, a SQL code repair function, and a SQL code completion function. For example, regarding the natural language SQL generation function (referred to as the Text2SQL function in the subsequent description), many users are not familiar with SQL syntax, but can use natural language to describe query requirements. The SQL assistant can parse the natural language input and convert it into the corresponding SQL query code, which can reduce the user's learning cost and improve the accuracy and efficiency of query generation.

[0045] Regarding the SQL code naming function, when naming SQL query codes, the standardization of naming is crucial to the readability and maintainability of the code. SQL Assistant can analyze the content of the SQL code and generate a summary code title to ensure that the naming is clear, concise and accurate. Regarding the SQL code optimization function, writing efficient SQL code requires a deep understanding of the working principles and optimization techniques of the database. SQL Assistant can analyze the user's SQL code and provide optimization suggestions to help users improve the performance and quality of queries.

[0046] Regarding the SQL code interpretation function, in order to improve the readability of the code, the generated SQL code needs to have corresponding comments, but many users are not good at writing comments. SQL Assistant can automatically generate code comments and explain the function and logic of the code to help users quickly understand and maintain SQL code. Regarding the SQL code repair function, when writing SQL queries, syntax errors or logic errors are common problems. SQL Assistant can detect errors in SQL code and automatically generate repair suggestions to reduce the time users spend debugging code. Regarding the SQL code completion function, SQL Assistant has an intelligent automatic completion function that can suggest table names, column names, function names, etc. based on the context, helping users quickly complete SQL code writing and improve code writing efficiency.

[0047] The basic prompt words 310 provide role settings, function settings, and output settings for the language model 306 in the SQL assistant 302. For example, the basic prompt words 310 can be set to "1. You are a senior data analyst with rich SQL experience; 2. You can help them modify SQL, explain SQL, search help documents, and answer SQL-related questions. They can use the " / " command to specify their abilities; 3. You can use " / help": answer SQL-related knowledge; " / strengthen": optimize the selected code to improve syntax and performance; " / explain": explain the selected code; " / doc": search and summarize help documents; " / why": ask code-related questions in the editing area". In some embodiments, the basic prompt words 310 can also include content related to quality incentives to promote the SQL assistant 302 to generate higher quality output. For example, the quality incentive can be "the questioner will evaluate the quality of your answer based on the following factors, such as whether it solves the problem, clarity, conciseness, and professionalism in the field of data analysis, and provide different levels of rewards based on quality."

[0048] In some embodiments, based on the user input, the data table related to the user input can be determined, and then the table information associated with the data table can be obtained from the database, and the table information includes the field name and field type of the data table. For example, the table names of all tables involved can be extracted from the user input 308, and then the field name, field type and some additional information can be queried from the database based on the table name, and the table information in the form of a string is constructed based on this information and added to the basic prompt word. By introducing table information (such as field name and field type) into the prompt word, the SQL assistant 302 can generate SQL code that is more in line with the database structure, reducing problems such as spelling errors and field type mismatches. In addition, introducing table information into the prompt word can also improve the effects of other functions of the SQL assistant (for example, SQL completion, repair, etc.).

[0049] In some embodiments, the structured table information can be generated by encapsulating the table information using Extensible Markup Language (XML), and the structured table information can be added to the basic prompt word. For example, the structured table information can be constructed using XML tags and encapsulated in " / ", and contains " <schema>"and" <name>" and other metadata sub-tags, Figure 3B A schematic diagram of structured table information 300B according to an embodiment of the present disclosure is shown. In addition, XML can be used to structure and encapsulate other parts of the prompt words to generate structured prompt words for input into the language model of the SQL assistant. By structuring the table information and other prompt words, the SQL assistant can parse and process the input information more accurately, facilitate expansion and maintenance, and reduce ambiguity, so that the SQL assistant can better respond to user needs.

[0050] Function prompt words 312 can provide details and guidance for specific tasks, helping the model to more accurately complete specific SQL tasks, such as generating queries, optimizing codes, interpreting SQL statements, etc. In some embodiments, for example, a few-shot prompting technology can be used to set multiple question and answer instances as reference prompt words. For example, when the SQL assistant 302 executes the Text2SQL function, reference prompt words related to Text2SQL can be obtained, and the reference prompt words can include multiple question and answer instances related to Text2SQL. Figure 3C A schematic diagram of reference prompt words 300C according to an embodiment of the present disclosure is shown, which includes multiple question-answering examples related to Text2SQL. By using reference prompt words related to the target function, the SQL assistant can still efficiently complete the task with a small number of examples even when the training data is limited. It should be understood that the reference prompt words obtained for different SQL functions are different.

[0051] In addition, the function prompt word 312 also includes a thinking chain prompt word related to the target function. In some embodiments, the automatic thinking chain technology can be used to generate the thinking chain prompt word. For example, first obtain a set of questions related to the target function, cluster them, and generate multiple problem clusters. Subsequently, these problem clusters are sampled to generate multiple problem samples corresponding to each problem cluster. Based on these problem samples and zero-sample thinking chain prompt words, corresponding reasoning steps are generated, and finally the thinking chain prompt words are obtained. Assuming that five sample questions are sampled, one of the sample questions can be "I want to query all records in the database that use products with id 123 in 2022". Through the zero-sample thinking chain prompt word, the large model can be used to generate reasoning steps for the problem, wherein the zero-sample thinking chain prompt word can be "Let's think step by step", and the generated reasoning steps can be "First, determine the database table related to the product; second, find the field related to the product usage time; then, identify the product with 'id' 123; finally, build a query statement to filter the records of using the product in 2022". Finally, the reasoning steps generated for each problem sample are merged as thinking chain prompt words. It should be understood that for different SQL functions, the acquired thinking chain prompt words are different.

[0052] In some embodiments, user input, basic prompt words, reference prompt words, and thought chain prompt words can be combined to generate combined prompt words. For example, these contents can be spliced ​​in order. In addition, these contents can be spliced ​​in a structured manner to generate combined prompt words, such as using XML to encapsulate each prompt word part into a hierarchical structure. For example, <input> Tags encapsulate user input, <base> Label packaging basic prompt words, <reference>Label packaging reference words, <chain>The tag encapsulates the thought chain prompt word. Through this structured splicing method, the SQL assistant can more easily parse different types of prompt words, improve processing efficiency and generation accuracy. In some embodiments, the user input can be split into multiple tasks corresponding to the target function based on the combined prompt words and the split prompt words. For example, the language model 306 can split the user input 308 into tasks based on the combined prompt words and the split prompt words, and execute multiple tasks in sequence. Figure 3D Describe the process of executing multiple rounds of subtasks.

[0053] Figure 3D FIG. 3 shows a schematic diagram of a process 300D for executing multiple rounds of subtasks according to an embodiment of the present disclosure. Figure 3D As shown, user input 322 may be "I want to query the database for all records that used product id 123 in 2022". At box 324, user splitting may be performed. For example, the splitting prompt may be "Please split the user's question <user input> into multiple subtasks", and then the language model 328 (i.e., Figure 3A The language model 306 in the text2sql function can split the user input 322 according to the combination prompt words and the split prompt words into: task 1, generate a SQL clause to query the records of using the product in 2022; task 2, generate a SQL clause to query product usage information; and task 3, merge all clauses to generate a complete SQL query.

[0054] At box 326, a task prompt word can be constructed. For example, the task prompt word of task 1 can be "Based on the question 'I want to query all records in the database that used the product with id 123 in 2022', please execute the task 'Generate a SQL clause to query the records of using the product in 2022'". Then, the language model 328 can be used to execute the task and generate the corresponding task output 330. For example, the task output 330 can be a SQL query code for task 1. The task output 330 of task 1 can then be added to the task prompt word of task 2 and executed using the language model 328. After multiple rounds of execution, the final task output 332 is used as the target output for the user input 322, that is, the generated SQL query code.

[0055] Figure 4A-4C A schematic diagram of reference prompt words 400A-400C for SQL code optimization functions according to an embodiment of the present disclosure is shown. Quality optimization of SQL code involves knowledge in multiple aspects, including index usage, connection optimization, subquery optimization, and transaction management. In order to allow the language model in the SQL assistant to have a clear understanding of the goal of code quality optimization, some embodiments of the present invention add quality optimization examples to the reference prompt words. For example, reference prompt word 400A shows an optimization example for selective queries of SQL code, including recommended practices and unrecommended practices, with the goal of minimizing the amount of data returned and selecting only the required columns and rows. For example, avoid using "SELECT *" and only select the required columns to reduce unnecessary data transmission; and use the WHERE clause in the query to filter data to reduce the amount of data processed.

[0056] Reference prompt 400B illustrates an optimization example for table joins in SQL code, including recommended practices and unrecommended practices, with the purpose of selecting the appropriate join type (such as INNER JOIN, LEFT JOIN, etc.) according to the query requirements. For example, ensure that there are indexes on the join columns to improve the efficiency of the join; and reduce the number of connected tables to simplify the query. Reference prompt 400C shows an optimization example for subqueries in SQL code. For example, when possible, use JOIN instead of subqueries to improve query efficiency; and try to avoid using nested subqueries to simplify the query logic. By using these quality optimization examples, SQL Assistant can provide users with efficient SQL code optimization suggestions, avoid common inefficient writing methods, and ensure that the generated SQL code is more concise, optimized and easy to maintain. High-quality SQL code can also reduce the load on the database and improve overall query efficiency.

[0057] Figure 5 A schematic diagram of a process 500 for generating knowledge hints for SQL code repair functions according to an embodiment of the present disclosure is shown. In order to improve the ability of SQL assistants to repair SQL code, some embodiments of the present disclosure use a technology for generating knowledge hints to support SQL code repair. Since SQL code error repair requires specific domain knowledge, which is often difficult to determine in advance, the required knowledge can be automatically generated through a language model to improve the repair effect. Figure 5 As shown, at box 502, user input 502 can be obtained, and the user input includes the SQL code that needs to be repaired. Then, knowledge generation 504 can be performed according to the user input 502, and the knowledge generation process is shown in box 506. In box 506, knowledge 516, knowledge 518 and knowledge 520 can be generated based on the prompt word 508 using the language model 514, wherein the prompt word 508 can include an instruction 510 indicating knowledge generation, a question and answer instance 512 associated with the SQL code repair, and the user input 502. It should be understood that the three knowledge generated here are shown only for exemplary purposes, and the embodiments of the present disclosure do not limit the number of generated knowledge. At box 522, knowledge integration can be performed. For example, the user input 502 can be integrated with the generated knowledge 516, knowledge 518 and knowledge 520 to generate output 524. In some embodiments, the generated instructions can be added to the reference prompt word and input into the language model of the SQL assistant together with the reference prompt word.

[0058] Figure 6 FIG. 6 is a block diagram of an apparatus 600 for generating a functional output of a SQL assistant according to some embodiments of the present disclosure. Figure 6 As shown, the device 600 includes a user input acquisition module 602, which is configured to acquire user input, the user input indicates the SQL assistant to perform functions related to SQL processing in the form of natural language, and the SQL assistant is constructed based on the language model. The device 600 also includes a target function determination module 604, which is configured to determine the target function indicated by the user input based on the user input. The device 600 also includes a function prompt acquisition module 606, which is configured to acquire reference prompt words and thinking chain prompt words corresponding to the target function based on the target function, the reference prompt words include multiple question and answer instances corresponding to the target function, and the thinking chain prompt words include reasoning steps corresponding to the target function. The device 600 also includes an input task splitting module 608, which is configured to split the user input into multiple tasks corresponding to the target function based on the user input, the reference prompt words, the thinking chain prompt words and the basic prompt words, and the basic prompt words indicate at least one of the role setting, function setting and output setting of the SQL assistant. The device 600 also includes a task sequence execution module 610, which is configured to execute multiple tasks in sequence, and the task output of each task in the multiple tasks is added to the input prompt word of the next task. In addition, the apparatus 600 further includes a function output determining module 612 configured to determine, in response to a final task among the plurality of tasks being executed, a task output of the final task as a function output corresponding to the target function.

[0059] Figure 7 A block diagram of an electronic device 700 is shown in accordance with certain embodiments of the present disclosure. Figure 7 1 shows a block diagram of an electronic device 700 according to some embodiments of the present disclosure. The electronic device 700 may be a device or apparatus described in the embodiments of the present disclosure. Figure 7 As shown, the electronic device 700 includes a central processing unit (CPU) and / or a graphics processing unit (GPU) 701, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 702 or loaded from a storage unit 708 to a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 can also be stored. The CPU / GPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704. Although not shown in FIG. Figure 7 As shown in FIG. 7 , the electronic device 700 may further include a coprocessor.

[0060] Multiple components in the electronic device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the electronic device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0061] The various methods or processes described above may be executed by the CPU / GPU 701. For example, in some embodiments, the methods may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the CPU / GPU 701, one or more steps or actions in the methods or processes described above may be performed.

[0062] In some embodiments, the methods and processes described above may be implemented as a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present disclosure.

[0063] Computer readable storage medium can be a tangible device that can hold and store instructions used by an instruction execution device. Computer readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer readable storage medium used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.

[0064] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0065] The computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, and conventional procedural programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as a separate software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present disclosure.

[0066] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0067] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0068] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the equipment, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each frame in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the frame can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous frames can actually be executed substantially in parallel, and they can also be executed in the opposite order sometimes, depending on the functions involved. It should also be noted that each frame in the block diagram and / or flow chart, and the combination of frames in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0069] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

[0070] Some example implementations of the present disclosure are listed below.

[0071] Example 1. A method for generating a functional output of a SQL assistant, comprising:

[0072] Obtaining user input, wherein the user input is in a natural language form to instruct the SQL assistant to perform a function related to SQL processing, and the SQL assistant is constructed based on a language model;

[0073] Based on the user input, determining a target function indicated by the user input;

[0074] Based on the target function, obtaining reference prompt words and thought chain prompt words corresponding to the target function, wherein the reference prompt words include a plurality of question and answer instances corresponding to the target function, and the thought chain prompt words include reasoning steps corresponding to the target function;

[0075] Splitting the user input into a plurality of tasks corresponding to the target function based on the user input, the reference prompt words, the thought chain prompt words and the basic prompt words, wherein the basic prompt words indicate at least one of the role setting, the function setting and the output setting of the SQL assistant;

[0076] Executing the plurality of tasks in sequence, wherein the task output of each task in the plurality of tasks is added to the input prompt word of the next task; and

[0077] In response to a final task among the plurality of tasks being executed, a task output of the final task is determined as a function output corresponding to the target function.

[0078] Example 2. The method according to Example 1, wherein splitting the user input into the plurality of tasks corresponding to the target functions comprises:

[0079] Generate a combined prompt word by combining the user input, the basic prompt word, the reference prompt word and the thought chain prompt word; and

[0080] Based on the user input, generating a splitting prompt word, wherein the splitting prompt word instructs the SQL assistant to perform task splitting on the user input; and

[0081] Based on the combined prompt word and the split prompt word, the user input is split into the multiple tasks corresponding to the target function.

[0082] Example 3. The method of any one of Examples 1-2, wherein performing the plurality of tasks comprises:

[0083] By executing an initial task among the plurality of tasks, a task output of the initial task is generated;

[0084] Based on the task output of the initial task, generating the task output of the intermediate task by executing the intermediate task among the plurality of tasks; and

[0085] Based on the task output of the intermediate task, a task input of the final task is generated by executing the final task of the plurality of tasks.

[0086] Example 4. According to the method of any one of Examples 1-3, the thought chain prompt word is generated by:

[0087] Obtaining a set of questions related to the target function;

[0088] Generating a plurality of problem clusters by clustering the problem set;

[0089] By sampling a plurality of problem clusters respectively, a plurality of problem samples corresponding to the plurality of problem clusters are generated;

[0090] Based on the multiple question samples and the zero-sample thinking chain prompt words, generate multiple reasoning steps corresponding to the multiple question samples; and

[0091] The thought chain prompt words are generated based on the multiple question samples and multiple reasoning steps.

[0092] Example 5. The method according to any one of Examples 1-4, further comprising:

[0093] Based on the user input, determining a data table related to the user input;

[0094] Acquire table information associated with the data table from a database, wherein the table information includes field names and field types of the data table;

[0095] Generate structured table information by encapsulating the table information using extensible markup language;

[0096] The structured table information is added to the basic prompt word.

[0097] Example 6. The method according to any one of Examples 1-5, wherein the multiple functions of the SQL assistant related to SQL processing include at least one of the following:

[0098] Natural language SQL generation function;

[0099] SQL code naming function;

[0100] SQL code optimization function;

[0101] SQL code interpretation function;

[0102] SQL code repair function; or

[0103] SQL code completion function.

[0104] Example 7. According to the method of any one of Examples 1-6, in response to the target function being a SQL optimization function, the reference hint word further includes at least one of the following:

[0105] Indicates an instance of optimization for selective queries in SQL code;

[0106] Indicates an optimized instance of table joins for SQL code; or

[0107] Indicates an instance of optimization for a subquery in SQL code.

[0108] Example 8. According to any one of Examples 1-7, in response to the target function being a SQL optimization function, the method further includes:

[0109] Based on the user input, generating target knowledge associated with the user input; and

[0110] The target knowledge is added to the reference prompt word.

[0111] Example 9. A device for generating a functional output of a SQL assistant, comprising:

[0112] a user input acquisition module configured to acquire user input, wherein the user input instructs the SQL assistant to perform functions related to SQL processing in a natural language form, and the SQL assistant is constructed based on a language model;

[0113] a target function determination module, configured to determine the target function indicated by the user input based on the user input;

[0114] a function prompt acquisition module, configured to acquire, based on the target function, reference prompt words and thought chain prompt words corresponding to the target function, wherein the reference prompt words include a plurality of question-answering instances corresponding to the target function, and the thought chain prompt words include reasoning steps corresponding to the target function;

[0115] an input task splitting module, configured to split the user input into a plurality of tasks corresponding to the target function based on the user input, the reference prompt words, the thought chain prompt words and the basic prompt words, wherein the basic prompt words indicate at least one of the role setting, the function setting and the output setting of the SQL assistant;

[0116] a task sequence execution module, configured to execute the plurality of tasks in sequence, wherein the task output of each task in the plurality of tasks is added to the input prompt word of the next task; and

[0117] The function output determination module is configured to determine, in response to a final task among the plurality of tasks being executed, a task output of the final task as a function output corresponding to the target function.

[0118] Example 10. The method according to claim 1, wherein the input task splitting module comprises:

[0119] a combination prompt generating module, configured to generate a combination prompt word by combining the user input, the basic prompt word, the reference prompt word and the thought chain prompt word; and

[0120] a task prompt generating module, configured to generate a splitting prompt word based on the user input, wherein the splitting prompt word instructs the SQL assistant to perform task splitting on the user input; and

[0121] The second task splitting module is configured to split the user input into the multiple tasks corresponding to the target function based on the combined prompt word and the split prompt word.

[0122] Example 11. The apparatus according to Example 10, wherein the task sequence execution module comprises:

[0123] An initial output generating module, configured to generate a task output of an initial task among the plurality of tasks by executing the initial task;

[0124] an intermediate output generation module configured to generate a task output of the intermediate task by executing the intermediate task among the plurality of tasks based on the task output of the initial task; and

[0125] The final output generation module is configured to generate a task input of the final task by executing the final task among the multiple tasks based on the task output of the intermediate task.

[0126] Example 12. The device according to any one of Examples 10-11, wherein the thought chain prompt words are generated by the following modules:

[0127] A question set acquisition module, configured to acquire a question set related to the target function;

[0128] A question clustering generation module is configured to generate a plurality of question clusters by clustering the question set;

[0129] A question sample generation module is configured to generate a plurality of question samples corresponding to the plurality of question clusters by sampling the plurality of question clusters respectively;

[0130] A reasoning step generation module, configured to generate a plurality of reasoning steps corresponding to the plurality of question samples based on the plurality of question samples and the zero-sample thinking chain prompt words; and

[0131] The thinking prompt generating module is configured to generate the thinking chain prompt words based on the multiple question samples and multiple reasoning steps.

[0132] Example 13. The apparatus according to any one of Examples 10-12, further comprising:

[0133] a data table determination module, configured to determine a data table related to the user input based on the user input;

[0134] A table information acquisition module is configured to acquire table information associated with the data table from a database, wherein the table information includes a field name and a field type of the data table;

[0135] The structure information generating module is configured to generate structured table information by encapsulating the table information using extensible markup language;

[0136] The structure information adding module is configured to add the structured table information to the basic prompt word.

[0137] Example 14. The apparatus according to any one of Examples 10-13, wherein the plurality of functions of the SQL assistant related to SQL processing include at least one of the following:

[0138] Natural language SQL generation function;

[0139] SQL code naming function;

[0140] SQL code optimization function;

[0141] SQL code interpretation function;

[0142] SQL code repair function; or

[0143] SQL code completion function.

[0144] Example 15. The apparatus according to any one of Examples 10-14, in response to the target function being a SQL optimization function, wherein the reference prompt word further includes at least one of the following:

[0145] Indicates an instance of optimization for selective queries in SQL code;

[0146] Indicates an optimized instance of table joins for SQL code; or

[0147] Indicates an instance of optimization for a subquery in SQL code.

[0148] Example 16. The apparatus according to any one of Examples 10-15, in response to the target function being a SQL optimization function, further comprising:

[0149] a target knowledge generation module, configured to generate target knowledge associated with the user input based on the user input; and

[0150] The target knowledge adding module is configured to add the target knowledge to the reference prompt word.

[0151] Example 17. An electronic device comprising:

[0152] Processor; and

[0153] A memory coupled to the processor, the memory having instructions stored therein, wherein when the instructions are executed by the processor, the electronic device performs actions, the actions comprising:

[0154] Obtaining user input, wherein the user input is in a natural language form to instruct the SQL assistant to perform a function related to SQL processing, and the SQL assistant is constructed based on a language model;

[0155] Based on the user input, determining a target function indicated by the user input;

[0156] Based on the target function, obtaining reference prompt words and thought chain prompt words corresponding to the target function, wherein the reference prompt words include a plurality of question and answer instances corresponding to the target function, and the thought chain prompt words include reasoning steps corresponding to the target function;

[0157] Splitting the user input into a plurality of tasks corresponding to the target function based on the user input, the reference prompt words, the thought chain prompt words and the basic prompt words, wherein the basic prompt words indicate at least one of the role setting, the function setting and the output setting of the SQL assistant;

[0158] Executing the plurality of tasks in sequence, wherein the task output of each task in the plurality of tasks is added to the input prompt word of the next task; and

[0159] In response to a final task among the plurality of tasks being executed, a task output of the final task is determined as a function output corresponding to the target function.

[0160] Example 18. The electronic device of Example 17, wherein splitting the user input into the plurality of tasks corresponding to the target functions comprises:

[0161] Generate a combined prompt word by combining the user input, the basic prompt word, the reference prompt word and the thought chain prompt word; and

[0162] Based on the user input, generating a splitting prompt word, wherein the splitting prompt word instructs the SQL assistant to perform task splitting on the user input; and

[0163] Based on the combined prompt word and the split prompt word, the user input is split into the multiple tasks corresponding to the target function.

[0164] Example 19. The electronic device of any of Examples 17-18, wherein performing the plurality of tasks comprises:

[0165] By executing an initial task among the plurality of tasks, a task output of the initial task is generated;

[0166] Based on the task output of the initial task, generating the task output of the intermediate task by executing the intermediate task among the plurality of tasks; and

[0167] Based on the task output of the intermediate task, a task input of the final task is generated by executing the final task of the plurality of tasks.

[0168] Example 20. The electronic device according to any one of Examples 17-19, wherein the thought chain prompt word is generated by:

[0169] Obtaining a set of questions related to the target function;

[0170] Generating a plurality of problem clusters by clustering the problem set;

[0171] By sampling a plurality of problem clusters respectively, a plurality of problem samples corresponding to the plurality of problem clusters are generated;

[0172] Based on the multiple question samples and the zero-sample thinking chain prompt words, generate multiple reasoning steps corresponding to the multiple question samples; and

[0173] The thought chain prompt words are generated based on the multiple question samples and multiple reasoning steps.

[0174] Example 21. The electronic device according to any one of Examples 17-20, wherein the actions further include:

[0175] Based on the user input, determining a data table related to the user input;

[0176] Acquire table information associated with the data table from a database, wherein the table information includes field names and field types of the data table;

[0177] Generate structured table information by encapsulating the table information using extensible markup language;

[0178] The structured table information is added to the basic prompt word.

[0179] Example 22. The electronic device according to any one of Examples 17-21, wherein the plurality of functions of the SQL assistant related to SQL processing include at least one of the following:

[0180] Natural language SQL generation function;

[0181] SQL code naming function;

[0182] SQL code optimization function;

[0183] SQL code interpretation function;

[0184] SQL code repair function; or

[0185] SQL code completion function.

[0186] Example 23. The electronic device according to any one of Examples 17-22, in response to the target function being a SQL optimization function, wherein the reference prompt word further includes at least one of the following:

[0187] Indicates an instance of optimization for selective queries in SQL code;

[0188] Indicates an optimized instance of table joins for SQL code; or

[0189] Indicates an instance of optimization for a subquery in SQL code.

[0190] Example 24. The electronic device according to any one of Examples 17-23, in response to the target function being a SQL optimization function, the action further comprises:

[0191] Based on the user input, generating target knowledge associated with the user input; and

[0192] The target knowledge is added to the reference prompt word.

[0193] Example 25. A computer-readable storage medium having one or more computer instructions stored thereon, wherein the one or more computer instructions are executed by a processor to implement the method according to any one of Examples 1 to 8.

[0194] Example 26. A computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions that, when executed by a device, cause the device to perform the method according to any one of Examples 1 to 8.

[0195] Although the disclosure has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Instead, the specific features and actions described above are merely example forms of implementing the claims.< / chain> < / reference> < / name> < / schema>

Claims

1. A method for generating functional output of a structured query language SQL assistant, comprising: Obtaining user input, wherein the user input is in a natural language form to instruct the SQL assistant to perform a function related to SQL processing, and the SQL assistant is constructed based on a language model; Based on the user input, determining a target function indicated by the user input; Based on the target function, obtaining reference prompt words and thought chain prompt words corresponding to the target function, wherein the reference prompt words include a plurality of question and answer instances corresponding to the target function, and the thought chain prompt words include reasoning steps corresponding to the target function; Splitting the user input into a plurality of tasks corresponding to the target function based on the user input, the reference prompt words, the thought chain prompt words and the basic prompt words, wherein the basic prompt words indicate at least one of the role setting, the function setting and the output setting of the SQL assistant; The plurality of tasks are executed in sequence, and the task output of each task in the plurality of tasks is added to the input prompt word of the next task; as well as In response to a final task among the plurality of tasks being executed, a task output of the final task is determined as a function output corresponding to the target function.

2. The method according to claim 1, wherein splitting the user input into the plurality of tasks corresponding to the target functions comprises: Generate a combined prompt word by combining the user input, the basic prompt word, the reference prompt word and the thought chain prompt word; as well as Based on the user input, generating a splitting prompt word, wherein the splitting prompt word instructs the SQL assistant to perform task splitting on the user input; as well as Based on the combined prompt word and the split prompt word, the user input is split into the multiple tasks corresponding to the target function.

3. The method of claim 1 , wherein performing the plurality of tasks comprises: By executing an initial task among the plurality of tasks, a task output of the initial task is generated; Based on the task output of the initial task, generating the task output of the intermediate task by executing the intermediate tasks among the plurality of tasks; as well as Based on the task output of the intermediate task, a task input of the final task is generated by executing the final task of the plurality of tasks.

4. The method according to claim 1, wherein the thought chain prompt words are generated by: Obtaining a set of questions related to the target function; Generating a plurality of problem clusters by clustering the problem set; By sampling a plurality of problem clusters respectively, a plurality of problem samples corresponding to the plurality of problem clusters are generated; Based on the multiple question samples and the zero-sample thinking chain prompt words, generate multiple reasoning steps corresponding to the multiple question samples; as well as The thought chain prompt words are generated based on the multiple question samples and multiple reasoning steps.

5. The method according to claim 1, further comprising: Based on the user input, determining a data table related to the user input; Acquire table information associated with the data table from a database, wherein the table information includes field names and field types of the data table; Generate structured table information by encapsulating the table information using extensible markup language; The structured table information is added to the basic prompt words.

6. The method according to claim 1, wherein the plurality of functions of the SQL assistant related to SQL processing include at least one of the following: Natural language SQL generation function; SQL code naming function; SQL code optimization function; SQL code interpretation function; SQL code repair function; or SQL code completion function.

7. The method according to claim 1, in response to the target function being a SQL optimization function, wherein the reference hint word further comprises at least one of the following: Indicates an instance of optimization for selective queries in SQL code; Indicates an optimized instance of table joins for SQL code; or Indicates an instance of optimization for a subquery in SQL code.

8. The method according to claim 7, in response to the target function being a SQL optimization function, the method further comprises: Based on the user input, generating target knowledge associated with the user input; as well as The target knowledge is added to the reference prompt words.

9. A device for generating a functional output of a SQL assistant, comprising: a user input acquisition module configured to acquire user input, wherein the user input instructs the SQL assistant to perform functions related to SQL processing in a natural language form, and the SQL assistant is constructed based on a language model; a target function determination module, configured to determine the target function indicated by the user input based on the user input; a function prompt acquisition module, configured to acquire, based on the target function, reference prompt words and thought chain prompt words corresponding to the target function, wherein the reference prompt words include a plurality of question-answering instances corresponding to the target function, and the thought chain prompt words include reasoning steps corresponding to the target function; an input task splitting module, configured to split the user input into a plurality of tasks corresponding to the target function based on the user input, the reference prompt words, the thought chain prompt words and the basic prompt words, wherein the basic prompt words indicate at least one of the role setting, the function setting and the output setting of the SQL assistant; A task sequence execution module is configured to execute the plurality of tasks in sequence, and the task output of each task in the plurality of tasks is added to the input prompt word of the next task; as well as The function output determination module is configured to determine, in response to a final task among the plurality of tasks being executed, a task output of the final task as a function output corresponding to the target function.

10. An electronic device comprising: processor; as well as A memory coupled to the processor, the memory having instructions stored therein, wherein when the instructions are executed by the processor, the electronic device executes the method according to any one of claims 1 to 8.

11. A computer program product tangibly stored on a non-transitory computer readable medium and comprising computer executable instructions for performing the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Model-based interaction method and device, electronic equipment and storage medium

    CN117235222A

  • Data query statement generation method and device, equipment and storage medium

    CN117453717A