CN121092153A - Code generation method based on large language model and electronic equipment - Google Patents
Code generation method based on large language model and electronic equipmentInfo
- Publication number
- CN121092153A CN121092153A CN202511639571.4A CN202511639571A CN121092153A CN 121092153 A CN121092153 A CN 121092153A CN 202511639571 A CN202511639571 A CN 202511639571A CN 121092153 A CN121092153 A CN 121092153A
- Authority
- CN
- China
- Prior art keywords
- template
- candidate
- code
- user query
- templates
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Embodiments of the present disclosure relate to a method and an electronic device for code generation based on a large language model. The code generation method based on the large language model comprises the steps of receiving a user query, wherein the user query comprises a user demand description, selecting at least one candidate template corresponding to the user query from a template library based on template information of a plurality of candidate templates in the template library, wherein the template library stores the plurality of candidate templates and template weights of each template in the plurality of candidate templates, the template weights are associated with the use times of the corresponding template and the result condition of using the corresponding template to generate codes, and inputting the user query and the at least one candidate template into the large language model to generate code responses corresponding to the user query. In this way, the success rate and accuracy of online user code generation are improved.
Description
Technical Field
The present disclosure relates generally to the field of computers, and more particularly to a method and electronic device for large language model based code generation.
Background
With the increasing demand for software development, online users are striving for code generation based on specific technology stacks, such as platform application programming interfaces (application programming interface, APIs), front end templates, domain-specific languages (DSLs). The traditional code generation scheme relies on fixed template matching or single large language model (large language model, LLM) generation, lacks dynamic feedback and optimization on the template use effect, cannot iteratively improve the code generation success rate, and part of templates with high potential and few use times are ignored (under exploration) for a long time, while part of templates with low success rate are repeatedly used (over utilization).
Although the relevance can be improved by the aid of a retrieval enhancement generation (RAG) technology, the conventional RAG scheme is mostly based on static similarity sorting, historical performance and exploration requirements of templates are not combined, and the relationship between a high-success rate template and a potential high-quality template is difficult to balance, so that the code generation success rate and the code generation efficiency are difficult to further improve.
Disclosure of Invention
According to example embodiments of the present disclosure, a method, apparatus, electronic device, computer-readable storage medium, and computer program product for large language model based code generation are provided. The template using effect can be dynamically fed back and optimized, so that the success rate and accuracy of online user code generation can be improved.
In a first aspect of the disclosure, a method for generating code based on a large language model is provided, which comprises the steps of receiving a user query, wherein the user query comprises 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 the plurality of candidate templates and the template weight of each template in the plurality of candidate templates, the template weights are associated with the use times of the corresponding template and the result condition of generating 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 code response corresponding to the user query.
In a second aspect of the present disclosure, there is provided 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, which instructions, when executed by the at least one processing unit, cause the electronic device to perform the method described according to the first aspect of the present disclosure.
In a third aspect of the disclosure, an apparatus for generating codes based on a large language model is provided, which includes a receiving unit configured to receive a user query, the user query including a user demand 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 template weights of each of the plurality of candidate templates, wherein the template weights are associated with a number of uses of the corresponding template and a result case of generating codes using the corresponding template, and a generating unit to input the user query and the at least one candidate template to the large language model, and generate a code response corresponding to the user query.
In a fourth aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon machine executable instructions which, when executed by a device, cause the device to perform a method according to the first aspect of the present disclosure.
In a fifth aspect of the present disclosure, there is provided a computer program product comprising computer executable instructions which, when executed by a processor, implement the method described in accordance with the first aspect of the present disclosure.
In a sixth aspect of the present disclosure, there is provided an electronic device comprising processing circuitry configured to perform the method described in accordance with the first aspect of the present disclosure.
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 be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The above and other features, advantages and aspects of embodiments of the present disclosure will become more apparent by reference to the following detailed description when taken in conjunction with the accompanying drawings. In the drawings, wherein like or similar reference numerals designate like or similar elements, and wherein:
FIG. 1 illustrates a schematic diagram of a system according to some embodiments of the present disclosure;
FIG. 2 illustrates a schematic flow diagram of a method of large language model based code generation in accordance with some embodiments of the present disclosure;
FIG. 3 illustrates a schematic diagram of a process of large language model based code generation, according to some embodiments of the present disclosure;
FIG. 4 illustrates a block diagram of an example apparatus in accordance with some embodiments of the present disclosure, and
FIG. 5 illustrates a block diagram of an example device that may be used to implement embodiments of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure have been shown in the accompanying drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustration purposes only and are not intended to limit the scope of the present disclosure.
The large language model in embodiments of the present disclosure may be applied to a variety of application scenarios, such as writing articles, generating dialogs, creating poems, generating content for social media/news, etc., generating codes/notes/documents, generating teaching materials, assisting language learning, etc.
In practical applications, code may be generated using a single language model or relying on fixed template matching. However, the conventional code generation method lacks dynamic feedback and optimization on the template use effect, and cannot iteratively improve the code generation success rate. The conventional RAG scheme also does not combine the historical performance and the exploration requirement of the template, so that the code generation success rate and the code generation efficiency are difficult to further improve.
To address the above-mentioned problems, as well as potentially other problems, embodiments of the present disclosure provide a method of code generation based on a large language model. In embodiments of the present disclosure, the programming agent may dynamically update template information, e.g., the number of times a template is used and the template weight, based on feedback information from the user on the functional performance of the generated code. In addition, the programming agents of the present disclosure explore templates that have high potential but are used a small number of times. In this way, the success rate and accuracy of online user code generation are further improved.
Fig. 1 illustrates a schematic diagram of a system 100 according to some embodiments of the present disclosure. 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 embedded generation module 104, a similarity calculation module 105, a confidence upper bound (upper confidence bound, UCB) preference module 106, a RAG generation module 107, and a feedback update module 108.
As shown in fig. 1, LLM 101 and programming agent 102 can receive and transmit information from each other to cooperate to perform a related task. The LLM 101 can perform deep understanding and processing on natural language, and complete various complex tasks such as code generation, knowledge question and answer and the like based on a neural network. After receiving the hint information, the LLM 101 can process the hint information and convert it into a vector representation.
It will be appreciated that the prompt entered by the user is most often presented in natural language. The prompt input by the user to the large language model LLM 101 may be a piece of text that directs the model to generate a particular output. For example, the hint may be a question, a sentence fragment, an instruction, or any other form of text. The LLM 101 may predict the following content based on the prompt information, for example, in a task of generating a code, if the prompt information is "you are professional code generation assistants," a code that can be directly run is generated based on the user requirement and the provided reference template, and the LLM 101 outputs a code that meets the user requirement according to the input prompt word.
Illustratively, the template library module 103 may store template information of a plurality of candidate templates, taking template X (first template) as an example, the template information of the template X may include identification information of the template X, the number of times of use of the template X, and a template weight of the template X, wherein the template weight of the template X is related to the number of times of use of the template X and a result of generating a code using the template X in a preset history period. For example, the number of uses of template X may be a positive integer (number of calls) or 0 (no calls). For example, the outcome of generating code using template X may include outcome of generating code each time X is used, where a outcome may be any of directly accepted code generated based on template X without modification, accepted code generated based on template X with one or more modifications, or unamplified code generated based on template X.
Alternatively, for template X, the template weight of template X may be determined based on the result of historical use of template X to generate code. Alternatively, for the template X, the number of uses (e.g., n) and the template weight (e.g., s) of the template X within a preset history period may be stored.
In embodiments of the present disclosure, the template weights may also be referred to as template scores, etc. for characterizing the success rate at which the code of the corresponding template is adopted, and for example, the "score" referred to below may be replaced with the template weight.
In an embodiment of the present disclosure, the template library module 103 stores a plurality of validated templates T and associates a history buffer for each template,AndThe number of times the template is used in a preset history period, and the score of the template, respectively. Illustratively, the score of a stored template relates to the historical usage of the corresponding template, such as where the corresponding template history was used and the generated code was successfully accepted (or accepted after modification, or not accepted even if modification). Assuming that m (m is an integer greater than or equal to 1) templates exist in the template library module 103, wherein a template refers to a set of verification test examples containing "user query-code" pairs, the set of all templates is denoted asEach templateBy inquiry(User demand description) and code(Corresponding to the correct code) and all pass the function verification, wherein i is an integer greater than or equal to 1 and less than or equal to m.
Illustratively, 10000 sets of code template-based "query-code" pairs are collected, manually validated, stored in Redis, and initialized。
In an embodiment of the present disclosure, the embedded generation module 104 combines the user query Q with a template based on an embedded language model (embedding language model)Is converted into an embedded vector (embedding vector) for capturing text semantic information. The term "embedded vector" is also referred to as a low-dimensional dense vector, feature vector, or the like.
Illustratively, the embedding vector dimension is denoted as d, the templateIs written as the embedded vector of (2)(For the real set, d is the vector dimension), the embedded vector corresponding to the user query is noted as。
Alternatively, the embedded language model employs a model structure MM to convert a string into 768-dimensional embedded vectors. It should be appreciated that other embedded language models, such as Gemini Embeddings, etc., may also be employed by the embedded language model, as may other dimensions, as are vector dimensions, without limitation to this disclosure.
For example, a user enters a query, such as "exact-based landing page code (using the XY component)", and the model structure MM generates an embedded vector for the user query.
In embodiments of the present disclosure, the similarity calculation module 105 calculates cosine similarities of the user query embedded vector and the respective template embedded vectors, which may characterize semantic relevance of the user query to each template. For example, the cosine similarity of the embedded vector of the user query and 10000 templates is calculated.
In an embodiment of the present disclosure, UCB optimization module 106 calculates UCB scores for each template based on similarity, template history performance, and exploration factors, and screens Top-K templates. The historical performance of the template includes the number of uses of the template within a preset historical periodScore of template. Illustratively, an array of each template use case can be recorded using a history bufferIncluding the number of times of useAnd cumulative performance score. The UCB optimization module 106 selects the K templates with the highest scores, namely Top-K templates, from the candidate templates based on the UCB scores.
The method has the advantages that partial templates with high potential but few use times can be mined by introducing the exploration factors into the algorithm for calculating UCB scores, and meanwhile, the scores of the templates are taken into considerationAnd the exploration factors are used for balancing exploration and utilization of the templates, so that the accuracy and the efficiency of code generation are improved. The term "exploration factor" may also be referred to as a balance factor, exploration-utilization balance factor, exploration parameter, exploration-utilization parameter, exploration intensity, or otherwise, as not limited to this disclosure.
For example, UCB scores for each template (e.g., 10000 templates described above) are calculated using UCB optimization module 106, and the 5 highest scoring templates, namely Top-5 templates, are selected. Illustratively, the 5 templates screened have a similarity to the user query of greater than or equal to 0.75, wherein the number of 2 template uses is less than or equal to 3. It can be appreciated that, although the number of times of using the 2 templates is small in total 10000 templates, the Top-5 templates can be screened by UCB score, so that templates with small number of times of use but high potential can be explored, and the use rate of the high potential templates is improved.
In the embodiment of the present disclosure, the RAG generation module 107 inputs the Top-K template as the search result to the LLM 101, and the two cooperate to generate the object code. For example, the Top-5 template is input into the LLM 101 to generate a React landing page code containing the XY component.
In an embodiment of the present disclosure, the feedback update module 108 updates the history buffer of the corresponding template according to the user's feedback information for the generated code. Illustratively, the user feedback "the code was run successfully after the button style was modified" (number of modifications t=1), updates the Top-5 template(Each add 1) and(E.g., 1.2 each). Illustratively, the user feedback "the code still fails after 10 button styles have been modified" (number of modifications t=10), number of uses of update Top-5 templateScore of (each plus 1) and template(E.g., each minus 1). It should be appreciated that the above-described addition and subtraction scores for the template scores are merely exemplary, and the present disclosure is not limited in this regard, e.g., the addition and subtraction scores may be a function related to the number of times the code is modified.
FIG. 2 illustrates a schematic flow diagram of a method 200 of large language model based code generation, according to some embodiments of the present disclosure. At block 202, a user query is received, the user query including a user demand description. At block 204, at least one candidate template corresponding to the user query is selected from a template library based on template weights for a plurality of candidate templates in the template library, wherein the plurality of candidate templates and the template weights for each of the plurality of candidate templates are stored in the template library, wherein the template weights are associated with a number of uses of the corresponding template and a resulting situation in which the code was generated using the corresponding template. At block 206, the user query and at least one candidate template are input to a large language model, generating a code response corresponding to the user query.
In some embodiments of the present disclosure, a mode in which the programming agent 102 works in conjunction with the LLM 101 is employed to more efficiently process hints information. The programming agent 102 can screen out the Top-K template meeting the requirements and excavate the template with less use times and high potential, and execute the same flow for all subsequent online user queries, thereby further realizing the dynamic iterative optimization of the template performance and the self-learning closed loop of the model.
By way of example, the user demand description may be text, speech, etc. Illustratively, the code requirement description may be entered through a human-machine interaction interface.
In some embodiments of the present disclosure, feedback information of a user's response to the code is received, and a number of uses and template weights of at least one candidate template in the template library are updated based on the feedback information. Taking a first template of the candidate templates as an example, the template weight of the first template is related to the number of times of using the first template in a preset history periodAnd a result instance of the code generated using the first template.
Illustratively, the resulting case of generating code using the first template includes any of code generated based on the first template that is directly accepted without modification, code generated based on the first template that is accepted after one or more modifications, or code generated based on the first template that is not accepted.
Alternatively, the score of the first template may also be calculated/updated based on the result of the code generation using the first template. It should be appreciated that the number of uses and score may be initialized when the template is first stored in the history buffer, e.g.Thereby ensuring the correctness of template information after the template is used for a plurality of times.
Illustratively, after the user uses the generated code, the user feeds back his or her functional performance through feedback information, and the feedback update module 108 updates the number of uses of the template and the score of the template recorded in the history buffer of each template in Top-K according to the feedback information.
Illustratively, the feedback information includes one or more types. For example, the feedback information indicates that the user did not modify the code response (i.e., the code generated based on at least one candidate template was not modified and was directly accepted), the feedback update module 108 adds 1 to the number of uses of each candidate template of the K templates and adds a first preset value to the score. For example, assuming that the first preset value is 1, then
(1)
In formula (1)Indicating that the assignment update, i.e. the left parameter update, is the right calculation result.
Illustratively, the feedback information indicates that the code response was modified by the user to function properly (i.e., the code generated based on the at least one candidate template was adopted after one or more modifications), and wherein updating the template information includes adding 1 to the number of uses of each of the at least one candidate template and adding a second preset value to the score. For example, assume that the second preset value is 1.2, then
(2)
Optionally, the second preset value is greater than the first preset value, so that in a subsequent user query process, the use rate of the template corresponding to the modified code which normally operates is improved.
In some embodiments of the present disclosure, the feedback information indicates that the code response is not still functioning properly 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 includes adding 1 to the number of uses of each of the at least one candidate template and subtracting a particular value from the score, the particular value being associated with the number of modifications of the code response and a third preset value. For example, assuming that the third preset value is 1, then
(3)
In formula (3)For the number of modifications made by the user,Is an integer greater than 1 and is selected from the group consisting of,Representation fetchAnd a smaller value, constant, of 1The template performance evaluation can be flexibly configured according to specific situations (such as computing resources, response speed and the like), for example, a is taken to be 10, so that template performance evaluation is not excessively influenced due to too few modification times of failure, for example, the corresponding template is not considered to have exploratory value due to single modification failure.
As discussed above, the first preset value, the second preset value, and the third preset value may be referred to in updating the template information, and it should be understood that the size of the first/second/third preset value is not limited by the embodiments of the present disclosure, for example, the three may be different from each other, or two of the three may be equal, or the like. For example, the size may be set based on an application policy, which may be a plurality of candidate templates that recommend the number of uses of the application, or a template that suggests that the application is not used, or the like.
In some embodiments of the present disclosure, UCB optimization module 106 selects at least one candidate template comprising determining a similarity between the user query and each of the plurality of candidate templates, determining an upper bound UCB score for confidence between the user query and each of the plurality of templates based on the plurality of similarities between the user query and the plurality of candidate templates and the template information for the plurality of candidate templates, and selecting at least one candidate template based on the user query and the plurality of UCB scores for the plurality of candidate templates.
For example, for each templateThe semantic similarity to the user query Q is computed, for example expressed as:
(4)
Wherein the function is ,Is vector quantityAnd (3) withIs used for the dot product of (a),Is vector quantityIs used for the mold length of the mold,Is vector quantityIs a die length of the die. In the formula (4), the amino acid sequence of the compound,Equivalent to in a function,Equivalent to a function of。
Illustratively, for each templateThe UCB optimization module 106 calculates the UCB score. In some embodiments, the UCB score is also based on a balance factor, which indicates the template selection policy. Alternatively, the UCB calculation formula may be:
(5)
in formula (5) Is a templateIf the empirical average score of (a)Then. Alternatively, except forDividing, also can be a reference toAndIs a function of (i.e.)Wherein the function isAlong with itIncreasing withDecreasing. If it isThen(Indicating that the initial performance is unknown). In formula (5)For the total number of uses of all templates,I.e. the sum of the number of uses of all templates.
In formula (5)As a balance factor, the balance factor is,For example. Illustratively, the UCB score is also based on a balance factor, which indicates the template selection policy,The larger the template, the more likely it is to explore the template with fewer uses; smaller templates tend to utilize higher average scores.
Optionally, the UCB calculation formula may be:
(6)
The parameter a in equation (6) is an adjustable super parameter, such as a=10, 20,30 or others. In formulae (5) and (6) As a natural logarithmic function. It should be understood that formulas (5) and (6) are merely exemplary, and the present disclosure is not limited in this regard.
It should be appreciated that the term "balance factor" may also be referred to as a heuristics factor, heuristics-utilized balance factor, heuristics coefficient, heuristics parameter, heuristics-utilized parameter, heuristics intensity, or otherwise, and is not limiting to this disclosure.
In some embodiments of the present disclosure, the at least one candidate template is the K highest scoring of the corresponding UCB of the plurality of candidate templates, wherein K is a predefined positive integer. Illustratively, UCB scores for all templates can be calculated by equation (5) or (6), and the 5 templates with the highest scores, namely Top-5 templates, are selected.
In some embodiments of the present disclosure, UCB optimization module 106 enters LLM 101 with the Top-K template as the search result, and finally generates the object code by 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.
It should be appreciated that some or all of the modules (e.g., the embedded generation module 104, the RAG generation module 107, etc.) in embodiments of the present disclosure may be integrated in the LLM 101, as the present disclosure is not limited in this regard.
As an example, the programming agent 102 may interact with the LLM 101 by adopting a four-segment structure of "System Prompt" →context information "→user request" →output request (Output Requirement) ", as shown in table 1:
TABLE 1
FIG. 3 illustrates a schematic flow diagram of a process 300 for large language model based code generation in accordance with some embodiments of the present disclosure. As shown in FIG. 3, at the initial stage of the overall system operation, the number of uses and scores for all templates are initialized 301, i.e. User query processing 302 is then performed, such as converting the user requirements description in the user query to a vector representation, i.e., an embedded vector, via the embedded generation module 104. Similarity calculation 303 is then performed, for example, by the similarity calculation module 105 calculating the similarity of the code requirement description of the user to all templates stored by the Redis, for example, using the UCB preference module 106 and calculating UCB scores for each template based on the similarity, the historical performance of the template (e.g., number of uses, score) and the balance factor (304), and screening the K templates (305) with the highest scores, i.e., top-K templates. At 306, the Top-K template is entered into the LLM and then to RAG code generation 307. At the same time, the user may determine the code performance 308 and input feedback information from which the system may read the performance and update the template information based on the performance (309). Repeating steps 302-309, executing the same flow for all subsequent online user queries, and realizing dynamic iterative optimization of template performance.
It should be understood that in embodiments of the present disclosure, "first," "second," etc. are merely intended to indicate that multiple objects may be different, but at the same time do not exclude that two objects are identical, and should not be construed as limiting the embodiments of the present disclosure.
It should also be understood that the manner, case, category, and division of embodiments in the embodiments of the present disclosure are for descriptive convenience only and should not be construed as being particularly limiting, and that the features of the various manners, categories, cases, and embodiments may be combined with one another in a logical manner.
It should also be understood that the above is only intended to assist those skilled in the art in better understanding the embodiments of the present disclosure, and is not intended to limit the scope of the embodiments of the present disclosure. Various modifications, variations, combinations, etc. may be made by those skilled in the art in light of the above teachings. Such modifications, variations, or combinations are also within the scope of embodiments of the present disclosure.
It should also be appreciated that the foregoing description focuses on differences between the various embodiments and that the same or similar features may be referred to or otherwise referred to herein for brevity and clarity.
Fig. 4 illustrates a schematic block diagram of an example apparatus 400, according to some embodiments of the disclosure. The apparatus 400 may be implemented in software, hardware, or a combination of both. As shown in fig. 4, the apparatus 400 includes a receiving unit 402, a selecting unit 404, and a generating unit 406.
The receiving unit 402 is configured to receive a user query, the user query comprising a user requirement description. And a selection unit 404 configured to select at least one candidate template corresponding to the user query from the 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 of the plurality of candidate templates, and wherein the template weights are associated with the number of uses of the corresponding template and the result of using the corresponding template to generate the code. The generating unit 406 is configured to input the user query and the at least one candidate template into the large language model, and generate a code response corresponding to the user query.
In some embodiments, the apparatus 400 may further include an updating unit. The receiving unit 402 is configured to receive feedback information of the user's response to the code, and the updating unit is configured to update template information of at least one candidate template in the template library based on the feedback information.
In some embodiments, the template weight of a first template of the plurality of candidate templates is associated with a number of uses of the first template within a preset historical period of time and a resulting condition of using the first template.
In some embodiments, the resulting case of generating code using the first template includes any of code generated based on the first template being directly accepted without modification, code generated based on the first template being accepted after one or more modifications, or code generated based on the first template being accepted.
In some embodiments, the selection unit 404 is configured to select at least one candidate template includes determining a similarity between the user query and each of the plurality of candidate templates, and determining a UCB score between the user query and each of the templates based on the plurality of similarities of the user query and the plurality of candidate templates and template information for the plurality of candidate templates.
In some embodiments, the UCB score is also based on a balance factor, which indicates the template selection policy.
In some embodiments, at least one candidate template is the K highest scoring UCB of the plurality of candidate templates, wherein K is a predefined positive integer.
In some embodiments, the corresponding UCB score of at least one candidate template exceeds a preset score.
In some embodiments, the feedback information indicates that the user has not modified the code response and the updating unit is configured to add 1 to the number of uses of each of the at least one candidate templates and add a first preset value to the score.
In some embodiments, the feedback information indicates that the code response is functioning properly after being modified by the user, and the updating unit is configured to add 1 to the number of uses of each of the at least one candidate templates and add a second preset value to the score.
In some embodiments, the feedback information indicates that the code response is still not functioning properly after being modified by the user, and the updating unit is configured to add 1 to the number of uses of each of the at least one candidate templates and subtract a specific value associated with the number of modifications of the code response and a third preset value.
The apparatus 400 of fig. 4 can be used to implement the processes described above in connection with fig. 1-3, and are not repeated here for brevity.
The division of the modules or units in the embodiments of the disclosure is schematically only one logic function division, and there may be another division manner in actual implementation, and in addition, each functional unit in the disclosed embodiments may be integrated in one unit, or may exist alone physically, or two or more units may be integrated into one unit. The integrated units may be implemented in hardware or in software functional units.
Fig. 5 illustrates a block diagram of an example device 500 that may be used to implement embodiments of the present disclosure. It should be understood that the apparatus 500 illustrated in fig. 5 is merely exemplary and should not be construed as limiting the functionality and scope of the implementations described herein. For example, the process described above with respect to fig. 1-3 may be performed using the apparatus 500.
As shown in fig. 5, 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 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. The processing unit 510 may be a real or virtual processor and is capable of performing various processes according to programs stored in the memory 520. In a multiprocessor system, multiple processing units execute computer-executable instructions in parallel to increase the parallel processing capabilities of computing device 500.
Computing device 500 typically includes a number of computer storage media. Such media may be any available media that is accessible by computing device 500 and includes, but is not limited to, volatile and non-volatile media, removable and non-removable media. The memory 520 may be volatile memory (e.g., registers, cache, random access memory (random access memory, RAM)), non-volatile memory (e.g., read Only Memory (ROM), electrically erasable programmable read only memory (ELECTRICALLY ERASABLE PROGRAMMABLE READ ONLY MEMORY, EEPROM), flash memory), or some combination thereof. Storage device 530 may be a removable or non-removable media and may include machine-readable media such as flash drives, magnetic disks, or any other media that may be capable of storing information and/or data (e.g., training data for training) and may be accessed within computing device 500.
Computing device 500 may further include additional removable/non-removable, volatile/nonvolatile storage media. Although not shown in fig. 5, a magnetic disk drive for reading from or writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk may be provided. In these cases, each drive may be connected to a bus (not shown) by one or more data medium interfaces. Memory 520 may include a computer program product 525 having one or more program modules configured to perform the various methods or acts of the various implementations of the present disclosure.
Communication unit 540 enables communication with other computing devices via a communication medium. Additionally, the functionality of the components of computing device 500 may be implemented in a single computing cluster or in multiple computing machines capable of communicating over a communications connection. Accordingly, the computing device 500 may operate in a networked environment using logical connections to one or more other servers, a network personal computer (personal computer, PC), or another network node.
The input device 550 may be one or more input devices such as a mouse, keyboard, trackball, etc. The output device 560 may be one or more output devices such as a display, speakers, printer, etc. Computing device 500 may also communicate with one or more external devices (not shown), such as storage devices, display devices, etc., with one or more devices that enable a user to interact with computing device 500, or with any device (e.g., network card, modem, etc.) that enables computing device 500 to communicate with one or more other computing devices, as desired, via communication unit 540. Such communication may be performed via an input/output (I/O) interface (not shown).
According to an exemplary implementation of the present disclosure, a computer-readable storage medium having stored thereon computer-executable instructions, wherein the computer-executable instructions are executed by a processor to implement the method described above is provided. According to an exemplary implementation of the present disclosure, there is also provided a computer program product tangibly stored on a non-transitory computer-readable medium and comprising computer-executable instructions that are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is provided, on which a computer program is stored which, when being executed by a processor, implements the method described above.
Various aspects of the present disclosure are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus, devices, and computer program products implemented according to the disclosure. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer readable program instructions may be provided to a processing unit 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 processing unit 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 may also be stored in a computer readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable medium having the instructions stored therein includes an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various implementations of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The foregoing description of implementations of the present disclosure has been provided for illustrative purposes, is not exhaustive, and is not limited to the implementations disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the various implementations described. The terminology used herein was chosen in order to best explain the principles of each implementation, the practical application, or the improvement of technology in the marketplace, or to enable others of ordinary skill in the art to understand each implementation disclosed herein.
Claims (14)
1. A method of large language model based code generation, comprising:
receiving a user query, wherein the user query comprises 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 weights of each template in the plurality of candidate templates, wherein the template weights are associated with the number of uses of the corresponding template and the result of generating code using the corresponding template, and
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 user response to the code, and
Based on the feedback information, the number of uses and template weights of the at least one candidate template in the template library are updated.
3. The method of claim 1, wherein the template weight of a first template of the plurality of candidate templates is associated with a number of uses of the first template within a preset historical period of time and a resulting situation in which the first template was used to generate code.
4. A method according to claim 3, wherein the resulting situation in which the code is generated using the first template comprises any of:
The code generated based on the first template is directly adopted without modification,
Code generated based on the first template is adapted after one or more modifications, or
Code generated based on the first template is not adopted.
5. The method of claim 1, wherein selecting at least one candidate template comprises:
determining a similarity between the user query and each of the plurality of candidate templates;
Determining a confidence upper bound UCB score between the user query and each template based on a plurality of similarities of the user query and the plurality of candidate templates and template information of the plurality of candidate templates, and
At least one candidate template is selected based on the user query and the plurality of candidate templates multiple UCB scores.
6. The method of claim 5, wherein the UCB score is further based on a balance factor, the balance factor indicating a template selection policy.
7. The method of claim 5, wherein the at least one candidate template is a top K number of 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.
9. The method of claim 2, wherein the feedback information indicates that the user did not modify the code response, and wherein updating the number of uses and template weights comprises:
and adding 1 to the number of times of using each candidate template in the at least one candidate template and adding a first preset value to the template weight.
10. The method of claim 2, wherein the feedback information indicates that the code response is functioning properly after being modified by the user, and wherein updating the number of uses and template weights comprises:
And adding 1 to the number of times of using each candidate template in the at least one candidate template and adding a second preset value to the template weight.
11. The method of claim 2, wherein the feedback information indicates that the code response is still not functioning properly after being modified by the user, and wherein updating the number of uses and template weights comprises:
adding 1 to the number of uses of each of the at least one candidate template and subtracting a specific value from a template weight, the specific value being associated with the number of modifications of the code response and a third 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 when executed by the at least one processing unit cause the electronic device to perform the method of any one of claims 1-11.
13. An apparatus for large language model based code generation, comprising:
a receiving unit configured to receive a user query, the user query including a user demand description;
A selection 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 of the plurality of candidate templates, wherein the template weights are associated with the number of uses of the corresponding template and the result of generating a code using the corresponding template, and
And the generating unit is used for inputting the user query and the at least one candidate template into a large language model and generating a code response corresponding to the user query.
14. A computer readable storage medium having stored thereon a computer program which when executed by a processor implements the method according to any of claims 1 to 11.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202511639571.4A CN121092153A (en) | 2025-11-10 | 2025-11-10 | Code generation method based on large language model and electronic equipment |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202511639571.4A CN121092153A (en) | 2025-11-10 | 2025-11-10 | Code generation method based on large language model and electronic equipment |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN121092153A true CN121092153A (en) | 2025-12-09 |
Family
ID=97885571
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202511639571.4A Pending CN121092153A (en) | 2025-11-10 | 2025-11-10 | Code generation method based on large language model and electronic equipment |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN121092153A (en) |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116107577A (en) * | 2022-09-28 | 2023-05-12 | 重庆长安汽车股份有限公司 | Method, device, equipment and medium for generating code file based on automobile platform |
| CN116842926A (en) * | 2023-07-13 | 2023-10-03 | 百度(中国)有限公司 | Template generation method and device, electronic equipment and storage medium |
| CN118093621A (en) * | 2024-02-20 | 2024-05-28 | 上海信投数字科技有限公司 | Structured query language generation method and device, electronic equipment and storage medium |
| CN120469666A (en) * | 2025-07-08 | 2025-08-12 | 济南宇视智能科技有限公司 | Code generation method, device and medium based on natural language |
-
2025
- 2025-11-10 CN CN202511639571.4A patent/CN121092153A/en active Pending
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116107577A (en) * | 2022-09-28 | 2023-05-12 | 重庆长安汽车股份有限公司 | Method, device, equipment and medium for generating code file based on automobile platform |
| CN116842926A (en) * | 2023-07-13 | 2023-10-03 | 百度(中国)有限公司 | Template generation method and device, electronic equipment and storage medium |
| CN118093621A (en) * | 2024-02-20 | 2024-05-28 | 上海信投数字科技有限公司 | Structured query language generation method and device, electronic equipment and storage medium |
| CN120469666A (en) * | 2025-07-08 | 2025-08-12 | 济南宇视智能科技有限公司 | Code generation method, device and medium based on natural language |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| EP3631618B1 (en) | Automated dependency analyzer for heterogeneously programmed data processing system | |
| Cummins et al. | Synthesizing benchmarks for predictive modeling | |
| CN107608951B (en) | Report generation method and system | |
| US12159235B2 (en) | Method and apparatus for verifying accuracy of judgment result, electronic device and medium | |
| Pandi et al. | Opttyper: Probabilistic type inference by optimising logical and natural constraints | |
| Paduraru et al. | An Automatic Test Data Generation Tool using Machine Learning. | |
| CN111985217B (en) | A keyword extraction method, computing device and readable storage medium | |
| CN116166236A (en) | Code recommendation method, device, computer equipment and storage medium | |
| CN117094302A (en) | Automatic processing method, device and storage medium based on ChatGPT | |
| CN107688609A (en) | A kind of position label recommendation method and computing device | |
| CN112668281A (en) | Automatic corpus expansion method, device, equipment and medium based on template | |
| JP7757023B2 (en) | Classification support system, classification support device, classification support method, and program | |
| CN116894434A (en) | Grammar error correction methods and electronic devices | |
| CN116541071A (en) | Application programming interface migration method based on prompt learning | |
| CN119088368B (en) | Code generation method and device | |
| CN114780577A (en) | SQL statement generation method, device, device and storage medium | |
| Wagg et al. | Streamlining and standardizing software citations with The Software Citation Station | |
| CN121092153A (en) | Code generation method based on large language model and electronic equipment | |
| JP2017538226A (en) | Scalable web data extraction | |
| US20250321959A1 (en) | Hybrid natural language query (nlq) system based on rule-based and generative artificial intelligence translation | |
| CN120104173A (en) | Code annotation information processing method, device, computer equipment and storage medium | |
| CN112559711A (en) | Synonymous text prompting method and device and electronic equipment | |
| Imai et al. | Zelig: Everyone’s statistical software | |
| CN114238553A (en) | A document duplication checking method and terminal | |
| CN119088931A (en) | Automatic question-answering method, device, electronic device and storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |