Code generation method and device based on large language model, equipment and storage medium
By using a software development guidance model based on a large language model, software function decomposition diagrams and interface function call code are generated, solving the problems of low efficiency in traditional software development and poor flexibility of automation tools, and achieving efficient and accurate code generation and rapid response to personalized needs.
Patent Information
- Application Number
- CN202510952679.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-12-12
AI Technical Summary
Traditional software development relies on manual coding, which is inefficient, has high barriers to entry, and takes a long time. It is difficult to respond quickly to changes in software requirements. Existing automated code generation tools are inflexible, require high technical skills from developers, and produce inconsistent code quality.
A software development guidance model based on a large language model is adopted to generate a functional decomposition diagram of the target software. By reasoning about the target sub-modules and interface function call code, the modularization and automation of complex software development tasks are realized.
Reduce manual coding workload, improve development efficiency, increase the accuracy and adaptability of generated code, lower the development threshold, and support rapid response to personalized needs.
Smart Images

Figure CN121116433A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer and artificial intelligence technology, and in particular to a code generation method, apparatus, device and storage medium based on a large language model. Background Technology
[0002] With the rapid development of Internet technology (IT), software is increasingly widely used in various fields, and its complexity and functional requirements are constantly rising. Developers spend a significant amount of time and energy writing code during the software development process. Therefore, how to automate code generation has become one of the research hotspots in this field.
[0003] Traditional software development heavily relies on manual coding by developers, a method with numerous limitations. First, manual coding is inefficient, requiring developers to spend a significant amount of time writing repetitive code, such as defining common data structures, database operations, and user interface layouts. These repetitive tasks not only drain developers' energy but are also prone to human error, leading to a decline in software quality. Second, traditional development models demand extremely high technical skills from developers, requiring proficiency in multiple programming languages, development frameworks, and complex system architectures. This creates a high barrier to entry, making it difficult for non-specialists to participate and limiting the talent pool and innovation potential in software development. Furthermore, with rapidly changing software requirements, traditional development models struggle to respond quickly, resulting in long development cycles and slow iteration speeds, failing to meet the modern market's demands for rapid software delivery and flexible adjustments. Summary of the Invention
[0004] The main objective of this invention is to provide a code generation method, apparatus, device, and storage medium based on a large language model, aiming to solve the technical problems of low efficiency, high threshold, and long cycle of manual coding in existing technologies.
[0005] The first aspect of this invention provides a code generation method based on a large language model, the code generation method based on a large language model comprising: In response to a code generation request, a software development guidance model is used to generate a target software function decomposition diagram of the target source code. The code generation request carries the target requirements to be implemented, and the target software function decomposition diagram is used to indicate the hierarchical paths between submodules in the target source code. The hierarchical paths include the calling methods between interface functions in the previous submodule and interface functions in the next submodule of two submodules with a calling relationship. The software development guidance model is built based on a large language model. Using a software development guidance model, target sub-modules for achieving target requirements are inferred from the target software function decomposition diagram, and interface function call code for achieving the target requirements is generated.
[0006] The present invention also provides a code generation device based on a large language model, the code generation device based on a large language model comprising: The first generation module is used to generate a target software function decomposition diagram of the target source code in response to a code generation request using a software development guidance model. The code generation request carries the target requirements to be implemented, and the target software function decomposition diagram is used to indicate the hierarchical paths between sub-modules in the target source code. The hierarchical paths include the calling methods between interface functions in the previous sub-module and interface functions in the next sub-module of two sub-modules with a calling relationship. The software development guidance model is built based on a large language model. The reasoning module is used to infer the target sub-modules for achieving the target requirements from the target software function decomposition diagram using the software development guidance model, and generate interface function call code for achieving the target requirements.
[0007] The present invention also provides a computer device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor invokes the instructions in the memory to cause the computer device to execute the above-described code generation method based on a large language model.
[0008] The present invention also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the above-described code generation method based on a large language model.
[0009] This invention provides a code generation method based on a large language model. It utilizes a software development guidance model to functionally decompose the target source code, obtaining a software function decomposition diagram. Then, based on this diagram and target requirements, the software development guidance model infers target sub-modules to implement those requirements, thereby generating interface function call code. This application decomposes complex software development tasks into modular sub-tasks. Leveraging the reasoning capabilities of a large language model, it infers the code to achieve the target requirements, eliminating the need for manual coding. This method is suitable for anyone to customize code, has a low barrier to entry, and a short development cycle, reducing the workload of manual coding. Furthermore, the software development guidance model can quickly infer the hierarchical paths of sub-modules, improving development efficiency and making code generation more systematic and efficient. Attached Figure Description
[0010] Figure 1This is a schematic flowchart of the first embodiment of the code generation method based on a large language model in this invention. Figure 2 This is a schematic diagram of the functional modules of an embodiment of the code generation device based on a large language model according to the present invention; Figure 3 This is a schematic diagram of one embodiment of the computer device in this invention. Detailed Implementation
[0011] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" or "having" and any variations thereof are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0012] In recent years, automated code generation technology has gradually emerged, attempting to alleviate the pain points of traditional development models. However, existing automated code generation technologies still have significant shortcomings. First, most existing code generation tools are based on fixed templates and rules, lacking flexibility and adaptability. These tools can typically only generate simple, single-function code snippets, making it difficult to handle complex business logic and diverse requirements. For example, when software requirements change, these tools often cannot quickly adjust the generated code, requiring developers to manually modify a large amount of code, which is not only time-consuming but also prone to introducing new errors. Second, existing automated code generation tools have not significantly reduced the technical requirements and reliance on developers. They mostly require developers to have a high level of technical expertise to configure and maintain the generation tools, and in some cases, developers even need to perform extensive secondary development on the generated code, which to some extent weakens the advantages of automated code generation technology. In addition, the quality of code generated by existing tools varies greatly, lacking standardization and readability, making it difficult to meet the requirements of high-quality software development.
[0013] Based on this, this application provides a code generation and related solutions based on a large language model.
[0014] refer to Figure 1 This application provides a code generation method based on a large language model, which includes: S100: Utilizing a software development guidance model in response to a code generation request, a target software function decomposition diagram of the target source code is generated. The code generation request carries the target requirements to be implemented, and the target software function decomposition diagram is used to indicate the hierarchical paths between submodules in the target source code. The hierarchical paths include the calling methods between interface functions in the previous submodule and interface functions in the next submodule of two submodules with a calling relationship. The software development guidance model is constructed based on a large language model.
[0015] Specifically, the code generation method based on a large language model of this application can be applied to computer devices or smart terminals, and can be applied to software development scenarios, such as software development for smart terminals, and / or self-updating, self-iteratio, and self-optimization of software code in smart terminals, etc., which this application does not limit. Furthermore, large language models are deployed in computer devices and smart terminals.
[0016] A code generation request, or code generation instruction, can be generated by a smart terminal or computer device based on user instructions or user operations. For example, a user issues a code generation instruction or code generation request through a computer device or smart terminal to achieve a certain target requirement (or target task). In response to the code generation request, the computer device or smart terminal uses its deployed large language model to implement the code generation function.
[0017] The target source code may include functional code from a smart terminal (or terminal device) or application software. It contains sub-modules (functional modules) that implement various functions. These sub-modules contain interface functions, and they communicate with each other to implement the various functions of the smart terminal or application software. Existing sub-modules in the target source code can be recombined and called by a large language model to implement new functions or requirements.
[0018] For example, a smart terminal can be any artificial intelligence terminal, not limited to humanoid robots, quadruped robots, smart drones, or railway inspection robots. The various functions of a smart terminal are implemented by multiple sub-modules, and each sub-module is a code block.
[0019] In this embodiment, the computer device or smart terminal utilizes a software development guidance model to respond to a code generation request for achieving user target requirements. It performs software functional decomposition on the target source code of the smart terminal or application software, generating a target software functional decomposition diagram (i.e., a call stack diagram) of the target source code. The code generation request carries the user target requirements (or user target tasks) to be implemented. The target software functional decomposition diagram indicates the hierarchical paths between various sub-modules in the target source code. These hierarchical paths include the calling patterns between interface functions in the preceding and following sub-modules that have a calling relationship. In other words, the target software functional decomposition diagram is a call stack diagram generated with each sub-module as a level, using the calling patterns between interface functions in the preceding and following sub-modules as the hierarchical paths between the two sub-modules.
[0020] The software development guidance model is built on a large language model, and the sub-modules contain interface functions.
[0021] S200: Using the software development guidance model, deduce the target sub-modules for achieving the target requirements from the target software function decomposition diagram, and generate interface function call code for achieving the target requirements.
[0022] Specifically, using a software development guidance model based on the user's target requirements and the target software function decomposition diagram, the target sub-modules needed to achieve the user's target requirements are inferred from the target software function decomposition diagram. The target sub-modules are then combined and called according to the calling method between the obtained target sub-modules to generate interface function call code for achieving the user's target requirements.
[0023] When the solution of this application is applied to a smart terminal, the user can input or issue a request via voice. The smart terminal integrates a software development guidance model, which can generate new code to meet the user's requirements, thereby achieving self-optimization and self-updating of the code, as well as self-optimization and addition of functions to the smart terminal.
[0024] Taking intelligent drones as an example, intelligent drones can carry heavy supplies and fly, thus possessing the functions of logistics transportation and precision spraying; equipped with cameras, drones can also collect forest videos or images, enabling functions such as wildfire monitoring. By configuring a large language model within the intelligent drone, the solution in this application enables the large language model to function as a software development guidance model, allowing users to customize and add functions to the intelligent drone.
[0025] Users can issue new requests to smart drones via voice or text input. For example, a new request could be for 8 hours of hovering in the air. This would allow a lighting device to be mounted on the drone, providing 8 hours of illumination for an area by the drone and the lighting device that hovers in the air for an extended period.
[0026] Through the solution in this embodiment, the software development guidance model deployed in the intelligent drone can autonomously decompose the source code of the intelligent drone according to new requirements, deduce the target sub-modules that realize the hovering function, call and combine these target sub-modules, and set or specify the hovering duration to realize the hovering function for a specific duration.
[0027] For example, if the new requirement is railway fault inspection, the software development guidance model deployed in the intelligent drone can autonomously decompose the source code of the intelligent drone according to the new requirement and deduce several target sub-modules to realize the inspection function, such as: path planning module, photo taking module or video recording module, target recognition module, fault judgment module, etc.
[0028] The system includes a path planning module that enables the intelligent drone to fly within a user-specified area; a photo or video module that allows the intelligent drone to take photos or videos of the railway tracks within a specified area; a target recognition module that enables the intelligent drone to identify railway gaps based on the collected railway track photos or videos and obtain the size of the gaps; and a fault diagnosis module that enables the intelligent drone to determine whether the railway tracks have malfunctioned due to thermal expansion and contraction based on the size of the gaps.
[0029] Of course, the solution proposed in this application can also be used to develop or expand other functions of intelligent drones. By autonomously generating new function codes, intelligent drones can complete other specified tasks. This application does not impose any restrictions on this.
[0030] Taking a quadruped robot as an example, when a request to retrieve a frisbee is sent to the quadruped robot, the software development guidance model deployed in the quadruped robot can autonomously decompose its own source code according to the new requirements and deduce several target sub-modules to achieve the frisbee retrieval, such as: a photo-taking module, a target recognition module, and a path planning module.
[0031] The system includes a camera module that can take 360-degree photos or videos of the surrounding environment; a target recognition module that can identify the frisbee in the photos or videos and locate its trajectory; a path planning module that can plan a path based on the frisbee's trajectory and move to the landing location of the frisbee; a target recognition module that can take photos or videos of the surrounding environment again after retrieving the frisbee; a target recognition module that can identify the target person in the photos or videos; and a path planning module that can replan a new path based on the target person's location, move to the target person's location with the frisbee, and hand the frisbee to the target person.
[0032] Of course, the above are merely illustrative examples. The method of this application can be applied to automatic code generation in various fields. The specific deployment depends on the actual application situation, and this application does not impose any restrictions on it.
[0033] This embodiment utilizes a software development guidance model to functionally decompose the target source code, obtaining a software function decomposition diagram. Then, based on this diagram and target requirements, the software development guidance model infers the target sub-modules used to implement those requirements, thereby generating the interface function call code that fulfills them. This embodiment decomposes complex software development tasks into modular sub-tasks, and leverages the reasoning capabilities of a large language model to deduce the sub-modules that achieve the target requirements, reducing the workload of manual coding. Furthermore, the software development guidance model can quickly deduce the hierarchical paths of sub-modules, improving development efficiency and making code generation more systematic and efficient.
[0034] In one embodiment, step S100, which involves using a software development guidance model to generate a target software functional decomposition diagram of the target source code in response to a code generation request, includes: Using a sub-functional module hierarchical path library as a prompt for functional decomposition reasoning in a software development guidance model, the software development guidance model responds to code generation requests to perform functional decomposition and hierarchical path expansion on the target source code, generating a target software functional decomposition diagram of the target source code. The sub-module hierarchical path library includes existing hierarchical paths, which are used to indicate the process of a first sub-module inputting x parameters, processing them, and then returning y output parameters as the z input parameters of a second sub-module.
[0035] Specifically, the sub-functional module's skip path library stores some existing skip paths. For example, existing skip paths include historical skip paths used by users and / or existing skip paths in the knowledge base. The sub-functional module's skip path library can be presented in any form, not limited to graphics, documents, flowcharts, etc.
[0036] The sub-functional module hierarchical path library serves as a demonstration template for hierarchical paths, guiding large language models on how to functionally decompose arbitrary source code. Therefore, software development guidance models can learn, based on the sub-functional hierarchical path library, how to break down the target source code by function to obtain sub-modules, and learn the calling methods between these sub-modules.
[0037] In this embodiment, the sub-functional module cross-level path library is used as a guiding prompt for the software development guidance model to perform functional decomposition reasoning training. It guides the software development guidance model on how to perform functional decomposition and cross-level path expansion on the target source code, and generate the target software functional decomposition diagram of the target source code.
[0038] The term "level-skipping path" describes or characterizes the process in which a first submodule takes x parameters as input, processes them, and then returns y output parameters as z input parameters for a second submodule.
[0039] The second submodule can be the same submodule (the first submodule) or a different submodule than the first submodule. There can be multiple second submodules; that is, the output of the same first submodule may be the input of multiple different second submodules.
[0040] This embodiment utilizes a software development guidance model based on a sub-function hierarchical path library to learn how to decompose the target source code by function to obtain sub-modules, and learns the calling methods between these sub-modules to accurately obtain the target software function decomposition diagram of the target source code.
[0041] In one embodiment, step S200, which involves using a software development guidance model to infer target sub-modules for implementing target requirements from the target software functional decomposition diagram and generating interface function call code for implementing the target requirements, includes: Construct the first prompt word for each sub-module in the target software function decomposition diagram, wherein the first prompt word includes the first hierarchical structure of the sub-module and the target output of the target function of the sub-module, the first hierarchical structure includes the JSON description statement of the interface function contained in the sub-module, and the JSON description statement includes at least one of the following: the function description of the interface function, the interface function name, the input parameters, the output parameters, and the return value; The software development guidance model is used to identify the functions of sub-modules based on the first prompt word; The functions of the sub-modules are integrated to obtain a sub-module function table, and a function mapping table is obtained based on the sub-module function table; The software development guidance model is fine-tuned using the aforementioned function mapping table; The target sub-modules needed to achieve the target requirements are deduced using the finely tuned software development guidance model.
[0042] Specifically, the first-level structure is a simplified version of the submodule hierarchy, which contains a JSON description statement for each interface function contained in the submodule.
[0043] A submodule may contain one or more interface functions, each corresponding to a function. Therefore, a submodule may have one or more functions, each with an output (i.e., the output of the interface function). This embodiment will obtain the target output of the submodule's target function, that is, the target output of the target interface function. The target function may include one or more functions or all functions of the submodule.
[0044] The first cue word guides the software development guidance model in identifying the functionality of submodules. Based on the initial first cue word, the software development guidance model obtains the first-level structure of any submodule in the target software function decomposition diagram and the target output of the target function. This is equivalent to constructing a first cue word for each submodule traversed, thereby identifying the functionality of the submodule based on the first cue word.
[0045] The initial prompt word can be input by the user into the software development guidance model, or it can be automatically generated based on the prompt word generation rules and then fed into the software development guidance model.
[0046] The software development guidance model traverses each sub-module based on the initial first prompt word and constructs a corresponding first prompt word, thereby realizing the identification of the sub-module's function.
[0047] By integrating the functions of all identified submodules, a submodule function table containing the submodules and their functions can be obtained. The function mapping table contains this submodule function table.
[0048] The purpose of inputting the initial prompt words into the software development guidance model is to instruct the model to identify the functions of sub-modules according to the prompt words, essentially training the model's ability to identify code functions. During this process, the user can also instruct the model to output the function identification results of one or more sub-modules at any time; for example, instructing the model to output the function identification results of the 10 most recently identified or soon-to-be-identified sub-modules. The user can view the model's output function identification results to determine the accuracy of the model's identification of sub-module functions and provide timely feedback to the software development guidance. If the model's function identification results are accurate, the feedback will be positive. If the model's function identification results are inaccurate, the feedback will be negative, and will also include user-provided guidance to further correct and guide the model to perform accurate function identification.
[0049] This embodiment uses a fine-tuned software development guidance model to train a large language model to compose new code and implement new functions using user-specified code. Compared to existing technologies where large language models use commercially available code for code generation, this embodiment is more targeted, and the generated code better meets user needs.
[0050] This embodiment utilizes the self-learning capability of a large language model, providing a first prompt to guide the software development guidance model in accurately identifying the functions of sub-modules.
[0051] This embodiment leverages the powerful language understanding and generation capabilities of a large language model, and incorporates domain-specific knowledge for fine-tuning, enabling the generated code to better adapt to complex user tasks and dynamic inter-module call relationships. The construction and fine-tuning process of the function mapping table further optimizes the accuracy of code generation.
[0052] In one embodiment, step S200, which involves using a software development guidance model to infer target sub-modules for implementing target requirements from the target software functional decomposition diagram and generating interface function call code for implementing the target requirements, further includes: Construct a second prompt word for each interface function in the target software function decomposition diagram, wherein the second prompt word includes the first hierarchical structure of the submodule in which the interface function is located, the hierarchical path that needs to be traversed from the initial submodule to the submodule in which the interface function is located, the functional description of the interface function, and the output of the corresponding function of the interface function; The software development guidance model is used to identify the functionality of the interface functions contained in the submodule based on the second prompt word; The functions of the interface functions contained in the submodule are integrated to obtain an interface function function table, wherein the function mapping table also includes the interface function function table.
[0053] Specifically, the function mapping table also includes a submodule function table and an interface function table.
[0054] The initial submodule is the first submodule on the hierarchical path traversed by the submodule reaching the interface function in the target software functional decomposition diagram. For example, in the hierarchical path ABCD, the initial submodule is A, where the output of A serves as the input of B, the output of B serves as the input of C, and the output of C serves as the input of D; in the hierarchical path EFCG, the initial submodule is E, where the output of E serves as the input of F, the output of F serves as the input of C, and the output of C serves as the input of G.
[0055] The second cue word guides the software development guidance model on how to identify the functionality of submodules. Based on the initial second cue word, the software development guidance model obtains the first-level structure of the submodule containing any interface function in the target software functional decomposition diagram, the hierarchical path required to reach the submodule containing the interface function from the initial submodule, the functional description of the interface function, and the output of the interface function. This is equivalent to constructing a second cue word for each interface function traversed, thereby identifying the functionality of the interface function based on the second cue word.
[0056] The initial second prompt word can be input by the user into the software development guidance model, or it can be automatically generated based on the second prompt word generation rules and then fed into the software development guidance model.
[0057] The software development guidance model iterates through each interface function based on the initial second prompt word and constructs a corresponding second prompt word, thereby realizing the recognition of the interface function's functionality.
[0058] By integrating the functions of all identified interface functions, a function table containing the interface functions and their functionalities can be obtained. The function mapping table contains this function table.
[0059] The purpose of inputting the initial second prompt word into the software development guidance model is to instruct the model to identify the functionality of interface functions according to the clues provided by the second prompt word. This essentially trains the software development guidance model's ability to identify interface function functions. During this process, the user can also instruct the software development guidance model to output the functionality identification results of one or more interface functions at any time. For example, the user can instruct the model to output the functionality identification results of the 10 most recently identified or soon-to-be-identified interface functions. The user can view the functionality identification results output by the model to determine whether the software development guidance model's identification of interface function functions is accurate and provide timely feedback to the software development guidance. If the functionality identification result of the software development guidance model is accurate, the feedback result is also positive. If the functionality identification result of the software development guidance model is inaccurate, the feedback result is negative and also includes user-provided guidance descriptions to further correct and guide the model to perform accurate functionality identification.
[0060] The function mapping table in this embodiment includes the mapping relationship between each sub-module (sub-functional module) and its function description, and each interface function contained in the sub-module and its function description.
[0061] The process of using a fine-tuned software development guidance model to deduce the target sub-modules needed to achieve user goals includes: Using the finely tuned software development guidance model, based on the functions of the sub-modules and the functions of the interface functions contained in the sub-modules, the target sub-modules required to achieve the user's target requirements are deduced.
[0062] That is, the software development guidance model is used to deduce and reason about the hierarchical path of the target sub-modules to be used to achieve the user's target requirements based on the user's target requirements.
[0063] This embodiment utilizes the self-learning capability of the large language model, and provides a second prompt to guide the software development guidance model to accurately identify the functionality of interface functions.
[0064] In one embodiment, fine-tuning the software development guidance model using the function mapping table includes: A third prompt word is generated, wherein the third prompt word includes the target requirement, the calling method between the interface functions of the previous submodule and the current submodule with a calling relationship in the target software function decomposition diagram, and a first output instruction. The first output instruction is used to indicate that if the target requirement can be achieved according to the running result of the previous submodule, the model output is empty; if the target requirement cannot be achieved according to the running result of the previous submodule, the model output is the inferred historical skip path corresponding to the previous submodule. The running result of the previous submodule is the result obtained by the software development guidance model from the submodules included in the historical skip path of the previous submodule. The third prompt word is input into the software development guidance model, so that the software development guidance model, based on the third prompt word and the function mapping table, traverses the sub-modules in the target software function decomposition diagram, takes the traversed sub-modules related to the target requirements as the current sub-module, obtains the calling method between the current sub-module and the previous sub-module with a calling relationship, regenerates the third prompt word, and obtains the model output corresponding to the current sub-module based on the new third prompt word, until the model output is empty.
[0065] Specifically, the third prompt word is used to guide the software development guidance model on how to deduce the target sub-modules used to achieve the target requirements by traversing and reasoning based on the calling relationships between interface functions in the target software function decomposition diagram, the functions of sub-modules in the function mapping table, and the functions of interface functions.
[0066] The software development guidance model, based on the initial third cue word, identifies a submodule from the target software functional decomposition diagram that has a calling relationship with the previous submodule and is relevant to the target requirement as the current submodule. It then obtains the calling method between the two, as well as the calling path including the previous submodule or the historical skipping path that the submodule should execute (including all inferred target submodules from the initial submodule to the previous submodule and the calling relationships or calling methods between target submodules). Based on the historical skipping path of the previous submodule and the calling method between the previous and current submodules, the software development guidance model derives and executes the skipping path that the current submodule should execute, obtaining the corresponding execution result. If the execution result of the current submodule cannot achieve the target requirement, the model outputs the historical skipping path of the current submodule, which includes the calling methods or skipping paths between all submodules related to the target requirement from the initial submodule to the current submodule. The software development guidance model re-acquires the next submodule of the current submodule that is related to the target requirement as the current submodule, then obtains the calling method and historical skip path of the two, generates a new third prompt word, runs the new skip path (including all target submodules from the initial submodule to the new current submodule and the calling relationship or calling method between the target submodules), obtains the running result, and so on.
[0067] If the current submodule's execution result meets the target requirement, then the current submodule is the terminating submodule. If the current submodule's execution result does not meet the target requirement, then it is necessary to deduce the next submodule as the current submodule.
[0068] It should be noted that all submodules from the initial submodule to the current submodule are derived from the software development guidance model and are related to the target requirements. In the derivation process, the software development guidance model starts from the initial submodule and gradually derives the next optimal submodule related to the target requirements, then derives the next optimal submodule from the next optimal submodule, and so on, until the derived submodule can achieve the target requirements.
[0069] The initial submodule can be a target submodule related to the target requirements, inferred by the software development guidance model based on the target requirements, the function mapping table, and the target software function decomposition diagram. Starting from the initial submodule, the software development guidance model proceeds to infer subsequent target submodules step by step, forward or backward, by autonomously constructing a third cue word.
[0070] It should be noted that the previous submodule is inferred before the current submodule, and their calling relationship can be either caller or called; the next submodule is inferred after the current submodule, and their calling relationship can also be either caller or called. That is, the inference of the target submodule in this application is not limited to whether it is derived from the calling direction or the called direction.
[0071] The initial third prompt can be input by the user into the software development guidance model, or it can be automatically generated based on the third prompt generation rules and then fed into the software development guidance model.
[0072] The software development guidance model traverses sub-modules based on the initial third clue word and constructs corresponding new third clue words, thereby realizing the deduction and search of the target sub-module.
[0073] The purpose of inputting the initial third prompt word into the software development guidance model is to instruct the model to reason about the target sub-modules according to the logic of the third prompt word. This is essentially training the software development guidance model's ability to infer the target sub-modules needed to achieve the target requirements from among numerous sub-modules. During this process, the user can also instruct the software development guidance model to output one or more intermediate results at any time; for example, instructing the model to output all recently inferred target sub-modules. The user can review all the target sub-modules inferred by the model to determine whether they are relevant to the target requirements and whether they are reasonable, and provide timely feedback to the software development guidance. If all the target sub-modules inferred by the software development guidance model are relevant to the target requirements, the feedback result is positive. If some target sub-modules inferred by the software development guidance model are completely irrelevant to the target requirements, the feedback result is negative, and it also includes user-provided guidance to further correct and guide the model to accurately infer the target sub-modules based on the target requirements.
[0074] The software development guidance model in this embodiment can determine how to traverse sub-modules based on user target requirements, function mapping table, and third prompt words. Not every sub-module will be selected during traversal; instead, the most suitable target sub-module is selected based on actual target requirements.
[0075] This embodiment leverages the powerful reasoning capabilities of large language models to train and fine-tune the reasoning ability of the software development guidance model in a specific domain based on target requirements and prompt words, accurately inferring target sub-modules related to target requirements.
[0076] This embodiment integrates domain-specific knowledge into the software development guidance model by fine-tuning the large language model, enabling the developed software to better meet the actual needs of a specific domain. The construction of the function mapping table further strengthens the application of domain knowledge.
[0077] Traditional modular development combined with manual code generation: Although it can achieve modular software development, it is less efficient, difficult to incorporate domain-specific knowledge, and cannot achieve automated code generation.
[0078] Existing rule-based code generation systems generate code through predefined rules, but this method is inflexible and difficult to adapt to complex user tasks and dynamic module call relationships.
[0079] Other AI-assisted development tools include machine learning-based code recommendation systems, but these tools typically cannot perform in-depth fine-tuning with domain-specific knowledge like this invention, and the accuracy and adaptability of the generated code may not be as good as this invention.
[0080] In one embodiment, the step of reasoning out the target sub-modules needed to achieve the target requirements using a fine-tuned software development guidance model includes: A fourth prompt word is generated, which includes the target requirement, the current submodule and its historical skip path, and a second output instruction. The second output instruction is used to output an empty model if the running result of the current submodule can achieve the target requirement, and to output the historical skip path of the current submodule if the running result of the current submodule cannot achieve the target requirement. The running result of the current submodule is the result obtained by the software development guidance model running the submodules included in the historical skip path of the current submodule. Using the software development guidance model based on the fourth prompt word, when the model output is empty, interface function call code that achieves the target requirements is generated, wherein the interface function call code contains the required target sub-module.
[0081] Specifically, the fourth prompt word guides the software development guidance model on how to obtain the interface function call code based on the target requirements, the current submodule and its historical hierarchical path, and the second output instruction. The historical hierarchical path of the current submodule includes all inferred target submodules from the initial submodule to the current submodule, as well as the call relationships between these target submodules.
[0082] During the fine-tuning of the software development guidance model, if running the historical skip path corresponding to the current submodule can achieve the target requirement, then the current submodule is the final module. If the second output instruction indicates that the model output is empty, it means that the target requirement can be achieved based on the target submodules that have been traversed and inferred. The software development guidance model calls and combines all the target submodules inferred from the initial submodule to the current submodule to obtain the interface function call code that achieves the target requirement.
[0083] Of course, if running the historical skip path corresponding to the current submodule cannot achieve the target requirement, the model output will be the historical skip path corresponding to the current submodule. At this time, the software development guidance model knows that the current submodule is not the terminal module, so the interface function call code to achieve the target requirement cannot be obtained at present.
[0084] This embodiment leverages the powerful reasoning capabilities of a large language model. During the model fine-tuning process, software development guides the model output. When the current model output is empty, the current submodule is determined to be the terminating module. Then, based on all target submodules from the initial submodule to the current submodule, the interface function call code that achieves the target requirements is obtained.
[0085] In one embodiment, the method further includes: The software development guidance model is provided for users to interact with smart terminals.
[0086] Specifically, the smart terminal is equipped with a human-computer interaction interface and a software development guidance model. Users can input commands or prompts, etc., through the human-computer interaction interface via voice or text input to the software development guidance model, thereby realizing interaction between the two.
[0087] In one embodiment, this application also provides a code generation device based on a large language model, characterized in that the code generation device based on a large language model includes: The first generation module 100 is used to generate a target software function decomposition diagram of the target source code in response to a code generation request using a software development guidance model. The code generation request carries the target requirements to be implemented, and the target software function decomposition diagram is used to indicate the hierarchical paths between sub-modules in the target source code. The hierarchical paths include the calling methods between interface functions in the previous sub-module and interface functions in the next sub-module of two sub-modules with a calling relationship. The software development guidance model is constructed based on a large language model. The reasoning module 200 is used to infer the target sub-modules for achieving the target requirements from the target software function decomposition diagram using the software development guidance model, and generate interface function call code for achieving the target requirements.
[0088] For details on the functionality of the code generation device based on the large language model, please refer to the description of the code generation method based on the large language model above, which will not be repeated here.
[0089] The present invention has the following advantages over existing technical solutions: (1) Improve software development efficiency By generating software function decomposition diagrams and function mapping tables, complex software development tasks are broken down into modular subtasks. A large language model is then used to automatically generate interface function call code, reducing the workload of manual coding. Simultaneously, the software development guidance model can quickly guide submodules through hierarchical paths, further improving development efficiency.
[0090] Structural or process improvements: The introduction of software function decomposition diagrams and function mapping tables has modularized and structured the software development process, making code generation more systematic and efficient.
[0091] (2) Improve the accuracy and adaptability of code generation Leveraging the powerful language understanding and generation capabilities of large language models, and fine-tuning them with domain-specific knowledge, the generated code can better adapt to complex user tasks and dynamic inter-module call relationships. The construction and fine-tuning process of the function mapping table further optimizes the accuracy of code generation.
[0092] Structural or process improvements: By constructing first, second, and third prompt words, richer contextual information is provided to the large language model, enabling it to generate code that better meets actual needs.
[0093] (3) Enhance the interactivity between users and the development process Interactive components allow users to directly interact with the software development guidance model, providing real-time feedback and making the development process more aligned with user expectations. Furthermore, the interface function call code generated based on the target user's task better meets their personalized needs.
[0094] Structural or process improvements: Interactive components were added, enabling real-time interaction between users and the development model, allowing users to participate in all aspects of software development.
[0095] (4) Incorporating domain-specific knowledge By fine-tuning the large language model and integrating domain-specific knowledge into the software development guidance model, the developed software can better meet the actual needs of specific domains. The construction of a function mapping table and a sample library further enhances the application of domain knowledge.
[0096] Structural or process improvements: Fine-tune the large language model using a function mapping table and a sample library to enable the model to better understand and generate domain-specific code.
[0097] Replaceable or non-essential structures or processes: Submodule bypass path library: While it helps generate more accurate software function decomposition diagrams, in some simple scenarios, development can be carried out directly based on the software function decomposition diagram without relying on the bypass path library.
[0098] Complex construction of third and fourth prompt words: In some cases, the construction process of prompt words can be simplified to directly generate interface function call code, but this may sacrifice some accuracy and adaptability.
[0099] Interactive components: While enhancing the interactivity between users and the development process, in some highly automated development scenarios, interactive components can be omitted and code can be generated directly.
[0100] This application visualizes modular and dynamic calling relationships: In the prior art, the decomposition of software functions is usually relatively static. This invention identifies cross-level paths and dynamically displays the calling relationships between modules, which is more in line with actual development needs.
[0101] Domain knowledge integration: Existing technologies often lack guidance from domain-specific knowledge during code generation. This invention deeply integrates domain knowledge into a large language model through a function mapping table and fine-tuning mechanism, which significantly improves the accuracy and adaptability of the generated code.
[0102] Enhanced user interactivity: Most existing development tools lack real-time user feedback mechanisms. This invention, through interactive components, allows users to directly participate in the development process, adjust requirements in real time, and improve development flexibility and user experience.
[0103] Figure 3 This is a schematic diagram of the structure of a computer device 7000 provided in an embodiment of the present invention. The computer device 7000 can vary significantly due to different configurations or performance characteristics. It may include one or more central processing units (CPUs) 710 (e.g., one or more processors) and a memory 720, and one or more storage media 730 (e.g., one or more mass storage devices) for storing application programs 733 or data 732. The memory 720 and storage media 730 may be temporary or persistent storage. The program stored in the storage media 730 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the computer device 7000. Furthermore, the processor 710 may be configured to communicate with the storage media 730 and execute the series of instruction operations in the storage media 730 on the computer device 7000.
[0104] The computer device 7000 may also include one or more power supplies 740, one or more wired or wireless network interfaces 750, one or more input / output interfaces 760, and / or one or more operating systems 731, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 3 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0105] The present invention also provides a computer device, the computer device including a memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor performs the steps of the code generation method based on the large language model described in the above embodiments. The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the computer performs the steps of the code generation method based on the large language model.
[0106] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0107] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0108] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A code generation method based on a large language model, characterized in that, The code generation method based on a large language model includes: In response to a code generation request, a software development guidance model is used to generate a target software function decomposition diagram of the target source code. The code generation request carries the target requirements to be implemented, and the target software function decomposition diagram is used to indicate the hierarchical paths between submodules in the target source code. The hierarchical paths include the calling methods between interface functions in the previous submodule and interface functions in the next submodule of two submodules with a calling relationship. The software development guidance model is built based on a large language model. Using a software development guidance model, target sub-modules for achieving target requirements are inferred from the target software function decomposition diagram, and interface function call code for achieving the target requirements is generated.
2. The code generation method based on a large language model according to claim 1, characterized in that, The process of using a software development guidance model to generate a target software functional decomposition diagram of the target source code in response to a code generation request includes: Using a sub-functional module hierarchical path library as a prompt for functional decomposition reasoning in a software development guidance model, the software development guidance model responds to code generation requests to perform functional decomposition and hierarchical path expansion on the target source code, generating a target software functional decomposition diagram of the target source code. The sub-module hierarchical path library includes existing hierarchical paths, which are used to indicate the process of a first sub-module inputting x parameters, processing them, and then returning y output parameters as the z input parameters of a second sub-module.
3. The code generation method based on a large language model according to claim 1, characterized in that, The step of using a software development guidance model to deduce target sub-modules for implementing target requirements from the target software functional decomposition diagram, and generating interface function call code for implementing the target requirements, includes: Construct the first prompt word for each sub-module in the target software function decomposition diagram, wherein the first prompt word includes the first hierarchical structure of the sub-module and the target output of the target function of the sub-module, the first hierarchical structure includes the JSON description statement of the interface function contained in the sub-module, and the JSON description statement includes at least one of the following: the function description of the interface function, the interface function name, the input parameters, the output parameters, and the return value; The software development guidance model is used to identify the functions of sub-modules based on the first prompt word; The functions of the sub-modules are integrated to obtain a sub-module function table, and a function mapping table is obtained based on the sub-module function table; The software development guidance model is fine-tuned using the aforementioned function mapping table; The target sub-modules needed to achieve the target requirements are deduced using the finely tuned software development guidance model.
4. The code generation method based on a large language model according to claim 3, characterized in that, The step of using a software development guidance model to infer target sub-modules for implementing target requirements from the target software functional decomposition diagram, and generating interface function call code for implementing the target requirements, further includes: Construct a second prompt word for each interface function in the target software function decomposition diagram, wherein the second prompt word includes the first hierarchical structure of the submodule in which the interface function is located, the hierarchical path that needs to be traversed from the initial submodule to the submodule in which the interface function is located, the functional description of the interface function, and the output of the corresponding function of the interface function; The software development guidance model is used to identify the functionality of the interface functions contained in the submodule based on the second prompt word; The functions of the interface functions contained in the submodule are integrated to obtain an interface function function table, wherein the function mapping table also includes the interface function function table.
5. The code generation method based on a large language model according to claim 3 or 4, characterized in that, The fine-tuning of the software development guidance model using the function mapping table includes: A third prompt word is generated, wherein the third prompt word includes the target requirement, the calling method between the interface functions of the previous submodule and the current submodule with a calling relationship in the target software function decomposition diagram, and a first output instruction. The first output instruction is used to indicate that if the target requirement can be achieved according to the running result of the previous submodule, the model output is empty; if the target requirement cannot be achieved according to the running result of the previous submodule, the model output is the inferred historical skip path corresponding to the previous submodule. The running result of the previous submodule is the result obtained by the software development guidance model from the submodules included in the historical skip path of the previous submodule. The third prompt word is input into the software development guidance model, so that the software development guidance model, based on the third prompt word and the function mapping table, traverses the sub-modules in the target software function decomposition diagram, takes the traversed sub-modules related to the target requirements as the current sub-module, obtains the calling method between the current sub-module and the previous sub-module with a calling relationship, regenerates the third prompt word, and obtains the model output corresponding to the current sub-module based on the new third prompt word, until the model output is empty.
6. The code generation method based on a large language model according to claim 5, characterized in that, The process of using a fine-tuned software development guidance model to deduce the target sub-modules needed to achieve the target requirements includes: A fourth prompt word is generated, which includes the target requirement, the current submodule and its historical skip path, and a second output instruction. The second output instruction is used to output an empty model if the running result of the current submodule can achieve the target requirement, and to output the historical skip path of the current submodule if the running result of the current submodule cannot achieve the target requirement. The running result of the current submodule is the result obtained by the software development guidance model running the submodules included in the historical skip path of the current submodule. Using the software development guidance model based on the fourth prompt word, when the model output is empty, interface function call code that achieves the target requirements is generated, wherein the interface function call code contains the required target sub-module.
7. The code generation method based on a large language model according to claim 1 or 2, characterized in that, The method further includes: The software development guidance model is provided for users to interact with smart terminals.
8. A code generation device based on a large language model, characterized in that, The code generation device based on the large language model includes: The first generation module is used to generate a target software function decomposition diagram of the target source code in response to a code generation request using a software development guidance model. The code generation request carries the target requirements to be implemented, and the target software function decomposition diagram is used to indicate the hierarchical paths between sub-modules in the target source code. The hierarchical paths include the calling methods between interface functions in the previous sub-module and interface functions in the next sub-module of two sub-modules with a calling relationship. The software development guidance model is built based on a large language model. The reasoning module is used to infer the target sub-modules for achieving the target requirements from the target software function decomposition diagram using the software development guidance model, and generate interface function call code for achieving the target requirements.
9. A computer device, characterized in that, The computer device includes: a memory and at least one processor, wherein the memory stores instructions; The at least one processor invokes the instructions in the memory to cause the computer device to execute the code generation method based on a large language model as described in any one of claims 1-7.
10. A computer-readable storage medium storing instructions thereon, characterized in that, When the instructions are executed by the processor, they implement the code generation method based on a large language model as described in any one of claims 1-7.
