Program generation method and device, equipment and storage medium

By obtaining demand information and using generative models to generate target program code, the problems of high threshold and low efficiency of program development in the existing technology are solved, and fast and efficient program development is achieved.

CN120215883APending Publication Date: 2025-06-27GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311799442.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-25
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

In the prior art, the threshold for program development is high and the efficiency is low, and it requires requirements analysis and code writing, resulting in a long development cycle and low writing efficiency.

Method used

By obtaining requirements information, performing capability search and sample search based on requirements information, obtaining target capability and target code sample fragments, constructing prompt text for generative models, and generating target program code through generative models to meet functional requirements.

Benefits of technology

It lowers the threshold for program development and improves the efficiency of program development. Users only need to enter the requirements information to generate target program code, eliminating the process of demand analysis and program code writing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120215883A_ABST
    Figure CN120215883A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a program generation method and device, equipment and a storage medium, and belongs to the technical field of artificial intelligence, the method comprises the steps that demand information is acquired, and the demand information is used for describing function demands needing to be met; capacity retrieval and example retrieval are conducted on the basis of the demand information, target capacity and target code example fragments are obtained, the target capacity is the capacity called for meeting the function demand, and the target code example fragments are program code example fragments related to the function demand; building a prompt text of a generative model based on the demand information, the target capability, the target code example fragment and the target program code grammar rule; based on the prompt text, a target program code is generated through a generative model, and a program corresponding to the target program code is used for meeting functional requirements; by adopting the scheme provided by the embodiment of the invention, the program development threshold can be reduced, and the program development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the field of artificial intelligence, and particularly to a program generation method, apparatus, device, and storage medium. Background Art

[0002] Computer devices can implement a variety of functions through installed programs. Common programs can include applications, mini programs, and so on.

[0003] In the related art, programs are usually written by developers with a code foundation, and a series of requirement analyses are required before code writing, resulting in a high threshold and low efficiency for program development. Summary of the Invention

[0004] Embodiments of the present application provide a program generation method, apparatus, device, and storage medium. The technical solutions are as follows:

[0005] On the one hand, embodiments of the present application provide a program generation method, the method including:

[0006] Obtain requirement information, where the requirement information is used to describe the functional requirements to be met;

[0007] Based on the requirement information, perform ability retrieval and example retrieval to obtain a target ability and a target code example segment, where the target ability is the ability called to meet the functional requirements, and the target code example segment is a program code example segment related to the functional requirements;

[0008] Based on the requirement information, the target ability, the target code example segment, and the target program code syntax rules, construct a prompt text for a generative model;

[0009] Based on the prompt text, generate target program code through the generative model, where the program corresponding to the target program code is used to meet the functional requirements.

[0010] On the other hand, embodiments of the present application provide a program generation apparatus, the apparatus including:

[0011] An obtaining module, configured to obtain requirement information, where the requirement information is used to describe the functional requirements to be met;

[0012] A retrieval module, configured to perform ability retrieval and example retrieval based on the requirement information to obtain a target ability and a target code example segment, where the target ability is the ability called to meet the functional requirements, and the target code example segment is a program code example segment related to the functional requirements;

[0013] A construction module for constructing a prompt text of a generative model based on the requirement information, the target capabilities, the target code example segments, and the target program code syntax rules;

[0014] A generation module for generating a target program code based on the prompt text through the generative model, and the program corresponding to the target program code is used to meet the functional requirements.

[0015] On the other hand, an embodiment of the present application provides a computer device, which includes a processor and a memory; the memory stores at least one computer instruction, and the at least one computer instruction is used to be executed by the processor to implement the program generation method as described in the above aspect.

[0016] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which stores at least one computer instruction, and the at least one computer instruction is used to be executed by a processor to implement the program generation method as described in the above aspect.

[0017] On the other hand, an embodiment of the present application provides a computer program product, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device implements the program generation method as described in the above aspect.

[0018] In the embodiment of the present application, since the generative model has powerful requirement understanding and content generation capabilities, the computer device uses the generative model to generate the target program code. In order to help the generative model understand the requirement information and improve the integrity and accuracy of the generated target program code, the computer device screens the capabilities and code example segments according to the requirement information to obtain the target capabilities and target code example segments, and then constructs the prompt text of the generative model by using the target capabilities, target code example segments, requirement information, and target program code syntax rules. Therefore, the user only needs to input the requirement information to generate the target program code through the generative model, eliminating the process of requirement analysis and program code writing, reducing the threshold of program development, and improving the efficiency of program development. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 is a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application; Figure 2 shows a flowchart of a program generation method provided by an exemplary embodiment of the present application; Figure 3It is an implementation schematic diagram of the construction process of the prompt text provided by an exemplary embodiment of the present application; Figure 4 It is an implementation schematic diagram of the process of supplementing capabilities through example retrieval provided by an exemplary embodiment of the present application; Figure 5 It shows a flowchart of a program generation method provided by another exemplary embodiment of the present application; Figure 6A It shows a schematic diagram of the capability information in json format provided by an exemplary embodiment of the present application; Figure 6B It shows a schematic diagram of the capability information in csv format provided by an exemplary embodiment of the present application; Figure 7 It is an implementation schematic diagram of the code inspection process provided by an exemplary embodiment of the present application; Figure 8 It is an implementation schematic diagram of the target program code loop generation process provided by an exemplary embodiment of the present application; Figure 9 It shows an implementation schematic diagram of the program generation process provided by an exemplary embodiment of the present application; Figure 10 It shows a structural block diagram of a program generation device provided by an exemplary embodiment of the present application; Figure 11 It shows a structural block diagram of a computer device provided by an exemplary embodiment of the present application. Detailed implementation manners

[0030] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the accompanying drawings.

[0031] As used herein, "a plurality of" means two or more. "And / or" describes the association relationship of associated objects and indicates that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.

[0032] Traditional program development requires entrusting developers with code foundations to write program code. Before writing the program code, requirements analysis also needs to be carried out, resulting in a long program development cycle and low writing efficiency of the program code. In addition, the runnable program code has high requirements for code accuracy, content logic, and syntax correctness, resulting in a relatively high threshold for program development.

[0033] In the embodiments of the present application, in order to lower the threshold of program development and improve the efficiency of program development, a program generation solution based on natural language requirement expression (which can be in the form of text, pictures, or multimedia) is provided. In this solution, a computer device can generate target program code that meets the functional requirements according to the requirement information (used to indicate the functional requirements to be met) and its own capabilities (including the services that the computer device can call and the service events composed of the services) by virtue of the requirement understanding and content generation capabilities of the generative model.

[0034] In some possible usage scenarios, after the user describes the requirement information, they wait for the computer device to generate program code to obtain the target program code.

[0035] Optionally, the solution provided in the embodiments of the present application can be implemented on one computer device or between two computer devices. The computer device is an electronic device with a requirement for program code generation. The computer device can be a smart phone, a tablet computer, a personal computer, an in-vehicle terminal (car computer), and so on. Please refer to Figure 1 , which shows a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application. The implementation environment includes a first terminal 110 and a second terminal 120.

[0036] Hereinafter, an example will be given in which the solution provided in the embodiments of the present application is implemented between the first terminal 110 and the second terminal 120. Among them, the first terminal 110 is a smart phone, and the second terminal 120 is a car computer.

[0037] In some embodiments, the first terminal 110 or the second terminal 120 dynamically generates target program code based on the requirement information. Among them, the requirement information may include at least one of text, pictures, or multimedia (audio and video), and the text may be user input text, or natural language text obtained by converting natural language instructions, or text obtained by semantic analysis of multimedia content (such as pictures, videos, etc.).

[0038] In some embodiments, the target program code dynamically generated by the first terminal 110 is only used to control the capabilities of the first terminal, and the target program code dynamically generated by the second terminal 120 is only used to control the capabilities of the second terminal, that is, the computer device only dynamically generates target program code based on its own capabilities and functional requirements.

[0039] In some other embodiments, when control is supported through data communication (direct connection communication or communication via a server) between the first terminal 110 and the second terminal 120 (it can be that the first terminal controls the second terminal unidirectionally, or it can be that the first terminal and the second terminal control each other bidirectionally), the target program code dynamically generated by the first terminal 110 supports invoking the capabilities of the second terminal 120, or the target program code dynamically generated by the second terminal 120 supports invoking the capabilities of the first terminal 110, that is, the computer device can dynamically generate target program code based on its own capabilities, the capabilities of other devices, and functional requirements.

[0040] In Figure 1 In the shown implementation environment, the smart phone has established a wireless communication connection (such as a Bluetooth connection) with the in-vehicle unit, and the smart phone supports controlling vehicle functions through this wireless communication connection. When the user issues a natural language instruction and the functional requirement indicated by the natural language instruction is implemented by the smart phone, the smart phone dynamically generates target program code including the capabilities of the phone. For example, after the user issues a natural language instruction, the smart phone generates target program code for a scenario arrangement interface that automatically uses the phone navigation and plays a playlist after getting in the car.

[0041] When the user issues a natural language instruction and the functional requirement indicated by the natural language instruction needs to be implemented by the in-vehicle unit, the smart phone dynamically generates target program code including the capabilities of the in-vehicle unit to facilitate the user to set the in-vehicle unit. For example, the smart phone generates target program code for a parameter adjustment interface for adjusting functions such as seat angle, seat ventilation, ambient light, seat heating, and seat massage.

[0042] In some embodiments, the computer device generates target program code by means of the requirement understanding and content generation functions of a generative model. Among them, the generative model is used to generate target program code based on requirement information, and the generative model can be deployed locally on the computer device or deployed at the server for the computer device to make a remote call.

[0043] In some embodiments, the target program code is intermediate code between the requirement information and the program, used to describe the situation of capability invocation. Based on this target program code, the computer device can further generate a target program. For example, according to the target program code, a user interface program can be further generated, and this program can meet the user's functional requirements.

[0044] In the following various embodiments, the program generation method is described by taking the computer device in the above implementation environment as an example.

[0045] Please refer to Figure 2 , which shows a flowchart of a program generation method provided by an exemplary embodiment of the present application. The method includes the following steps:

[0046] Step 201: Obtain requirement information, which is used to describe the functional requirements to be met.

[0047] Optionally, the requirement information may include at least one of text, pictures, or multimedia. For example, a computer device can obtain the requirement text alone, or can obtain the requirement text and pictures simultaneously (for example, the requirement text indicates setting a picture as the in-vehicle head unit background), or can obtain the requirement text and videos simultaneously (for example, the requirement text indicates setting a video as the screensaver animation), or can obtain pictures or videos alone. The embodiments of the present application do not limit the specific content included in the requirement information. For the convenience of description, in the following embodiments, the requirement information is taken as the requirement text as an example for illustration, but this is not a limitation. In some embodiments, the requirement text is a manually input text, or a natural language text obtained by text conversion of a natural language instruction, or a text obtained by semantic recognition of multimedia content, etc. The embodiments of the present application do not limit the acquisition method of the requirement text.

[0048] Moreover, the requirement text can be input in the foreground through a specific interface (such as a human-machine chat interface), or can be input in the background through a voice assistant or other means. This embodiment does not make a limitation on this.

[0049] In the embodiments of the present application, the functional requirements described by the requirement text may include specific functional requirements or abstract functional requirements.

[0050] For example, the requirement text is "I want to adjust the seat angle and seat ventilation". Among them, adjusting the seat angle and seat ventilation are specific functional requirements. Correspondingly, the program code to meet this requirement needs to support adjusting the seat angle and seat ventilation.

[0051] Another example, the requirement text is "I want to take a rest in the car". Among them, taking a rest in the car is an abstract functional requirement. Correspondingly, the program code to meet this requirement needs to call the capabilities related to rest in the in-vehicle head unit.

[0052] Step 202: Perform ability retrieval and example retrieval based on the requirement information to obtain a target ability and a target code example snippet. The target ability is the ability called to meet the functional requirements, and the target code example snippet is a program code example snippet related to the functional requirements.

[0053] The target code example snippet is a reference example for the generative model, enabling the generative model to imitate the reference example to generate the target program code.

[0054] In some embodiments, due to the limited capabilities of the computer device, the computer device can perform a capabilities retrieval and an example retrieval based on the requirement information, so as to obtain a target capability and a target code example snippet. Among them, the relevance of the target capability to the requirement information is higher than that of other capabilities, and the relevance of the target code example snippet to the requirement information is higher than that of other code example snippets.

[0055] Step 203: Construct a prompt text for the generative model based on the requirement information, the target capability, the target code example snippet, and the target program code syntax rules.

[0056] The target program code syntax rules are used to help the generative model understand and apply the syntax rules of the program code. Optionally, the target program code syntax rules can be DSL (Domain Specific Language) syntax rules, such as the syntax rules of XML (Extensible Markup Language). The target program code syntax rules can be described in natural language or in other syntax formats, and the embodiments of the present application do not limit this.

[0057] The prompt text (Prompt) is used to prompt the generative model to generate a target program code that meets the requirement information and has a complete function according to the target program code syntax rules. The prompt text also includes a role setting and a problem description for the generative model. For example, "You are a program generation expert. Please generate a DSL text according to my requirements."

[0058] In a schematic example, as Figure 3 shown, it is a schematic diagram of the implementation process of constructing the prompt text. The computer device first obtains the requirement information 301 input by the user, and then performs a capabilities retrieval and an example retrieval according to the requirement information 301 to obtain the target capability 302 and the target code example snippet 303 respectively. Finally, the requirement information 301, the target capability 302, the target program code syntax rules 303, the target code example snippet 304, the role setting 305, and the problem description 306 are combined to obtain the prompt text 307. The prompt text 307 is as follows:

[0059] You are a program generation expert. Please generate a DSL text according to my requirements.

[0060] My requirements:

[0061] [I want to turn on the massage function]

[0062] The program code syntax rules are as follows:

[0063] [DSL syntax]

[0064] The following capabilities can be invoked:

[0065] [List of target capabilities]

[0066] The following is a code example snippet:

[0067] [Target code example snippet].

[0068] Step 204, based on the prompt text, generate target program code through a generative model. The program corresponding to the target program code is used to meet the functional requirements.

[0069] The generative model (Artificial Intelligence Generated Content, AIGC) is a large language model (Large Language Model, LLM) with powerful natural language understanding and reasoning capabilities, and can output the target program code for invoking the target capabilities according to the input requirement information.

[0070] Optionally, the generative model can be a GPT (Generative Pre-Trained Transformer) model, an LLaMA model, a T5 model, etc. The embodiments of the present application do not limit the specific type of the generative model.

[0071] In summary, in the embodiments of the present application, since the generative model has powerful requirement understanding and content generation capabilities, the computer device uses the generative model to generate target program code. To help the generative model understand the requirement information and improve the integrity and accuracy of the generated target program code, the computer device filters the capabilities and code example snippets according to the requirement information to obtain the target capabilities and target code example snippets, and then constructs the prompt text of the generative model using the target capabilities, target code example snippets, requirement information, and target program code syntax rules. Therefore, the user only needs to input the requirement information to generate the target program code through the generative model, eliminating the process of requirement analysis and program code writing, reducing the threshold of program development, and improving the efficiency of program development.

[0072] The process of the computer device performing capability retrieval and example retrieval based on the requirement information may include the following steps.

[0073] Step 1, perform capability retrieval in the capability list based on the requirement information to obtain the target capabilities.

[0074] Among them, the capability list is used to store the relevant information of all capabilities that can be invoked by the computer device, including capability numbers, capability names, capability descriptions, input parameters, etc.

[0075] Exemplarily, the relevant information of the in-vehicle reading light control ability in the ability list is as follows. Here, serviceId is the ability number, serviceName is the ability name, serviceDescription is the ability description, and inputParams are the input parameters used to control the in-vehicle reading light. The input parameters include paramName, isRequired, constraints, and description.

[0076]

[0077] In some embodiments, since the input parameters in the ability list are variable information, while the ability number, ability name, and ability description are fixed information, the computer device retrieves abilities based on the fixed information such as the ability number, ability name, and ability description of the candidate abilities in the ability list, and then determines the candidate ability with a high degree of relevance to the demand information as the target ability.

[0078] In a possible implementation, the computer device pre-sets a relevance threshold, and then determines the candidate ability with a relevance exceeding the relevance threshold to the demand information as the target ability.

[0079] Step 2: Perform example retrieval in the example list based on the demand information to obtain the target code example snippet.

[0080] It should be noted that in the embodiments of the present application, Step 1 and Step 2 can be executed synchronously, and the embodiments of the present application do not limit the execution timing of Step 1 and Step 2.

[0081] The example list is used to store code example snippets for invoking the abilities of the computer device. The following is a code example snippet in XML format. Here, the code example snippet invokes the massage ability of the vehicle seat through <car-seat-massage-service-action status="1"level="2"position="1" / >.

[0082]

[0083] In a possible implementation, the computer device determines the target code example snippet from the example list based on the target ability. The target code example snippet is a candidate code snippet for invoking the target ability, and the target code example snippet is added to the prompt text.

[0084] In another possible implementation, the computer device calculates the relevance between the candidate code example snippet and the demand information based on the task description information of the candidate code example snippet, and then determines the candidate code example snippet with a high relevance as the target code example snippet.

[0085] Optionally, the computer device can perform capability retrieval and example retrieval through content recall, or the computer device can also perform capability retrieval and example retrieval through vector recall.

[0086] Among them, the ways for the computer device to perform capability retrieval can include at least one of the following.

[0087] 1. Perform content recall based on the requirement information and the capability description information of the candidate capabilities in the capability list to obtain the target capability.

[0088] The capability description information is used to describe the role of the candidate capabilities. In a possible implementation manner, the computer device calculates the text similarity between the requirement information and the capability description information through keyword matching, so as to determine the correlation degree between the functional requirement and the candidate capabilities, and then determines the candidate capabilities with a high correlation degree as the target capabilities.

[0089] 2. Perform vector recall based on the requirement representation vector corresponding to the requirement information and the capability representation vector corresponding to the candidate capabilities in the capability list to obtain the target capability, and the capability representation vector is obtained by vectorizing the capability description information of the candidate capabilities.

[0090] In a possible implementation manner, the computer device calculates the vector similarity of the requirement representation vector and the capability representation vector, such as cosine similarity or Euclidean distance, and determines the candidate capabilities with a high vector similarity as the target capabilities.

[0091] It should be noted that in the case of performing capability retrieval through content recall and vector recall, the computing device determines all the capabilities obtained by content recall and vector recall as the target capabilities.

[0092] The ways for the computer device to perform example retrieval can include at least one of the following.

[0093] The first type is to perform content recall based on the requirement information and the task description information of the candidate code example segments in the example list to obtain the target code example segments.

[0094] The task description information is used to describe the corresponding tasks processed by the candidate code example segments. In a possible implementation manner, the computer device calculates the text similarity between the requirement information and the task description information through keyword matching, so as to determine the correlation degree between the functional requirement and the candidate code example segments, and then determines the candidate capabilities with a high correlation degree as the target code example segments.

[0095] The second method is to perform vector recall based on the demand representation vector corresponding to the demand information and the task representation vector corresponding to the candidate code example segments in the example list, to obtain the target code example segments. The task representation vector is obtained by vectorizing the task description information of the candidate code example segments.

[0096] In a possible implementation, the computer device calculates the vector similarity between the demand representation vector and the task representation vector, such as cosine similarity or Euclidean distance, and determines the candidate code example segments with high vector similarity as the target code example segments.

[0097] It should be noted that in the case of example retrieval through content recall and vector recall, the computing device determines all the code example segments obtained by content recall and vector recall as the target code example segments.

[0098] Furthermore, in order to improve the effect of ability retrieval and example retrieval, the computer device can also obtain the target ability and the target code example segments with high language matching degree with the demand information by using a semantic matching model. Among them, the target ability is obtained through the first semantic matching model, and the target code example segments are obtained through the second semantic matching model.

[0099] From the above reasoning, it can be known that the ability retrieval can include the following steps.

[0100] Step 1: Input the demand information and the ability description information into the first semantic matching model to obtain the first semantic matching result output by the first semantic matching model. The first semantic matching model is trained based on the first sample downstream task dataset, which includes sample downstream demand information, ability description information, and the first semantic matching label. The first semantic matching label is used to represent whether the sample downstream demand information and the ability description information are semantically matched.

[0101] Among them, the first sample downstream task is strongly related to the application scenario. The computer device can determine the first sample downstream task according to the application scenario of the target program code, and then train the first semantic matching model based on the first sample downstream task dataset of the first sample downstream task.

[0102] Exemplarily, when the target program code is used to generate a vehicle control program, the computer device can determine that the first sample downstream task is a task strongly related to the vehicle control function. Therefore, the computer device trains the first semantic matching model based on the first sample downstream task dataset corresponding to the vehicle control task.

[0103] Step 2: In the case where the first semantic matching result indicates semantic matching, determine the candidate ability corresponding to the ability description information as the target ability.

[0104] As can be seen from the above reasoning, example retrieval may include the following steps.

[0105] Step 1: Input the requirement information and task description information into the second semantic matching model to obtain the second semantic matching result output by the second semantic matching model. The second semantic matching model is trained based on the second sample downstream task dataset, which includes sample downstream requirement information, task description information, and second semantic matching labels. The second semantic matching labels are used to represent whether the sample downstream requirement information and the task description information are semantically matched.

[0106] Among them, the second sample downstream task is strongly related to the application scenario. The computer device can determine the second sample downstream task according to the application scenario of the target program code, and then train the second semantic matching model based on the second sample downstream task dataset of the second sample downstream task.

[0107] Exemplarily, when the target program code is used to generate a financial data management program, the computer device can determine that the second sample downstream task is a task strongly related to the financial data management function. Therefore, the computer device trains the second semantic matching model based on the second sample downstream task dataset corresponding to the financial data management task.

[0108] Step 2: When the second semantic matching result indicates semantic matching, determine the candidate code example segment corresponding to the task description information as the target code example segment.

[0109] Furthermore, since the target code example segment obtained by example retrieval has a high correlation with the requirement information, the functions called in the target code example segment may meet the functional requirements of the requirement information. The computer device can supplement the target capabilities retrieved by the capabilities based on the capabilities called in the target code example segment, so as to improve the integrity of the capabilities called in the target program code and the accuracy of the target program code.

[0110] Exemplarily, the process of supplementing capabilities through example retrieval is as Figure 4 shown. The computer device vectorizes the candidate capabilities 411 in the capability list 410 and the candidate code example segment 421 in the example list 420 to obtain the capability representation vector 412 and the task representation vector 422. When the user inputs the requirement information 400, the computer device performs vector recall based on the requirement representation vector 401 corresponding to the requirement information and the capability representation vector 412 to obtain the target capability 413, performs vector recall based on the requirement representation vector 401 and the task representation vector 422 to obtain the target code example segment 423, and then supplements the target capability 413 according to the capabilities called in the target code example segment to obtain the supplemented target capability 414.

[0111] In an embodiment of the present application, on the one hand, the computer device retrieves, from the capability list, capabilities highly associated with the requirement information based on the requirement information, so as to obtain the target capabilities. This not only narrows the scope of capability calls of the generative model, improves the generation speed of the target program code, but also helps to improve the accuracy of the generated target program code. On the other hand, the computer device retrieves, from the example list, target code example segments highly associated with the requirement information based on the requirement information, provides reference examples for the generative model, and improves the accuracy of the generative model in generating the target program code. The capabilities called in the target code example segments can also supplement the target capabilities retrieved by the capabilities, further improving the accuracy of the generated target program code.

[0112] Please refer to Figure 5 , which shows a flowchart of a program generation method provided by another exemplary embodiment of the present application. The method includes the following steps.

[0113] Step 501: Obtain requirement information, where the requirement information is used to describe the functional requirements to be met.

[0114] Step 502: Perform capability retrieval in the capability list based on the requirement information to obtain target capabilities.

[0115] Step 503: Perform example retrieval in the example list based on the requirement information to obtain target code example segments.

[0116] The implementation manner of this step may refer to step 201, and the implementation manners of steps 502 to 503 may refer to steps 202A to 202B. The embodiments of the present application will not elaborate herein.

[0117] Step 504: Supplement the target capabilities retrieved by the capabilities based on the capabilities called in the target code example segments.

[0118] On the one hand, in the case where the generative model is an open-source large model, since the use of an open-source large model generally takes the number of tokens as the charging standard, in order to reduce the economic cost and improve the usability of the solution provided by the present application, the computer device needs to reduce the consumption quantity of tokens. Without performing capability retrieval, the computer device will consume a large number of tokens.

[0119] Exemplarily, as shown in Table 1, the computer device asks questions to the generative model and counts metrics such as the total number of tokens consumed total_tks, the number of tokens consumed by the prompt prompt_tks, the number of tokens consumed by the generated answer completion_tks, and the total cost of tokens total_cost of the computer device, so as to compare the token consumption quantities. Among them, the ability retrieval methods include vector recall method and content recall method. After the computer device retrieves through content recall and vector recall, the total number of tokens consumed, the number of tokens consumed by the prompt, and the total cost of tokens all decrease. Therefore, performing ability retrieval can reduce the token consumption quantity.

[0120] Table 1

[0121] Search strategy total_tks prompt_tks completion_tks total_cost Do not search 5853.26 5731.38 121.88 0.021 Content recall 2477.73 2356.65 121.083 0.008 Vector recall 2397.07 2268.42 128.65 0.007

[0122] On the other hand, since the recall rates of the content recall and vector recall methods for determining the target ability are relatively low, the computer device needs to improve the recall rate of ability retrieval.

[0123] In summary, the embodiment of the present application uses the ability called in the target code example segment obtained by example retrieval to supplement the target ability retrieved by ability, so as to improve the recall rate of ability retrieval while reducing the token consumption quantity.

[0124] Step 505, based on the target ability and the target code example segment, determine the target program code syntax rules from the full set of program code syntax rules. The target program code syntax rules include the syntax rules for calling the target ability and the syntax rules included in the target code example segment.

[0125] The full set of program code syntax rules is all the syntax rules corresponding to the target program code. The full set of program code syntax rules can be DSL syntax rules, and DSL syntax rules are used to represent the syntax rules of a specific domain language. However, it is difficult for the generative model to understand DSL syntax rules.

[0126] In some embodiments, the generative model is an LLM, and a large number of BNF (Backus-Naur Form) syntax rules are included in the training corpus of the LLM. From this, it can be seen that the LLM can better understand BNF syntax rules.

[0127] Compared with the DSL syntax rules described in natural language, BNF can reduce the number of errors in the target program code generated by the generative model, thereby improving the accuracy of the target program code.

[0128] Exemplarily, as shown in Table 2, compared with the DSL grammar rules described in natural language, in the case of the existence of a single target code example snippet, when the DSL grammar rules are described in BNF format, the number of syntax errors is less and the accuracy is higher. In the case of the existence of five target code example snippets, the number of syntax errors is further reduced and the accuracy is further improved.

[0129] Table 2

[0130] Syntax description format Number of examples Number of syntax errors Accuracy rate Natural language 1 14 0.517 BNF syntax 1 3 0.650 Natural language 5 6 0.650 BNF syntax 5 0 0.717

[0131] In summary, in order to enable the generative model to understand the DSL grammar rules and improve the normativity of the target program code generated by the generative model, the embodiments of the present application use BNF grammar to represent the DSL grammar rules, that is, use BNF grammar to represent the grammar rules of the full amount of program code.

[0132] Furthermore, the embodiments of the present application determine the target program code grammar rules from the grammar rules of the full amount of program code, narrow the scope of use of the program code grammar rules of the generative model, and improve the accuracy of the grammar rules of the target program code generated by the generative model.

[0133] Exemplarily, the grammar rules of the target program code represented by the BNF grammar rules are as follows. Among them, ::= represents definition, the content in "" represents characters, and the content in | is optional content, which can be used to represent the value range. The grammar rules of the target program code mainly describe the label composition of the program code snippet, including <app> 、 <trigger>Such tags are defined, and the attributes of some tags are defined.

[0134]

[0135] Step 506: Perform format conversion on the ability information of the target ability and the syntax rules of the target program code, where the format conversion is used to reduce the number of tokens of the ability information of the target ability and the syntax rules of the target program code.

[0136] After reducing the token consumption quantity through step 504 in the embodiment of the present application, the token consumption quantity is still relatively large.

[0137] Exemplarily, as shown in Table 3, the computer device calculates the token consumption quantity after ability supplementation, the token consumption quantity after ability retrieval through vector recall, and the token consumption quantity after ability retrieval through content recall by statistically analyzing indicators such as the total token consumption total_tks, the token consumption of the prompt prompt_tks, the token consumption of the generated answer completion_tks, and the total token cost total_cost.

[0138] Table 3

[0139] Search strategy total_tks prompt_tks completion_tks total_cost Ability supplement 2801.88 2672.32 129.567 0.009 Content recall 2477.73 2356.65 121.083 0.008 Vector recall 2397.07 2268.42 128.65 0.007

[0140] Among them, after supplementing the target ability retrieved by the ability based on the ability called in the target code example snippet, the total token consumption, the token consumption of the prompt, the token consumption of the generated answer, and the total token cost are all relatively large.

[0141] To further reduce the token consumption quantity, this step starts from the prompt text and reduces the number of tokens of the ability information of the target ability and the syntax rules of the target program code in the prompt text.

[0142] Exemplarily, Figure 6A and Figure 6B show schematic diagrams of the ability information in the prompt text in different formats, where Figure 6A is a schematic diagram of the ability information in json format, Figure 6B is a schematic diagram of the ability information in csv format. In json format, strings such as description, inputParams, name, and outputParams appear in large numbers of repetitions, resulting in the consumption of a large number of redundant tokens, while csv format omits a large number of repeated strings, and the ability information is relatively concise, reducing the token consumption quantity.

[0143] As can be inferred from the above reasoning, a computer device can convert the capability information of a target capability in JSON format or other formats into the capability information of the target capability in CSV format, thereby reducing the number of tokens of the capability information of the target capability. Similarly, the computer device can also perform format conversion on the syntax rules of the target program code, thereby reducing the number of tokens of the syntax rules of the target program code.

[0144] It should be noted that in the embodiments of the present application, steps 504 and 506 are not necessary steps. The computer device can, after executing steps 502 and 503, execute step 505 to determine the target program code syntax rules from the full set of program code syntax rules, and then execute step 507. The computer device can also add step 504 and / or step 506 during the execution of the method.

[0145] Step 507, construct a prompt text for the generative model based on the requirement information, target capability, target code example snippet, and target program code syntax rules.

[0146] The implementation manner of this step can refer to step 203, and the embodiments of the present application will not elaborate here.

[0147] Step 508, based on the prompt text, generate the target program code through the generative model, and the program corresponding to the target program code is used to meet the functional requirements.

[0148] The implementation manner of this step can refer to step 204, and the embodiments of the present application will not elaborate here.

[0149] In the above steps, the computer device narrows the scope of capability calls through capability retrieval, provides reference examples for the generative model through example retrieval, and supplements the target capability with the capabilities called in the target code example snippet, improving the integrity and accuracy of the generated target program code, reducing the number of tokens, and saving economic costs.

[0150] Although adding the target program code syntax rules to the prompt text can improve the syntax accuracy of the generated target program code, the target program code generated by the computer device through the above steps may still have syntax errors, and the generative model may fabricate fictional content during the process of generating the target program code. Therefore, the embodiments of the present application may further include the following steps.

[0151] Step 509, perform code checking on the target program code using the capability information of the target capability and the target program code syntax rules. The code checking includes fictional content checking and syntax checking. The fictional content checking is used to check whether the target program code contains fictional capabilities or fictional capability parameters.

[0152] In a possible implementation, after the generative model generates the target program code, on the one hand, the computer device compares the capability information of the target capability with the capabilities and their capability parameters called in the target program code by querying the capability list, so as to determine whether there are fictional capabilities or fictional capability parameters. On the other hand, the computer device performs a syntax check on the relevant syntax in the target program code using the syntax rules of the target program code to ensure that the syntax used in the target program code conforms to the syntax rules of the target program code.

[0153] Among them, in the case where the target program code passes the code check, the computer device outputs the target program code; in the case where the target program code fails the code check, the computer device generates an error message according to the check result of the code check to describe the error reason of the target program code for subsequent correction.

[0154] Step 510, in the case where the target program code fails the code check, input the target program code and the error message obtained from the code check into the generative model to obtain the adjusted target program code.

[0155] After obtaining the adjusted target program code, the computer device can continue to execute step 509 to perform a code check until the target program code passes the code check, so as to ensure that the target program code is correct and available, thus avoiding errors when generating a program based on the target program code subsequently.

[0156] Exemplarily, Figure 7 An implementation schematic diagram of the code check process is shown. After the prompt text 701 is generated, the computer device inputs the prompt text 701 into the generative model 702 to obtain the target program code 703. Subsequently, a code check is performed on the target program code 703. In the case where the target program code 703 is correct, the target program 704 is generated according to the target program code 703. In the case where the target program code 703 has an error, the computer device generates an error message 705. Subsequently, the error message 705 and the target program code 703 are input into the generative model 702 to obtain the adjusted target program code 703, and then the code check is performed again.

[0157] Furthermore, in order to ensure the correctness of the generated target program code, the computer device can set a code length control parameter, and based on the prompt text and the code length control parameter, the generative model is used to repeatedly generate the target program code.

[0158] In a possible implementation, after the generative model generates a target program code of a certain length, code checking is performed on the currently generated target program code. If the code checking passes, the current target program code is used as the input for the next loop generation to continue generating a target program code of a certain length until the complete target program code is obtained. Finally, the computer device outputs the complete and correct target program code.

[0159] Exemplarily, as Figure 8 FIG. is an implementation schematic diagram of the loop generation process of the target program code. The computer device first generates a target program code segment 801 according to the code length control parameter. Subsequently, after the target program code segment 801 passes the code check, the target program code segment 801 is input into the generative model 802 to loop-generate a target program code segment 803. Then, after the target program code segment 803 passes the code check, the target program code segment 803 is input into the generative model 802 to obtain a target program code segment 804. Subsequent loop generations are performed to obtain the complete target program code 805. If the target program code 805 passes the code check, the target program code 805 is used as the output of the computer device.

[0160] In the embodiments of the present application, the computer device supplements the target capabilities by using the capabilities called in the target code example segments, improving the integrity of the capabilities called in the target program code, thereby ensuring that the capabilities called in the target program code can meet the functional requirements. Subsequently, the target program code syntax rules are determined from the full set of program code syntax rules, narrowing the range of program code syntax rules used by the generative model, and using the BNF format to describe the target program code syntax rules, further improving the syntax accuracy of the target program code.

[0161] Thereafter, to improve economic efficiency and reduce economic costs, the computer device performs format conversion on the capability information of the target capabilities and the target program code syntax rules, thereby reducing the number of tokens consumed by the generative model. Finally, to ensure the correctness of the target program code, the computer device further performs code checking and adjusts the target program code with errors, so as to subsequently generate a target program using the target program code. While ensuring that the target program can meet the functional requirements, the threshold of program development is reduced and the efficiency of program development is improved.

[0162] See Figure 9 , which shows an implementation schematic diagram of the program generation process provided by an exemplary embodiment of the present application. Among them, after the user inputs demand information 901, the computer device performs a capability search on the candidate capabilities in the capability list 902 to obtain the target capability 903, and performs an example search on the candidate code example segments in the example list 904 to obtain the target code example segment 905, where the search methods include content recall and vector recall.

[0163] Then, the computer device adds the demand information 901, the target capability 903, the target code example segment 905, and the target program code syntax rule 906 to the prompt text 907, and inputs the prompt text 907 into the generative model 908 to obtain the target program code 909, and finally performs code checking on the target program code 909.

[0164] In the case where the target program code 909 has a syntax error or fictional content, the target program code 909 fails the check. The computer device generates an error message 910 based on the target program code 909, adds the target program code 909 and the error message 910 to the prompt text 907, and then inputs the prompt text 907 into the generative model 908 to obtain the adjusted target program code 909; in the case where the target program code 909 passes the check, the target program 911 is generated based on the target program code 909.

[0165] The generation of program code requires strong logic to ensure that the subsequent generated target program is executable. Then, although the solution provided in the above embodiment improves the syntax correctness and capability integrity in the generated target program code, it cannot guarantee the logical smoothness and reasonableness of the target program code before and after.

[0166] The embodiment of the present application improves the understanding ability of the generative model for the target code example segment by adding a logical chain to the prompt text, thereby improving the logic of the target program code. That is, the embodiment of the present application divides step 507 in the above embodiment, constructing the prompt text of the generative model based on the demand information, the target capability, the target code example segment, and the target program code syntax rule, into the following sub-steps.

[0167] Sub-step 1, obtain the target logical chain corresponding to the target code example segment, and the target logical chain is used to describe the task execution logic of the task completed by the target code example segment.

[0168] Among them, the logical chain is a Chain of Thought (CoT), which is used to describe the intermediate reasoning steps of the candidate code example segment. The logical chain can be described in a syntax form.

[0169] In a possible implementation, the computer device adds the logical chain to the example list, and then, when the computer device determines the target code example snippet through example retrieval, obtains the target logical chain corresponding to the target code example snippet from the example list.

[0170] Sub-step 2: Construct the prompt text of the generative model based on the requirement information, target capabilities, target code example snippet, target logical chain, and target program code syntax rules.

[0171] In a possible implementation, the computer device constructs the prompt text by using role setting, problem description, requirement information, target capabilities, target code example snippet, target logical chain, and target program code syntax rules.

[0172] Exemplarily, the prompt text is as follows:

[0173] You are a program generation expert. Please generate a DSL text according to my requirements.

[0174] My requirements:

[0175] [I want to turn on the massage function]

[0176] The program code syntax rules are as follows:

[0177] [DSL syntax]

[0178] The callable capabilities are as follows:

[0179] [List of target capabilities]

[0180] The code example snippets are as follows:

[0181] [Target code example snippet]

[0182] The step-by-step reasoning process of the code example snippet is as follows:

[0183] [Target logical chain corresponding to the target code example snippet].

[0184] In some possible application scenarios, there may be multiple rounds of interaction between the computer device and the user to refine the functional requirements. To enable the generative model to integrate the user's functional requirements during different rounds of interaction, the computer device inputs the context requirement information and the generated historical program code as part of the prompt text into the generative model.

[0185] In some embodiments, when there is historical requirement information associated with the requirement information, the computer device adds the context requirement information and the historical program code to the prompt text.

[0186] In summary, the embodiments of the present application can also divide step 507 in the above embodiments into the following sub-steps.

[0187] Sub-step 1: Obtain historical program code, which is generated based on the above-mentioned requirement information of the requirement information.

[0188] Sub-step 2: Based on the requirement information, target capabilities, target code example snippets, target logic chains, target program code syntax rules, and historical program code, construct the prompt text of the generative model.

[0189] In an illustrative example, the prompt engineering text after adding the historical functional requirement text and historical text is as follows:

[0190] You are a program generation expert. Please generate a DSL text according to my requirements.

[0191] The DSL syntax is as follows:

[0192] [DSL syntax]

[0193] The callable capabilities are limited to the following list:

[0194] [Capability list]

[0195] My historical requirements:

[0196] [Historical requirement text]

[0197] Historical DSL:

[0198] [Historical DSL]

[0199] My current requirement:

[0200] [I want to take a break in the car for a while].

[0201] It should be noted that the context requirement information, historical program code, target program code example snippets, and target logic chains can be added to the prompt text at the same time, or the historical program code can be added to the prompt text as the target program code example snippets. This embodiment will not elaborate here.

[0202] In the embodiments of the present application, the computer device adds the context requirement information and historical program code to the prompt text as part of the prompt text, enabling the generative model to generate the target program code according to the user's segmented requirements. Correspondingly, the user can express the functional requirements in segments, which helps to improve the user experience.

[0203] Please refer to Figure 10 , which shows the structural block diagram of a program generation device provided by an exemplary embodiment of the present application. The device includes:

[0204] An acquisition module 1001, configured to acquire requirement information, where the requirement information is used to describe the functional requirements to be satisfied.

[0205] A retrieval module 1002, configured to perform an ability retrieval and an example retrieval based on the requirement information, so as to obtain a target ability and a target code example snippet, where the target ability is the ability called to satisfy the functional requirements, and the target code example snippet is a program code example snippet related to the functional requirements.

[0206] A construction module 1003, configured to construct a prompt text of a generative model based on the requirement information, the target ability, the target code example snippet, and a target program code syntax rule.

[0207] A generation module 1004, configured to generate a target program code through the generative model based on the prompt text, where the program corresponding to the target program code is used to satisfy the functional requirements.

[0208] Optionally, the retrieval module 1002 is further configured to:

[0209] Perform an ability retrieval in an ability list based on the requirement information to obtain the target ability.

[0210] Perform an example retrieval in an example list based on the requirement information to obtain the target code example snippet.

[0211] Optionally, the retrieval module 1002 is further configured to:

[0212] Perform content recall based on the requirement information and the ability description information of candidate abilities in the ability list to obtain the target ability.

[0213] Perform vector recall based on the requirement representation vector corresponding to the requirement information and the ability representation vector corresponding to the candidate abilities in the ability list to obtain the target ability, where the ability representation vector is obtained by vectorizing the ability description information of the candidate ability.

[0214] The retrieval module 1002 is further configured to:

[0215] Perform content recall based on the requirement information and the task description information of candidate code example snippets in the example list to obtain the target code example snippet.

[0216] Perform vector recall based on the requirement representation vector corresponding to the requirement information and the task representation vector corresponding to the candidate code example snippets in the example list to obtain the target code example snippet, where the task representation vector is obtained by vectorizing the task description information of the candidate code example snippet.

[0217] Optionally, the retrieval module 1002 is further configured to:

[0218] Input the requirement information and the ability description information into a first semantic matching model to obtain a first semantic matching result output by the first semantic matching model. The first semantic matching model is trained based on a first sample downstream task dataset, and the first sample downstream task dataset includes sample downstream requirement information, the ability description information, and a first semantic matching label, where the first semantic matching label is used to characterize whether the sample downstream requirement information and the ability description information are semantically matched;

[0219] In the case where the first semantic matching result indicates semantic matching, determine the candidate ability corresponding to the ability description information as the target ability;

[0220] The retrieval module 1002 is further configured to:

[0221] Input the requirement information and the task description information into a second semantic matching model to obtain a second semantic matching result output by the second semantic matching model. The second semantic matching model is trained based on a second sample downstream task dataset, and the second sample downstream task dataset includes sample downstream requirement information, the task description information, and a second semantic matching label, where the second semantic matching label is used to characterize whether the sample downstream requirement information and the task description information are semantically matched;

[0222] In the case where the second semantic matching result indicates semantic matching, determine the candidate code example segment corresponding to the task description information as the target code example segment.

[0223] Optionally, the retrieval module 1002 is further configured to:

[0224] Supplement the target ability retrieved by the ability based on the ability called in the target code example segment.

[0225] Optionally, the apparatus further includes a logic chain acquisition module, configured to:

[0226] Obtain a target logic chain corresponding to the target code example segment, where the target logic chain is used to describe the task execution logic of the task completed by the target code example segment;

[0227] The construction module 1003 is further configured to:

[0228] Construct the prompt text of the generative model based on the requirement information, the target ability, the target code example segment, the target logic chain, and the target program code syntax rules.

[0229] Optionally, the device further includes a history acquisition module, configured to:

[0230] Acquire historical program code, where the historical program code is generated based on the above-mentioned requirement information of the requirement information;

[0231] The construction module 1003 is further configured to:

[0232] Construct the prompt text of the generative model based on the requirement information, the target capability, the target code example snippet, the target logic chain, the target program code syntax rules, and the historical program code.

[0233] Optionally, the device further includes a determination module, configured to:

[0234] Determine the target program code syntax rules from the full set of program code syntax rules based on the target capability and the target code example snippet, where the target program code syntax rules include the syntax rules for invoking the target capability and the syntax rules included in the target code example snippet.

[0235] Optionally, the full set of program code syntax rules uses BNF syntax, and the generative model is trained using the corpus of BNF syntax.

[0236] Optionally, the device further includes a conversion module, configured to:

[0237] Perform format conversion on the capability information of the target capability and the target program code syntax rules, where the format conversion is used to reduce the number of tokens of the capability information of the target capability and the target program code syntax rules.

[0238] Optionally, the device further includes an inspection module, configured to:

[0239] Perform code inspection on the target program code using the capability information of the target capability and the target program code syntax rules, where the code inspection includes fictional content inspection and syntax inspection, and the fictional content inspection is used to check whether the target program code contains fictional capabilities or fictional capability parameters;

[0240] In the case where the target program code fails the code inspection, input the target program code and the error information obtained from the code inspection into the generative model to obtain an adjusted target program code.

[0241] Optionally, the generation module 1004 is further configured to:

[0242] Generate the target program code through the generative model based on the prompt text and the code length control parameter, where the target program code is cyclically generated by the generative model based on the code length control parameter, and the program code generated each time is used as the input for the next cycle generation when it passes the code check.

[0243] In summary, in the embodiments of the present application, since the generative model has powerful requirement understanding and content generation capabilities, the computer device uses the generative model to generate the target program code. To help the generative model understand the requirement information and improve the integrity and accuracy of the generated target program code, the computer device screens the capabilities and code example segments according to the requirement information to obtain the target capabilities and target code example segments, and then constructs the prompt text of the generative model using the target capabilities, target code example segments, requirement information, and the syntax rules of the target program code. Therefore, the user only needs to input the requirement information to generate the target program code through the generative model, eliminating the process of requirement analysis and program code writing, reducing the threshold of program development, and improving the efficiency of program development.

[0244] It should be noted that: for the device provided in the above embodiment, only the above division of each functional module is used for illustration. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device provided in the above embodiment and the method embodiment belong to the same concept, and the specific implementation process can be found in the method embodiment, which will not be elaborated here.

[0245] Please refer to Figure 11 , which shows the structural block diagram of a computer device provided by an exemplary embodiment of the present application. The computer device includes a processor and a memory. The computer device may include one or more of the following components: a processor 1101 and a memory 1102.

[0246] Optionally, the processor 1101 is connected to various parts within the entire electronic device through various interfaces and circuits. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 1102, and by invoking data stored in the memory 1102, it performs various functions of the electronic device and processes data. Optionally, the processor 1101 may be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), or programmable logic array (PLA). The processor 1101 may integrate one or a combination of several of a central processing unit (CPU), a graphics processing unit (GPU), a neural-network processing unit (NPU), and a baseband chip, etc. Among them, the CPU mainly processes the operating system, user interface, application programs, etc.; the GPU is responsible for rendering and drawing the content to be displayed on the touch display screen; the NPU is used to implement artificial intelligence (AI) functions; the baseband chip is used to process wireless communication. It can be understood that the above baseband chip may not be integrated into the processor 1101 and may be implemented separately by a single chip.

[0247] Optionally, the processor 1101 is connected to various parts within the entire electronic device through various interfaces and circuits. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 1102, and by calling data stored in the memory 1102, it performs various functions of the electronic device and processes data. Optionally, the processor 1101 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), or programmable logic array (PLA). The processor 1101 can integrate one or a combination of several of a central processing unit (CPU), a graphics processing unit (GPU), a neural-network processing unit (NPU), and a baseband chip, etc. Among them, the CPU mainly processes the operating system, user interface, application programs, etc.; the GPU is responsible for rendering and drawing the content to be displayed on the touch display screen; the NPU is used to implement artificial intelligence (AI) functions; the baseband chip is used to process wireless communication. It can be understood that the above baseband chip may not be integrated into the processor 1101 and can be implemented separately by a single chip.

[0248] The memory 1102 can include random access memory (RAM) and can also include read-only memory (ROM). Optionally, the memory 1102 includes a non-transitory computer-readable storage medium. The memory 1102 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 1102 can include a program storage area and a data storage area. Among them, the program storage area can store instructions for implementing the operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the following various method embodiments, etc.; the data storage area can store data created according to the use of the electronic device (such as audio data, phone book, etc.).

[0249] In addition, those skilled in the art can understand that the structure of the computer device shown in the above drawings does not constitute a limitation on the computer device. The computer device can include more or fewer components than shown in the drawings, or combine certain components, or have different component arrangements.

[0250] An embodiment of the present application further provides a computer-readable storage medium, in which at least one instruction is stored, and the at least one instruction is loaded and executed by a processor to implement the program generation method provided in the above embodiment.

[0251] Optionally, the computer-readable storage medium may include: ROM, RAM, solid state drive (SSD), optical disc, etc. Among them, RAM may include resistive random access memory (ReRAM) and dynamic random access memory (DRAM).

[0252] An embodiment of the present application provides a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the program generation method described in the above embodiment.

[0253] Those of ordinary skill in the art can understand that all or part of the steps for implementing the above embodiments can be completed by hardware, or can be completed by a program instructing related hardware. The program can be stored in a computer-readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk, an optical disc, etc.

[0254] The above are only optional embodiments of the present application, and are not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.< / trigger> < / app>

Claims

1. A program generation method, characterized in that, The method includes: Obtaining requirement information, which is used to describe the functional requirements to be met; Performing an ability retrieval and an example retrieval based on the requirement information to obtain a target ability and a target code example snippet. The target ability is the ability called to meet the functional requirements, and the target code example snippet is a program code example snippet related to the functional requirements; Constructing a prompt text for the generative model based on the requirement information, the target ability, the target code example snippet, and the target program code syntax rules; Generating target program code through the generative model based on the prompt text, and the program corresponding to the target program code is used to meet the functional requirements.

2. The method according to claim 1, wherein The performing an ability retrieval and an example retrieval based on the requirement information to obtain a target ability and a target code example snippet includes: Performing an ability retrieval in an ability list based on the requirement information to obtain the target ability; Performing an example retrieval in an example list based on the requirement information to obtain the target code example snippet.

3. The method according to claim 2, wherein The performing an ability retrieval in an ability list based on the requirement information to obtain the target ability includes: Performing content recall based on the requirement information and the ability description information of the candidate abilities in the ability list to obtain the target ability; Performing vector recall based on the requirement representation vector corresponding to the requirement information and the ability representation vector corresponding to the candidate abilities in the ability list to obtain the target ability. The ability representation vector is obtained by vectorizing the ability description information of the candidate ability; The performing an example retrieval in an example list based on the requirement information to obtain the target code example snippet includes: Performing content recall based on the requirement information and the task description information of the candidate code example snippets in the example list to obtain the target code example snippet; Performing vector recall based on the requirement representation vector corresponding to the requirement information and the task representation vector corresponding to the candidate code example snippets in the example list to obtain the target code example snippet. The task representation vector is obtained by vectorizing the task description information of the candidate code example snippet.

4. The method according to claim 3, characterized in that, The performing an ability retrieval in an ability list based on the requirement information to obtain the target ability further includes: Inputting the requirement information and the ability description information into a first semantic matching model to obtain a first semantic matching result output by the first semantic matching model. The first semantic matching model is trained based on a first sample downstream task dataset, and the first sample downstream task dataset includes sample downstream requirement information, the ability description information, and a first semantic matching label, and the first semantic matching label is used to characterize whether the sample downstream requirement information and the ability description information are semantically matched; When the first semantic matching result indicates semantic matching, determining the candidate ability corresponding to the ability description information as the target ability; The performing an example retrieval in an example list based on the requirement information to obtain the target code example snippet further includes: Input the demand information and the task description information into a second semantic matching model to obtain a second semantic matching result output by the second semantic matching model. The second semantic matching model is trained based on a second sample downstream task dataset, and the second sample downstream task dataset includes sample downstream demand information, the task description information, and a second semantic matching label, where the second semantic matching label is used to characterize whether the sample downstream demand information and the task description information are semantically matched; In the case where the second semantic matching result indicates semantic matching, determine the candidate code example segment corresponding to the task description information as the target code example segment.

5. The method according to claim 2, characterized in that After retrieving the example in the example list based on the demand information to obtain the target code example segment, it further includes: Based on the capabilities called in the target code example segment, supplement the target capabilities retrieved by the capabilities.

6. The method according to claim 1, wherein The method further includes: Obtain a target logic chain corresponding to the target code example segment, where the target logic chain is used to describe the task execution logic of the task completed by the target code example segment; Constructing the prompt text of the generative model based on the demand information, the target capabilities, the target code example segment, and the target program code syntax rules includes: Construct the prompt text of the generative model based on the demand information, the target capabilities, the target code example segment, the target logic chain, and the target program code syntax rules.

7. The method according to claim 1, characterized in that, The method further includes: Obtain historical program code, where the historical program code is generated based on the previous demand information of the demand information; Constructing the prompt text of the generative model based on the demand information, the target capabilities, the target code example segment, and the target program code syntax rules includes: Construct the prompt text of the generative model based on the demand information, the target capabilities, the target code example segment, the target logic chain, the target program code syntax rules, and the historical program code.

8. The method according to claim 1, characterized in that Before constructing the prompt text of the generative model based on the demand information, the target capabilities, the target code example segment, and the target program code syntax rules, the method further includes: Based on the target capabilities and the target code example segment, determine the target program code syntax rules from the full set of program code syntax rules. The target program code syntax rules include the syntax rules for calling the target capabilities and the syntax rules included in the target code example segment.

9. The method according to claim 8, wherein The full set of program code syntax rules uses BNF syntax, and the generative model is trained using the corpus of BNF syntax.

10. The method according to claim 1, characterized in that, Before constructing the prompt text of the generative model based on the demand information, the target capabilities, the target code example segment, and the target program code syntax rules, the method further includes: Perform format conversion on the ability information of the target ability and the syntax rules of the target program code, where the format conversion is used to reduce the number of tokens of the ability information of the target ability and the syntax rules of the target program code.

11. The method according to claim 1, wherein After generating the target program code through the generative model based on the prompt text, the method further includes: Perform code checking on the target program code by using the ability information of the target ability and the syntax rules of the target program code. The code checking includes fictional content checking and syntax checking. The fictional content checking is used to check whether the target program code contains fictional abilities or fictional ability parameters. In the case where the target program code fails the code checking, input the target program code and the error information obtained from the code checking into the generative model to obtain an adjusted target program code.

12. The method according to claim 1, wherein Generating the target program code through the generative model based on the prompt text includes: Generate the target program code through the generative model based on the prompt text and the code length control parameter, where the target program code is cyclically generated by the generative model based on the code length control parameter, and the program code generated in each cycle is used as the input for the next cycle generation in the case of passing the code checking.

13. A program generation device, characterized in that, The device includes: An acquisition module for acquiring requirement information, where the requirement information is used to describe the functional requirements to be satisfied. A retrieval module for performing ability retrieval and example retrieval based on the requirement information to obtain a target ability and a target code example segment. The target ability is the ability called to satisfy the functional requirements, and the target code example segment is a program code example segment related to the functional requirements. A construction module for constructing a prompt text for the generative model based on the requirement information, the target ability, the target code example segment, and the syntax rules of the target program code. A generation module for generating a target program code through the generative model based on the prompt text, where the program corresponding to the target program code is used to satisfy the functional requirements.

14. A computer device, characterized in that, The computer device includes a processor and a memory; the memory stores at least one computer instruction, and the at least one computer instruction is used to be executed by the processor to implement the program generation method according to any one of claims 1 to 12.

15. A computer-readable storage medium, characterized in that, The storage medium stores at least one computer instruction, and the at least one computer instruction is used to be executed by a processor to implement the program generation method according to any one of claims 1 to 12.

16. A computer program product, characterized in that, The computer program product includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device implements the program generation method according to any one of claims 1 to 12.