Code generation method based on large language model and electronic equipment

By combining a programming intelligence agent and a UCB optimization module, the template weights are dynamically adjusted and the Top-K templates are selected, which solves the problem of low code generation success rate and efficiency in existing technologies and improves the efficiency and accuracy of code generation.

CN121092153AActive Publication Date: 2025-12-09BEIJING FEISHU TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202511639571.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-10
Publication Date
2025-12-09
Estimated Expiration
2045-11-10

AI Technical Summary

Technical Problem

Existing code generation methods lack dynamic feedback and optimization of template usage effects, making it difficult to improve code generation success rate and efficiency. Furthermore, existing RAG solutions fail to effectively balance the relationship between high-success-rate templates and potentially high-quality templates.

Method used

By dynamically updating template information through a programming intelligence agent, adjusting template weights based on user feedback, selecting Top-K templates using the UCB optimization module, and coordinating with a large language model to generate code, dynamic iterative optimization of template performance is achieved.

Benefits of technology

It improved the success rate and accuracy of code generation for online users, dynamically adjusted template usage strategies, and enhanced the efficiency and accuracy of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121092153A_ABST
    Figure CN121092153A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a code generation method based on a large language model and electronic equipment. The code generation method based on the large language model comprises the following steps: receiving a user query, wherein the user query comprises user demand description; based on template information of a plurality of candidate templates in a template library, at least one candidate template corresponding to the user query is selected from the template library, and the plurality of candidate templates and the template weight of each template in the plurality of candidate templates are stored in the template library; wherein the template weight is associated with the use frequency of the corresponding template and the result condition of generating the code by using the corresponding template; and inputting the user query and the at least one candidate template into the large language model to generate a code response corresponding to the user query. In this way, the success rate and accuracy of online user code generation are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates generally to the field of computers, and more particularly to a method for code generation based on large language models and an electronic device. BACKGROUND

[0002] With the increasing demand for software development, online users have a surge in demand for code generation based on specific technology stacks (such as platform application programming interfaces (APIs), front-end templates, domain-specific languages (DSLs)). Traditional code generation schemes rely on fixed template matching or single large language model (LLM) generation, lack dynamic feedback and optimization of template usage effectiveness, and cannot iteratively improve code generation success rate. Some high-potential but low-usage templates are long ignored (insufficient exploration), while some low-success-rate templates are repeatedly used (over-exploitation).

[0003] Retrieval-augmented generation (RAG) technology can improve relevance, but existing RAG schemes are mostly based on static similarity sorting and do not combine historical performance and exploration needs of templates, making it difficult to balance the relationship between “exploiting high-success-rate templates” and “exploring potential high-quality templates”, resulting in difficulty in further improving code generation success rate and efficiency. SUMMARY

[0004] According to an example embodiment of the present disclosure, a method, apparatus, electronic device, computer-readable storage medium, and computer program product for code generation based on a large language model are provided. The usage effectiveness of the template can be dynamically fed back and optimized, thereby improving the success rate and accuracy of online user code generation.

[0005] In a first aspect of the present disclosure, a method for code generation based on a large language model is provided, comprising: receiving a user query, the user query including a user demand description; selecting at least one candidate template corresponding to the user query from a template library based on template weights of a plurality of candidate templates in the template library, wherein the template library stores a plurality of candidate templates and a template weight of each template in the plurality of candidate templates, and wherein the template weight is associated with a usage frequency of the corresponding template and a result of generating code using the corresponding template; and inputting the user query and the at least one candidate template into a large language model to generate a code response corresponding to the user query.

[0006] In a second aspect of the present disclosure, an electronic device is provided, comprising: at least one processing unit; at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions, when executed by the at least one processing unit, causing the electronic device to perform the method described according to the first aspect of the present disclosure.

[0007] In a third aspect of the present disclosure, an apparatus for code generation based on large language model is provided, comprising: a receiving unit configured to receive a user query, the user query comprising a user requirement description; a selecting unit configured to select at least one candidate template corresponding to the user query from a template library based on template weights of a plurality of candidate templates in the template library, wherein the template library stores the plurality of candidate templates and the template weight of each template in the plurality of candidate templates, and the template weight is associated with the number of times of using the corresponding template and the result condition of generating code using the corresponding template; and a generating unit configured to input the user query and the at least one candidate template into the large language model to generate a code response corresponding to the user query.

[0008] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, the computer-readable storage medium having stored thereon machine executable instructions which, when executed by a device, cause the device to perform the method described according to the first aspect of the present disclosure.

[0009] In a fifth aspect of the present disclosure, a computer program product is provided, comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method described according to the first aspect of the present disclosure.

[0010] In a sixth aspect of the present disclosure, an electronic device is provided, comprising: processing circuitry configured to perform the method described according to the first aspect of the present disclosure.

[0011] The summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. The summary is not intended to identify key features or essential features of the disclosure, nor is it intended to limit the scope of the disclosure. Other features of the present disclosure will be apparent from the detailed description below. BRIEF DESCRIPTION OF DRAWINGS

[0012] The above and other features, aspects, and advantages of various embodiments of the present disclosure will become more apparent from the following detailed description in conjunction with the accompanying drawings, in which like reference numerals denote like elements. In the drawings:

[0013] Figure 1 A schematic diagram of a system according to some embodiments of the present disclosure is shown;

[0014] Figure 2 A schematic flowchart of a method of large language model based code generation is shown in accordance with some embodiments of the present disclosure;

[0015] Figure 3 A schematic diagram of a process of large language model based code generation is shown in accordance with some embodiments of the present disclosure;

[0016] Figure 4 A block diagram of an example apparatus in accordance with some embodiments of the present disclosure is shown; and

[0017] Figure 5 A block diagram of an example apparatus that can be used to implement embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0018] Embodiments of the present disclosure will be described in more detail with reference to the drawings. While certain embodiments of the present disclosure are shown in the drawings, it is understood that the present disclosure can be embodied in various forms and should not be interpreted as being limited to the embodiments set forth herein, but rather, these embodiments are provided for more complete and thorough understanding of the present disclosure. It is understood that the drawings and embodiments of the present disclosure are for exemplary purposes only and are not intended to limit the scope of protection of the present disclosure.

[0019] The large language model in embodiments of the present disclosure can be applied to a variety of application scenarios, such as writing articles, generating dialogues, creating poems, generating content for social media / news, generating code / comments / documents, generating teaching materials, assisting language learning, etc.

[0020] In actual applications, a single monolingual model or a fixed template matching can be used to generate code. However, the traditional code generation method lacks dynamic feedback and optimization of template usage effect, and cannot iteratively improve the success rate of code generation. The existing RAG scheme also does not combine the historical performance of the template with the exploration demand, making it difficult to further improve the success rate and efficiency of code generation.

[0021] To solve the above problems and potential other problems, embodiments of the present disclosure provide a method of large language model based code generation. In embodiments of the present disclosure, a programming agent can dynamically update template information, such as the number of times a template is used and the template weight, based on user feedback information on the functional performance of the generated code. In addition, the programming agent of the present disclosure also explores templates with high potential but few uses. In this way, the success rate and accuracy of online user code generation are further improved.

[0022] Figure 1A schematic diagram of a system 100 according to some embodiments of the present disclosure is shown. The system 100 includes a large language model (LLM) 101 and a programming agent 102, wherein the programming agent 102 includes a template library module 103, an embedding generation module 104, a similarity calculation module 105, an upper confidence bound (UCB) selection module 106, a RAG generation module 107, and a feedback update module 108.

[0023] like Figure 1 As shown, LLM 101 and the programming agent 102 can receive and transmit information to each other and collaborate to complete related tasks. LLM 101 is capable of deep understanding and processing of natural language, and can perform various complex tasks such as code generation and knowledge question answering based on neural networks. After receiving prompts, LLM 101 can process the prompts and convert them into vector representations.

[0024] It's understandable that user input prompts are mostly presented in natural language. The prompts input into the LLM 101 large language model can be a piece of text used to guide the model in generating specific outputs. For example, the prompt can be a question, a sentence fragment, an instruction, or any other form of text. LLM 101 can predict the next content based on the prompt. For instance, in a code generation task, if the prompt is "You are a professional code generation assistant, and you need to generate directly executable code based on user needs and provided reference templates…", LLM 101 will output code that meets the user's needs based on the input prompt.

[0025] For example, the template library module 103 can store template information for multiple candidate templates. Taking template X (the first template) as an example, the template information of template X can include: the identification information of template X, the number of times template X has been used, and the template weight of template X. The template weight of template X is related to: the number of times template X has been used within a preset historical time period and the result of generating code using template X. For example, the number of times template X has been used can be a positive integer (the number of times it has been called) or 0 (it has not been called). For example, the result of generating code using template X can include the result of generating code each time X is used. The result of a particular instance can be any of the following: the code generated based on template X is adopted directly without modification; the code generated based on template X is adopted after one or more modifications; or the code generated based on template X is not adopted.

[0026] Optionally, for a template X, a template weight of the template X can be determined based on historical results of using the template X to generate code. Optionally, for a template X, a number of times (e.g., n) of using the template X in a preset historical time period and a template weight (e.g., s) of the template X can be stored.

[0027] In embodiments of the present disclosure, the template weight can also be referred to as a template score, a score, etc., for representing a success rate of the code corresponding to the template being adopted. Exemplarily, the "score" mentioned below can be replaced by the template weight.

[0028] In embodiments of the present disclosure, the template library module 103 stores a plurality of verified templates T, and associates a historical buffer of each template , and is a number of times of using the template in a preset historical time period, and the score of the template. Exemplarily, the score of the stored template is related to historical usage of the corresponding template, for example, the corresponding template is historically used and the generated code is successfully accepted (or is accepted after being modified, or is not accepted even after being modified). It is assumed that there are m (m is an integer greater than or equal to 1) templates in the template library module 103, where the template refers to a verified test example set containing a "user query-code" pair, and the set formed by all templates is denoted as , each template is composed of a query (user demand description) and a code (corresponding correct code), and both are functionally verified, where i is an integer greater than or equal to 1 and less than or equal to m.

[0029] Exemplarily, 10,000 groups of "query-code" pairs based on code templates are collected, stored in Redis after being verified by humans, and is initialized.

[0030] In embodiments of the present disclosure, the embedding generation module 104 converts the user query Q and the template into embedding vectors (embedding vectors) based on an embedding language model, for capturing text semantic information. The term "embedding vector" is also referred to as a low-dimensional dense vector, a feature vector, etc.

[0031] Exemplarily, the dimension of the embedding vector is denoted as d, the embedding vector of the template is denoted as ( is a real set, and d is the dimension of the vector), and the embedding vector corresponding to the user query is denoted as .

[0032] Optionally, the embedding language model adopts a model structure MM to convert a string into a 768-dimensional embedding vector. It should be understood that the embedding language model can also adopt other embedding language models such as Gemini Embeddings, and the vector dimension can also adopt other dimensions, which are not limited by the present disclosure.

[0033] For example, a user inputs a query such as "React-based login page code (using XY components)", and the model structure MM generates an embedding vector of the user query.

[0034] In an embodiment of the present disclosure, the similarity calculation module 105 calculates the cosine similarity between the embedding vector of the user query and the embedding vector of each template, which can represent the semantic relevance between the user query and each template. For example, the embedding vector of the aforementioned user query is calculated with the cosine similarity of 10,000 templates.

[0035] In an embodiment of the present disclosure, the UCB optimization module 106 calculates the UCB score of each template based on the similarity, the historical performance of the template, and the exploration factor, and selects the Top-K template. The historical performance of the template includes the number of times the template is used in a preset historical time period , and the score of the template . For example, the historical buffer can record the array of the use of each template , including the number of times and the cumulative performance score . The UCB optimization module 106 selects the K templates with the highest scores from the candidate templates based on the UCB score, i.e., the Top-K template.

[0036] The introduction of the exploration factor in the algorithm for calculating the UCB score can excavate some high-potential but less-used templates, while taking into account the score and the exploration factor of the template to balance the exploration and utilization of the template, thereby improving the accuracy and efficiency of code generation. The term "exploration factor" can also be referred to as a balance factor, an exploration-exploitation balance factor, an exploration coefficient, an exploration parameter, an exploration-exploitation parameter, an exploration strength, or other; which are not limited by the present disclosure.

[0037] For example, the UCB selection module 106 calculates the UCB scores of each template (e.g., the aforementioned 10,000 templates), and selects the top-5 templates with the highest scores. For example, the similarity of the 5 selected templates to the user query is greater than or equal to 0.75, and the usage frequency of 2 of the 5 templates is less than or equal to 3. It can be understood that, among the total of 10,000 templates, although the usage frequency of the aforementioned 2 templates is low, the top-5 templates are selected by the UCB scores, which can explore templates with low usage frequency but high potential, and improve the usage rate of high-potential templates.

[0038] In an embodiment of the present disclosure, the RAG generation module 107 inputs the top-K templates as retrieval results into the LLM 101, and the two work together to generate target code. For example, the aforementioned top-5 templates are input into the LLM 101 to generate a React login page code containing an XY component.

[0039] In an embodiment of the present disclosure, the feedback update module 108 updates the historical buffer of the corresponding template according to the feedback information of the user on the generated code . For example, the user feedbacks that the code needs to be modified in the button style and then runs successfully (modification frequency t = 1), and the usage frequency of the top-5 templates (each is increased by 1) and the scores of the templates (e.g., each is increased by 1.2) are updated. For example, the user feedbacks that the code has been modified 10 times in the button style but still fails (modification frequency t = 10), and the usage frequency of the top-5 templates (each is increased by 1) and the scores of the templates (e.g., each is decreased by 1) are updated. It should be understood that the above addition and subtraction scores of the template scores are only exemplary, and the present disclosure is not limited thereto, for example, the addition and subtraction scores can be a function related to the number of times the code is modified.

[0040] Figure 2 A schematic flowchart of a method 200 of large language model-based code generation according to some embodiments of the present disclosure is shown. In block 202, a user query is received, and the user query includes a user requirement description. In block 204, at least one candidate template corresponding to the user query is selected from a template library based on template weights of a plurality of candidate templates in the template library, wherein the template library stores the plurality of candidate templates and the template weight of each template in the plurality of candidate templates, and the template weight is associated with the usage frequency of the corresponding template and the result of generating code using the corresponding template. In block 206, the user query and the at least one candidate template are input into a large language model to generate a code response corresponding to the user query.

[0041] In some embodiments of the present disclosure, a mode of the programmed intelligent agent 102 working with the LLM 101 is adopted to process prompt information more efficiently. The programmed intelligent agent 102 can filter out both the Top-K templates meeting the requirements and the templates with few uses but high potential, and perform the same process for all subsequent online user queries, further realizing dynamic iterative optimization of template performance and a self-learning closed loop of the model.

[0042] Exemplarily, the user demand description can be text, voice, etc. Exemplarily, the code demand description can be input through a human-computer interaction interface.

[0043] In some embodiments of the present disclosure, feedback information of a user on the code response is received; and based on the feedback information, the use frequency and the template weight of at least one candidate template in the template library are updated. Taking a first template in the plurality of candidate templates as an example, the template weight of the first template is associated with: the use frequency of the first template in a preset historical time period , and a result condition of generating the code using the first template.

[0044] Exemplarily, the result condition of generating the code using the first template includes any of the following: the code generated based on the first template is directly adopted without modification, the code generated based on the first template is adopted after one or more modifications, or the code generated based on the first template is not adopted.

[0045] Optionally, the score of the first template can also be calculated / updated according to the result condition of generating the code using the first template . It should be understood that when the template is first stored in the historical buffer, the use frequency and the score can be initialized, for example , so as to ensure the correctness of the template information after the template is used multiple times.

[0046] Exemplarily, after the user uses the generated code, the user feeds back the functional performance through the feedback information, and the feedback updating module 108 updates the use frequency and the score of the template recorded in the historical buffer of each template in the Top-K according to the feedback information.

[0047] Exemplarily, the feedback information includes one or more types. For example, if the feedback information indicates that the user does not modify the code response (i.e., the code generated based on the at least one candidate template is directly adopted without modification), the feedback updating module 108 adds 1 to the use frequency and a first preset value to the score of each candidate template in the K templates. For example, assuming that the first preset value is 1, then (1)

[0048] In formula (1), the represents assignment update, i.e., the left parameter is updated to the calculation result on the right.

[0049] Exemplarily, the feedback information indicates that the code response is normally run after being modified by the user (i.e., the code generated based on the at least one candidate template is adopted after being modified one or more times), and wherein updating the template information comprises: adding 1 to the usage times of each of the at least one candidate template, and adding a second preset value to the score. For example, assuming that the second preset value is 1.2, then (2)

[0050] Optionally, the second preset value is greater than the first preset value, so as to improve the usage rate of the template corresponding to the code that is normally run after being modified in the subsequent user query process.

[0051] In some embodiments of the present disclosure, the feedback information indicates that the code response is still unable to be normally run after being modified by the user (i.e., the code generated based on the at least one candidate template is not adopted), and wherein updating the template information comprises: adding 1 to the usage times of each of the at least one candidate template, and subtracting a specific value from the score, the specific value being associated with the number of times of modification of the code response and a third preset value. For example, assuming that the third preset value is 1, then (3)

[0052] In formula (3), the number of times of modification of the code response is , the integer greater than 1 is , the smaller value between 1 and represents taking , and the constant can be flexibly configured according to specific circumstances (e.g., computing resources, response speed, etc.), for example, a is taken as 10, so as to avoid that the failure of too few times of modification excessively affects the performance evaluation of the template, for example, the corresponding template is not considered to have exploration value because of a single modification failure.

[0053] As discussed above, the first preset value, the second preset value, and the third preset value can be involved in updating the template information, and it should be understood that embodiments of the present disclosure do not limit the size of the first / second / third preset value, for example, the three values can be mutually different, or two of the three values are equal, etc. For example, the size of the value can be set based on an application strategy, wherein the application strategy can be a plurality of candidate templates recommended to be used by the application, or a template that is not used by the application is suggested, etc.

[0054] In some embodiments of the present disclosure, the UCB preference module 106 selecting the at least one candidate template comprises: determining a similarity between the user query and each template in the plurality of candidate templates; determining a confidence upper bound (UCB) score between the user query and each template based on the plurality of similarities between the user query and the plurality of candidate templates and template information of the plurality of candidate templates; and selecting the at least one candidate template based on the plurality of UCB scores between the user query and the plurality of candidate templates.

[0055] For example, for each template , a semantic similarity with the user query Q is computed, for example, denoted as: (4)

[0056] where the function , is the dot product of the vectors and , the function is the length of the vector , and the function is the length of the vector . In equation (4), corresponds to in the function , and corresponds to in the function

[0057] . (5)

[0058] In equation (5), is the empirical average score of the template , and if . Optionally, instead of dividing by , it can be a function of and , i.e., , where the function increases with and decreases with . If , then (indicating that the initial performance is unknown). In equation (5), is the total number of uses of all templates, i.e., the sum of the number of uses of all templates.

[0059] In equation (5), a balancing factor, , for example . Illustratively, the UCB score is also based on a balancing factor, which indicates a template selection strategy, the larger the balancing factor, the more inclined to explore templates with less usage times; the smaller the balancing factor, the more inclined to exploit templates with high average scores.

[0060] Optionally, the UCB calculation formula can also be: (6)

[0061] The parameter A in formula (6) is an adjustable hyperparameter, for example, A = 10, 20, 30 or other. In the is a natural logarithm function. It should be understood that formula (5) and (6) are only illustrative, and the present disclosure is not limited thereto.

[0062] It should be understood that the term "balancing factor" can also be referred to as exploration factor, exploration-exploitation balancing factor, exploration coefficient, exploration parameter, exploration-exploitation parameter, exploration intensity or other; the present disclosure is not limited thereto.

[0063] In some embodiments of the present disclosure, the at least one candidate template is the top K candidate templates with the highest corresponding UCB scores, where K is a predefined positive integer. Illustratively, the UCB scores of all templates can be calculated by formula (5) or (6), and the top 5 templates with the highest scores, i.e., Top-5 templates, are selected.

[0064] In some embodiments of the present disclosure, the UCB preference module 106 inputs the Top-K templates as retrieval results into the LLM 101, and finally generates the target code by the RAG generation module 107. At the same time, the feedback update module 108 continues to receive feedback information of the user's response to the code, and dynamically updates the template information.

[0065] It should be understood that some of the modules in the embodiments of the present disclosure (such as the embedding generation module 104, the RAG generation module 107, etc.) or all the modules can be integrated in the LLM 101, and the present disclosure is not limited thereto.

[0066] As an example, the programming agent 102 can adopt a four-segment structure of "System Prompt → Context Information → User Query → Output Requirement" when interacting with the LLM 101, as shown in Table 1: Table 1

[0067] Figure 3 A schematic flowchart of a code generation process 300 based on a large language model according to some embodiments of the present disclosure is shown. Figure 3 As shown, at the initial stage of the entire system operation, the usage count and score of all templates are initialized with 301, that is... The user query processing 302 is then performed, for example, converting the user's requirement description in the query into a vector representation, i.e., an embedding vector, through the embedding generation module 104. Then, similarity calculation 303 is performed, for example, calculating the similarity between the user's code requirement description and all templates stored in Redis through the similarity calculation module 105. For example, using the UCB optimization module 106 and based on similarity, historical template performance (such as usage frequency and score), and a balance factor, the UCB score of each template is calculated (304), and the K templates with the highest scores are selected (305), i.e., the Top-K templates. In 306, the Top-K templates are input into the LLM, and then into the RAG code generation 307. Simultaneously, the user can judge the code's functional performance 308 and input feedback information. The system can read the functional performance from the feedback information and then update the template information based on the functional performance (309). Steps 302-309 are repeated for all subsequent online user queries, implementing dynamic iterative optimization of template performance.

[0068] It should be understood that in the embodiments of this disclosure, "first," "second," etc., are only used to indicate that multiple objects may be different, but at the same time, it does not exclude that two objects are the same, and should not be interpreted as any limitation on the embodiments of this disclosure.

[0069] It should also be understood that the manner, situation, category, and division of embodiments in the present disclosure are for the convenience of description only and should not constitute a special limitation. Various manners, categories, situations, and features in the embodiments can be combined with each other where logically consistent.

[0070] It should also be understood that the foregoing is merely to help those skilled in the art better understand the embodiments of this disclosure, and is not intended to limit the scope of the embodiments of this disclosure. Those skilled in the art can make various modifications, variations, or combinations based on the foregoing. Such modifications, variations, or combinations are also within the scope of the embodiments of this disclosure.

[0071] It should also be understood that the above description focuses on highlighting the differences between the various embodiments. Similarities or commonalities can be referenced or learned from each other, and for the sake of brevity, they will not be repeated here.

[0072] Figure 4A schematic block diagram of an example apparatus 400 is shown, according to some embodiments of the present disclosure. The apparatus 400 can be implemented by software, hardware, or a combination of both. As shown, the apparatus 400 includes a receiving unit 402, a selecting unit 404, and a generating unit 406. Figure 4 The receiving unit 402 is configured to receive a user query, the user query including a user requirement description. The selecting unit 404 is configured to select, based on template weights of a plurality of candidate templates in a template library, at least one candidate template corresponding to the user query from the template library, wherein the template library stores the plurality of candidate templates and the template weight of each template in the plurality of candidate templates, and the template weight is associated with a number of times of using the corresponding template and a result condition of generating code using the corresponding template. The generating unit 406 is configured to input the user query and the at least one candidate template into a large language model to generate a code response corresponding to the user query.

[0073] The receiving unit 402 is configured to receive a user query, the user query including a user requirement description. The selecting unit 404 is configured to select, based on template weights of a plurality of candidate templates in a template library, at least one candidate template corresponding to the user query from the template library, wherein the template library stores the plurality of candidate templates and the template weight of each template in the plurality of candidate templates, and the template weight is associated with a number of times of using the corresponding template and a result condition of generating code using the corresponding template. The generating unit 406 is configured to input the user query and the at least one candidate template into a large language model to generate a code response corresponding to the user query.

[0074] In some embodiments, the apparatus 400 can further include an updating unit. The receiving unit 402 is configured to receive feedback information of the code response from the user; and the updating unit is configured to update, based on the feedback information, template information of the at least one candidate template in the template library. In some embodiments, the template weight of the first template in the plurality of candidate templates is associated with: a number of times of using the first template within a preset historical time period, and a result condition of generating code using the first template. In some embodiments, the result condition of generating code using the first template includes any one of: the code generated based on the first template is directly adopted without modification, the code generated based on the first template is adopted after one or more modifications, or the code generated based on the first template is not adopted.

[0075] In some embodiments, the selecting unit 404 is configured to: selecting the at least one candidate template includes: determining a similarity between the user query and each template in the plurality of candidate templates; determining a UCB score between the user query and each template based on the plurality of similarities between the user query and the plurality of candidate templates and the template information of the plurality of candidate templates.

[0076] In some embodiments, the UCB score is further based on a balance factor, the balance factor indicating a template selection strategy.

[0077] In some embodiments, the at least one candidate template is K candidate templates in the plurality of candidate templates with the highest corresponding UCB scores, wherein K is a predefined positive integer.

[0078] In some embodiments, the corresponding UCB score of the at least one candidate template exceeds a preset score value.

[0079] In some embodiments, the feedback information indicates that the user has not modified the code response, and the update unit is configured to: increment the usage count of each candidate template in at least one candidate template by 1, and add a first preset value to the score.

[0080] In some embodiments, the feedback information indicates that the code response operates normally after being modified by the user, and the update unit is configured to: increment the usage count of each candidate template in at least one candidate template by 1, and add a second preset value to the score.

[0081] In some embodiments, the feedback information indicates that the code response still fails to function properly after being modified by the user, and the update unit is configured to: increment the usage count of each candidate template in at least one candidate template by 1, and subtract a specific value from the score, the specific value being associated with the number of modifications to the code response and a third preset value.

[0082] Figure 4 The device 400 can be used to achieve the above-mentioned combination. Figures 1 to 3 For the sake of brevity, the process described will not be repeated here.

[0083] The division of modules or units in the embodiments of this disclosure is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods. Furthermore, the functional units in the disclosed embodiments may be integrated into one unit, exist as separate physical entities, or two or more units may be integrated into one unit. The integrated unit described above can be implemented in hardware or as a software functional unit.

[0084] Figure 5 A block diagram of an example device 500 that can be used to implement embodiments of the present disclosure is shown. It should be understood that... Figure 5 The device 500 shown is merely exemplary and should not be construed as limiting the functionality and scope of the implementation described herein. For example, device 500 can be used to perform the functions described above. Figures 1 to 3 The process described.

[0085] like Figure 5 As shown, device 500 is in the form of a general-purpose computing device. Components of computing device 500 may include, but are not limited to, one or more processors or processing units 510, memory 520, storage devices 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. Processing unit 510 may be a physical or virtual processor and is capable of performing various processes according to programs stored in memory 520. In a multiprocessor system, multiple processing units execute computer-executable instructions in parallel to improve the parallel processing capability of computing device 500.

[0086] The computing device 500 typically includes a plurality of computer storage media. Such media can be volatile, nonvolatile, removable, and / or non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Storage 520 can be volatile memory (e.g., registers, cache, random access memory (RAM)), non-volatile memory (e.g., read only memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory), or some combination thereof. Storage 530 can be removable or non-removable media and can include machine readable media such as flash drives, magnetic disks or any other medium that can be used to store information and / or data (e.g., training data for training) and that can be accessed by the computing device 500.

[0087] The computing device 500 can further include additional removable / non-removable, volatile / non-volatile storage media. Although not shown, a removable, non-volatile memory such as a floppy disk drive, a magnetic tape drive, an optical disk drive or any other storage device that can be used to store information and / or data (e.g., training data for training) and that can be accessed by the computing device 500 can be provided. Figure 5 In these instances, each drive can be connected to the bus (not shown) by one or more data media interfaces. The storage 520 can include a computer program product 525 having one or more program modules configured to carry out the various methods or actions of the various implementations of the present disclosure.

[0088] The communication unit 540 enables communications with other computing devices over a communication media. Additionally, the functionality of the components of the computing device 500 can be implemented in a single computing cluster or a plurality of computer machines that are capable of communicating over a communication connection. Thus, the computing device 500 can operate in a networked environment using logical connections to one or more other servers, network personal computers (PCs), or another network nodes in the networking environment.

[0089] Input device 550 can be one or more input devices, such as a mouse, a keyboard, a trackball, etc. Output device 560 can be one or more output devices, such as a display, a speaker, a printer, etc. Computing device 500 can also communicate with one or more external devices (not shown) such as a storage device, a display device, etc. through communication unit 540, and with one or more devices that enable a user to interact with computing device 500, or any devices (e.g. a network card, a modem, etc.) that enable computing device 500 to communicate in a network environment. Such communication can be enabled by an input / output (I / O) interface (not shown).

[0090] According to an example implementation of the present disclosure, a computer readable storage medium is provided having computer executable instructions stored thereon, where the computer executable instructions are executed by a processor to implement the method described above. According to an example implementation of the present disclosure, a computer program product is also provided that is tangibly stored on a non-transitory computer readable medium and includes computer executable instructions, where the computer executable instructions are executed by a processor to implement the method described above. According to an example implementation of the present disclosure, a computer program product is provided having a computer program stored thereon, which when executed by a processor implements the method described above.

[0091] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.

[0092] These computer readable program instructions can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks. These computer readable program instructions can also be stored in a computer readable storage medium that can include a non-transitory computer readable storage medium. The instructions stored on the computer readable storage medium can be used to program a computer, a programmable data processing apparatus, and / or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.

[0093] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer, other programmable data processing apparatus, or other device implement the functions / acts specified in the flowchart and / or block diagram block or blocks.

[0094] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer, other programmable data processing apparatus, or other device implement the functions / acts specified in the flowchart and / or block diagram block or blocks.

[0095] The implementations of the disclosure have been described above with the intent to be illustrative rather than limiting. Although being shown and described in terms of certain implementations and overall functions, the implementations are not intended to exclude other implementations or technologies. Modifications and changes can be made in arrangement, operation, and details of the methods and apparatus described. Many modifications and variations of the described implementations are possible and will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described implementations. It is therefore intended that the description be considered in all respects as illustrative, rather than limiting, of the disclosed implementations. Changes are made to the descriptions that are intended to be protective of the applications claimed. It is therefore intended that the description be considered in all respects as illustrative, rather than limiting, of the disclosed implementations. Changes are made to the descriptions that are intended to be protective of the applications claimed.

Claims

1.A method of code generation based on large language model, comprising: receiving a user query, the user query comprising a user requirement description; selecting at least one candidate template corresponding to the user query from a template library based on template weights of a plurality of candidate templates in the template library, wherein the template library stores the plurality of candidate templates and the template weight of each template in the plurality of candidate templates, wherein the template weight is associated with the number of times of using the corresponding template and the result of generating code using the corresponding template; and inputting the user query and the at least one candidate template into a large language model to generate a code response corresponding to the user query. 2.The method of claim 1, further comprising: receiving feedback information of the code response from the user; and updating the number of times of using and the template weight of the at least one candidate template in the template library based on the feedback information. 3.The method of claim 1, wherein the template weight of a first template in the plurality of candidate templates is associated with the number of times of using the first template in a preset historical time period and the result of generating code using the first template. 4.The method of claim 3, wherein the result of generating code using the first template comprises any one of: the code generated based on the first template is directly adopted without modification, the code generated based on the first template is adopted after one or more modifications, or the code generated based on the first template is not adopted. 5.The method of claim 1, wherein selecting the at least one candidate template comprises: determining the similarity between the user query and each template in the plurality of candidate templates; determining the upper confidence bound (UCB) score between the user query and each template based on the plurality of similarities between the user query and the plurality of candidate templates and the template information of the plurality of candidate templates; and selecting the at least one candidate template based on the plurality of UCB scores between the user query and the plurality of candidate templates. 6.The method of claim 5, wherein the UCB score is further based on a balancing factor, the balancing factor indicating a template selection strategy. 7.The method of claim 5, wherein the at least one candidate template is the K templates with the highest corresponding UCB scores in the plurality of candidate templates, wherein K is a predefined positive integer. 8.The method of claim 5, wherein the corresponding UCB score of the at least one candidate template exceeds a preset score value. 9.The method of claim 2, wherein the feedback information indicates that the user does not modify the code response, and wherein updating the number of times of using and the template weight comprises: adding 1 to the number of times of using and a first preset value to the template weight of each candidate template in the at least one candidate template. 10.The method of claim 2, wherein the feedback information indicates that the code response is normally running after being modified by the user, and wherein updating the number of times of using and the template weight comprises: ​ ​ incrementing a usage frequency of each of the at least one candidate template by 1 and a template weight by a second preset value. 11.The method of claim 2, wherein the feedback information indicates that the code response cannot normally run after being modified by the user, and wherein updating the usage frequency and the template weight comprises: incrementing a usage frequency of each of the at least one candidate template by 1 and a template weight by a second preset value. 12.An electronic device comprising: at least one processing unit; at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions which, when executed by the at least one processing unit, cause the electronic device to perform the method according to any one of claims 1 to 11. 13.An apparatus for code generation based on a large language model, comprising: a receiving unit configured to receive a user query, the user query comprising a user requirement description; a selecting unit configured to select at least one candidate template corresponding to the user query from a template library based on template weights of a plurality of candidate templates in the template library, wherein the template library stores a plurality of candidate templates and a template weight of each of the plurality of candidate templates, wherein the template weight is associated with a usage frequency of the corresponding template and a result condition of generating a code using the corresponding template; and a generating unit configured to input the user query and the at least one candidate template into a large language model to generate a code response corresponding to the user query. 14.A computer readable storage medium having stored thereon a computer program, the program being executed by a processor to implement the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Code file generation method and device based on automobile platform, equipment and medium

    CN116107577A

  • Template generation method and device, electronic equipment and storage medium

    CN116842926A

  • Structured query language generation method and device, electronic equipment and storage medium

    CN118093621A

  • Code generation method and device based on natural language and medium

    CN120469666A

  • Nudging neural conversational model with domain knowledge

    US20200160841A1