Code generation method and device based on natural language and medium

By obtaining the functional requirements information described by the user in the natural language and generating code modules in combination with the target system feature information, the problem of low development efficiency of new functional requirements in the existing technology is solved, and the development efficiency and user experience are improved.

CN120469666AActive Publication Date: 2025-08-12JINAN YUSHI INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202510933530.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-08
Publication Date
2025-08-12
Estimated Expiration
2045-07-08

AI Technical Summary

Technical Problem

In the prior art, users have low efficiency in developing new functions of target systems in the scene, resulting in poor user experience.

Method used

By obtaining the functional requirements information described by the user's natural language, combining the feature information of the target system to generate prompt words, and using a large language model to generate code modules that execute function requirements, which are integrated into the target system.

Benefits of technology

It realizes the generation of code modules through natural language in the scene, improves the processing efficiency of user functional requirements, and improves the development efficiency and user experience of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120469666A_ABST
    Figure CN120469666A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method and device based on a natural language and a medium. The method comprises the following steps: obtaining candidate functions provided by a user based on a target system, and determining function demand information described by a natural language; determining target information from the feature information according to the function demand information; wherein the feature information is determined in advance according to candidate functions; and generating a cue word according to the function demand information and the target information, inputting the cue word into the large language model to generate a code module for executing the function demand information, and integrating the code module into the target system. According to the method, the feature metadata corresponding to the candidate functions of the target system is combined with the natural language information of the user to guide and generate the code module for executing the user-defined function requirements, so that the user is allowed to generate the code module which can be integrated into the target system through the natural language on the scene site; and the processing efficiency of the user function requirements is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a natural language-based code generation method, device and medium. Background Art

[0002] With the development of computer applications, a unified system will be used for management in different business scenarios. For example, a management system will be used to uniformly manage all projects and personnel on a construction site.

[0003] However, as business evolves, users often have new functional requirements for systems already deployed on-site. Conventional technology requires manufacturers to perform secondary development on the target system, then redeploy the new target system to the site. This inefficient new feature development approach results in a poor user experience with the target system. Summary of the Invention

[0004] The present invention provides a natural language-based code generation method, device and medium to solve the problem of low development efficiency of new functional requirements generated by systems deployed on-site.

[0005] According to one aspect of the present invention, a natural language-based code generation method is provided, comprising:

[0006] Obtain the functional requirement information described in natural language determined by the user based on the candidate functions provided by the target system;

[0007] Determining target information from feature information according to the functional requirement information; wherein the feature information is determined in advance according to the candidate function;

[0008] Prompt words are generated according to the functional requirement information and the target information, and the prompt words are input into a large language model to generate a code module for executing the functional requirement information, and the code module is integrated into the target system.

[0009] According to another aspect of the present invention, there is provided a natural language-based code generation apparatus, comprising:

[0010] The user function requirement acquisition module is used to obtain the function requirement information described in natural language determined by the user based on the candidate functions provided by the target system;

[0011] a target information determination module, configured to determine target information from feature information according to the functional requirement information; wherein the feature information is determined in advance according to the candidate functions;

[0012] A code module generation module is used to generate prompt words according to the functional requirement information and the target information, input the prompt words into a large language model to generate a code module for executing the functional requirement information, and integrate the code module into the target system.

[0013] According to another aspect of the present invention, an electronic device is provided, comprising:

[0014] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the natural language-based code generation method described in any embodiment of the present invention.

[0015] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the natural language-based code generation method described in any embodiment of the present invention when executed.

[0016] The technical solution of this embodiment guides the generation of code modules that execute user-defined functional requirements by combining the feature metadata corresponding to the candidate functions of the target system with the user's natural language information, allowing the user to generate code modules that can be integrated into the target system through natural language on-site, thereby improving the efficiency of processing user functional requirements.

[0017] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0019] Figure 1 is a flowchart of a natural language-based code generation method provided according to an embodiment of the present invention;

[0020] Figure 2 is a flowchart of another natural language-based code generation method provided according to an embodiment of the present invention;

[0021] Figure 3is a flowchart of another natural language-based code generation method provided according to an embodiment of the present invention;

[0022] Figure 4 1 is a schematic structural diagram of a natural language-based code generation device provided according to an embodiment of the present invention;

[0023] Figure 5 The present invention is a schematic diagram of an electronic device for implementing the natural language-based code generation method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0024] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0025] It should be noted that the terms "candidate", "target", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or that are inherent to these processes, methods, products or devices.

[0026] Figure 1 The present invention provides a flowchart of a method for generating code based on natural language. This embodiment is applicable to the case of expanding user-defined functions in a target system. The method can be executed by a code generating device based on natural language. The code generating device based on natural language can be implemented in the form of hardware and / or software. The code generating device based on natural language can be configured in a server with computing capabilities. Figure 1 As shown, the method includes:

[0027] S110 : Acquire functional requirement information described in natural language determined by the user based on candidate functions provided by the target system.

[0028] Among them, the target system is a management framework for target business scenarios that support the development of user-defined functions, such as a construction site management system. Some basic functions have been integrated into the target system, and the target system supports business expansion for users to develop customized functions based on their own personalized needs. Users can develop customized functions based on the application scenarios of the target system. Candidate functions are reference functions that support user extensions determined based on the application scenarios of the target system. For example, candidate functions are reference functions that are supported by a predetermined target system for user-defined extensions. The determination of candidate functions can be determined based on feature information in the target system, including but not limited to determination based on the capabilities of the target system. Functional requirement information described in natural language refers to the user inputting the functional requirement information to be extended in the form of natural language description.

[0029] Specifically, based on the business scenarios and feature information of the target system, multiple candidate functions that can be used for expansion reference are determined. The user determines the basic reference functions that need to be expanded based on the candidate functions, expands on the basis of the basic reference functions, and describes the expanded content in natural language and inputs it into the target system. The input method can be voice or text, which is not limited here.

[0030] For example, the target system is a construction site management system, and candidate functions include helmet detection and vehicle detection. The user selects helmet detection as a base reference function and expands upon it, determining the functional requirement information as "tracking the trajectory of people wearing white helmets." Describing functional requirements using natural language can more accurately express the user's overall needs.

[0031] In a feasible embodiment, S110 includes:

[0032] Obtain the user's initial input information and determine candidate prompt information based on the candidate functions and the initial input information;

[0033] Determine the target prompt information determined by the user from the candidate prompt information, and determine the first round of input information based on the initial input information and the target prompt information;

[0034] Determine the first round of response information based on the semantic recognition result of the first round of input information;

[0035] Obtain the next round of input information determined by the user based on the first round of response information, and determine the corresponding next round of response information based on the next round of input information, until the user's input completion instruction is obtained or the round number threshold is reached, and determine the function requirement information based on the user's input information of all rounds.

[0036] The initial input information is the partial functional requirement information that the user has not entered completely. That is, when the user has not entered the complete information, candidate prompt information is determined for the user based on the partial functional requirement information and the candidate functions supported by the target system, where the candidate prompt information is the functional description information supported by the target system and that the user may expand.

[0037] The user determines the target prompt information that matches the customized needs from the candidate prompt information, and combines the initial input information and the candidate prompt information to obtain the first round of input information, where the first round of input information is part of the functional requirement information input by the user. In order to guide the user to express his or her needs more fully and completely, the first round of response information is further matched to the user's first round of input information. The first round of response information is prompt information that is further expanded based on the functional requirements in the first round of input information. The user determines the next round of input information based on the prompt of the first round of response information, where the next round of input information can also be determined based on the user's partial input information combined with the next round of target prompt information. After multiple rounds of prompts and guidance to the user, the user determines that the input is complete, or reaches the preset round number threshold, then the complete functional requirement information is determined based on the user's current input information of all rounds.

[0038] For example, when the user inputs part of the natural language, an intelligent prompt function is provided to help the user express the needs more accurately. For example, when the user inputs "detection", detection is used as the initial input information. According to the semantic recognition result of the initial input information and the matching result of the candidate function, the candidate detection objects supported by the target system are determined as candidate prompt information, such as "open fire detection" and "personnel behavior detection". A multi-round dialogue protocol is designed: when the user inputs: "alarm when open fire is detected", it is used as the first round of input information. The system determines that the content that can be expanded is the alarm method based on the keyword detection result in the first round of input information, and determines the first round of response information as: "Please confirm the alarm method: [1] Trigger sound and light alarm [2] Push SMS [3] Link fire protection system". The user further supplements and improves the function requirement information based on the first round of response information until the preset round number threshold is reached or the user triggers the input completion instruction.

[0039] This embodiment guides users to input natural language that conforms to target system resources through intelligent prompts and multi-round dialogue guidance, thereby ensuring the validity and functional integrity of the generated code.

[0040] S120: Determine target information from the feature information according to the functional requirement information.

[0041] The feature information is pre-determined based on the candidate functions. Feature information is system metadata provided by the target system, specifically data that can be directly used when expanding user-defined functions. For example, feature information includes descriptions of the candidate functions and basic target system functions. Furthermore, feature information includes basic function call information corresponding to each candidate function.

[0042] In a feasible embodiment, the feature information also includes a code template corresponding to the basic function.

[0043] Specifically, for common functions such as data acquisition, image preprocessing, HTTP alarm push, ONVIF device control, etc., a code template library is established, and template codes are used to quickly and accurately generate code modules for custom functions.

[0044] Furthermore, the feature information also includes grammatical hard constraint information, including prohibiting the use of unauthorized APIs, variable references must exist, and an upper limit on the number of loops, to ensure the security and standardization of the code.

[0045] In a feasible embodiment, the characteristic information also includes abnormal data; the abnormal data includes the abnormal type occurring during the operation of the system and the corresponding processing mechanism.

[0046] Exception types refer to common error types that occur during operation, determined based on statistics of the target system's historical operating data, such as image acquisition failure, algorithm calculation timeout, etc. Exception types can help code modules generated based on user functional requirement information have better error recognition capabilities.

[0047] The signature information also includes the corresponding handling mechanism for each exception type. This helps the generated code module to take appropriate action based on the exception type when it catches an exception, preventing any impact on the target system's main program and ensuring the stability of the target system. For example, when the system encounters a resource limit overrun, it automatically downgrades or issues an alarm. For example, when it catches an out-of-memory exception, the corresponding action is to suspend secondary functions and prioritize critical tasks.

[0048] Specifically, based on the matching information between the functional requirement information and the feature information, the successfully matched feature information is determined as the target information. Exemplarily, semantic recognition is performed on the functional requirement information to obtain keyword information. Similarity matching is performed based on the code templates and candidate function-related information in the keyword information and the feature information. The successfully matched code templates and candidate function-related information are used as the target information. The candidate function-related information includes candidate function description information and the basic function call information corresponding to the candidate function. Furthermore, since various exception types may occur during the execution of the code module, all exception data is used as the target information.

[0049] S130 , generating prompt words according to the functional requirement information and the target information, inputting the prompt words into the large language model to generate a code module for executing the functional requirement information, and integrating the code module into the target system.

[0050] Specifically, the functional requirement information and target information are filled in the preset prompt word template respectively, and the prompt word template structure is used to combine the system metadata and the user's personalized needs. The large language model outputs the code module that can execute the functional requirement information based on the context information in the prompt word.

[0051] Optionally, prompt words are generated based on functional requirement information, target information, and other constraint information.

[0052] Among them, other constraint information refers to other information that prompts constraints on the generation of code modules. Other constraint information includes role description constraint information. For example, you are an intelligent resource configuration engine whose goal is to generate high-performance code based on the following context and output rule constraint information, such as automatically executing preset parallel code block logic when CPU / GPU / memory utilization is greater than 85%.

[0053] Including other constraint information in the prompt word can improve the accuracy of prompt word generation, facilitate the large language model to further clarify task requirements, and thus improve the accuracy of code module generation.

[0054] In a feasible embodiment, after generating a code module for executing the functional requirement information, the method further includes:

[0055] The code module and the execution result of the code module are displayed through a visual interface, and user feedback information on abnormal execution results is received through the visual interface.

[0056] Furthermore, the code module is visually displayed, and the execution result of the code module is visually displayed.

[0057] Specifically, code module visualization presents the generated code module program to the user in a visual manner, allowing the user to intuitively understand the structure and logic of the code module program. For example, a flowchart can be used to illustrate the execution process of the code module. Execution result visualization presents the running results of the code module to the user in a visual manner, such as by annotating detected abnormal areas or human behavior on an image.

[0058] The visually displayed execution results include normal execution results and abnormal execution results. For abnormal execution results, users can determine the feedback information of the abnormal execution results based on the visually displayed code module, and modify the code module according to the feedback information to correct the abnormal execution results.

[0059] The generated code combines a visual interface and a functional verification mechanism to ensure the validity of the generated code. The visual interface allows users to intuitively see the execution effect of the code or related output results, making it easier for users to check and debug.

[0060] Furthermore, the code module is called by a dynamic loading function pre-configured in the target system, so that the target system embeds the functional requirement information.

[0061] Specifically, we leverage the dynamic loading mechanisms provided by programming languages, such as the importlib module in Python and the class loader in Java. Taking Python as an example, we dynamically load the code module generated by the large model at runtime through the importlib.import_module function reserved in the target system, integrating it into the existing target system's operating environment.

[0062] Furthermore, data backup and program recovery: regularly back up the target system's data, including the feature information knowledge base, user-entered functional requirements information, generated code modules, etc. When the target system fails or data is lost, the program and data can be restored in time.

[0063] The technical solution of this embodiment guides the generation of code modules that execute user-defined functional requirements by combining the feature metadata corresponding to the candidate functions of the target system with the user's natural language information, allowing the user to generate code modules that can be integrated into the target system through natural language on-site, thereby improving the efficiency of processing user functional requirements.

[0064] Figure 2 This is a flowchart of another method for generating code based on natural language provided by an embodiment of the present invention. This embodiment further refines the feature information in the above embodiment. Figure 2 As shown, the method includes:

[0065] S210: Acquire functional requirement information described in natural language determined by the user based on candidate functions provided by the target system.

[0066] S220 . Determine keyword information based on the semantic recognition result of the functional requirement information; and determine matching data from the static data based on the keyword information as target information.

[0067] Among them, the feature information includes at least static data; the static data includes at least one of the following: function call interface information, variable information, target system function information, candidate function description information and target system deployment scenario knowledge information.

[0068] Function call interface information is a dynamic index of the interface. By establishing an API management library, the input / output parameters, return values, permission levels, QPS limits, and historical call performance data (such as average latency) of different function call interfaces are recorded, and semantic tags are added to the interfaces to facilitate large models to match user needs through semantic retrieval.

[0069] Variable information is a variable dependency graph that builds a data structure. It marks the real-time nature, read and write permissions (such as alarm_status is only readable) and description information of different variables, providing comprehensive variable information for code generation.

[0070] The candidate function description information records the description information, applicable scenarios, triggering rules, etc. of different candidate function algorithms. For example, for the detection of people not wearing helmets, the characteristics of the helmets such as type, color, and shape are recorded.

[0071] The target system's functional information describes the target system's detailed functions, uses, and features, including software and hardware configuration methods and instructions. For example, the function description and configuration method for detecting people not wearing helmets.

[0072] The target system deployment scenario knowledge information is associated with the device deployment scenario knowledge, and a built-in industry specification library (such as GB / T28181 standard protocol and safe production operation manual) is used to ensure that the generated code complies with industry standards and actual scenario requirements.

[0073] Specifically, various static data in the target system are counted in advance, and a system multi-source metadata registration center is built to record all static data, abnormal data, and code templates involved in the system. When the user enters the functional requirement information, the keyword information therein is determined based on the semantic recognition result of the functional requirement information, and the keyword information is matched with the various data in the system multi-source metadata registration center, and the successfully matched ones are used as the target information. Among them, the matching method can adopt similarity matching, that is, the keyword information and the keywords in the metadata are converted into word vectors, and the cosine similarity between the word vectors is calculated as the similarity matching result between the functional requirement information and the various data in the system multi-source metadata registration center, and the similarity matching result greater than the preset similarity threshold is used as the target information; or the matching method can also adopt index matching, that is, the index relationship between multiple candidate keyword information and the various data in the system multi-source metadata registration center is pre-determined, and the metadata corresponding to the keyword information in the functional requirement information is determined based on the index relationship as the target information.

[0074] Furthermore, the candidate function description information includes user authority description information corresponding to different candidate functions, and / or the function call interface information includes user authority description information corresponding to different function call interfaces.

[0075] By implementing user permission control on candidate functions and / or function call interfaces, users with different permissions can call different candidate functions and / or function call interfaces. For example, ordinary users can only generate simple custom functions, while administrator users can perform more advanced configuration and management. Exemplarily, if the user's function requirement information carries user permission information, and the matching data determined based on the function requirement information includes a function call interface that does not match the user's permissions, the permission restriction will be fed back to the user, a failure message will be generated, and the user will be further presented with description information of the candidate functions that match their permissions.

[0076] S230 , generating prompt words according to the functional requirement information and the target information, inputting the prompt words into the large language model to generate a code module for executing the functional requirement information, and integrating the code module into the target system.

[0077] The technical solution of this embodiment uses the static data of the target system combined with the user's natural language information as the input context information of the large language model, guiding the large language model to generate a code module that executes the user's customized functional requirements, thereby improving the efficiency and quality of code module generation.

[0078] Figure 3 This is a flowchart of another method for generating code based on natural language provided by an embodiment of the present invention. This embodiment further refines the feature information in the above embodiment. Figure 3 As shown, the method includes:

[0079] S310: Acquire functional requirement information described in natural language determined by the user based on candidate functions provided by the target system.

[0080] S320 . Determine keyword information based on the semantic recognition result of the functional requirement information; and determine matching data from the static data based on the keyword information as the first target information.

[0081] Among them, the feature information includes at least static data; the static data includes at least one of the following: function call interface information, variable information, target system function information, candidate function description information and target system deployment scenario knowledge information.

[0082] S330: Use the dynamic data and dynamic resource quantification model in the feature information as second target information.

[0083] The characteristic information at least includes dynamic data and a dynamic resource quantification model; the dynamic data includes at least one of the following: current data and historical data of system resource usage parameters, execution time parameters and network monitoring parameters.

[0084] Dynamic data refers to data that changes as the program executes. It comes from the function combinations set by the user, the click events executed, the unexpected events triggered, the interaction with external APIs or services, etc. They may change frequently during the life cycle of the program, and these situations cannot be accurately predicted before the actual operation of the system, and need to be recorded during the actual operation. For example, as the target system runs, the cost of storing and retrieving process data will also increase. The processing of large amounts of data may cause disk I / O read and write bottlenecks, changes in database operation duration, and other problems. The system resource usage parameters generated are dynamic data; in a high-concurrency environment, multiple users accessing or modifying the same data resources at the same time may cause preemption and slow response speed. The dynamic data generated are execution time parameters. The quality of the network conditions in the actual field environment directly affects the speed and stability of data transmission, and thus affects the response speed of the entire application. The network bandwidth peak generated is network monitoring data, which can also be used as dynamic data.

[0085] Since the execution of a user's functional requirement generally requires a combination of multiple algorithms or multiple functional modules, and the resource consumption generated by the combination of multiple algorithms is a nonlinear superposition effect, this embodiment pre-establishes a dynamic resource quantification model, and quantifies the resource consumption results under the dynamic combination of multiple algorithms according to the model. For example, the dynamic resource quantification model is a computing power resource comparison relationship set under the dynamic combination, and the relationship set includes resource consumption results corresponding to different algorithm combinations, such as a face detection model superimposed on work clothes detection, occupying 200MB of video memory, a peak memory usage of 200MB, 50ms / CPU core per frame of image processing, and consuming 0.5TOPS of computing power; or the dynamic resource quantification model is a deep learning model trained according to real-time dynamic data and historical dynamic data corresponding to different algorithm combinations.

[0086] For example, dynamic data is recorded during the execution of programs with different algorithm combinations in the target system. Dynamic data recording generally takes the form of log files, which are suitable for recording system monitoring information, application logs, etc. This embodiment establishes a structured storage log based on algorithm function combinations, time, resource type, etc., to record resource consumption under different conditions.

[0087] During dynamic data recording, call system monitoring tools, such as top, htop, vmstat, iostat, and other commands to obtain the usage of resources such as CPU, memory, and disk I / O. Scripts are written to execute these commands regularly and the output results are recorded in log files. Monitoring code is integrated into the application to record key indicators such as function call time and database operation duration. For example, in Python, the time module is used to record the execution time of functions; the database logging function is enabled to record information such as read and write operations, transaction processing time, etc. in all database operations. For example, in MySQL, slow query logs can be enabled to record SQL statements whose execution time exceeds a certain threshold; network monitoring tools are used to capture network data packets and analyze network bandwidth, latency, and other indicators. Scripts are written to regularly run tools such as tcpdump and save the analysis results. During software operation, resource data often has periodic patterns. Recording these periodic changes helps to dynamically adjust resources when generating code. This embodiment records dynamic data in units of minutes, hours, and days.

[0088] The dynamic resource quantification model is trained based on the recorded historical dynamic data of different algorithm combinations during execution. The input of the trained dynamic resource quantification model is the algorithm combination corresponding to different functional requirements, and the output information is resource consumption prediction information.

[0089] Since the dynamic data in the feature information represents the current resource consumption information of the target system, the dynamic resource quantification model can predict the resource consumption information of the user-defined functional requirement information. Therefore, the dynamic data and the dynamic resource quantification model are related to the generation of the code module, and the dynamic data and the dynamic resource quantification model are used as the second target information.

[0090] S340: Generate prompt words according to the functional requirement information, the first target information, and the second target information.

[0091] Construct prompts in steps, integrating system roles, output rules, static data encapsulation, dynamic data injection, and functional requirements. Using a templated prompt structure, dynamic and static data are contextualized. System roles and output rules serve as additional constraints, static data serves as the primary target, and dynamic data serves as the secondary target.

[0092] Specifically, the prompt words include: system role description: You are an intelligent resource configuration engine whose goal is to generate high-performance code based on the following context; static data encapsulation: function call interface of the target system and its description, variables and their description, and other information; dynamic data: current environment indicators: {{dynamic data summary}}, current CPU core average utilization: {{dynamic_data.cpu_average}}, current CPU core peak utilization: {{dynamic_data.cpu_perk}}, historical environment indicators: {{dynamic data summary}} CPU core average utilization in the past hour: {dynamic_data.cpu_hour_average last_hour_}}, CPU core peak utilization in the past hour: {{dynamic_data.cpu_perk_last_hour_}}, etc.; user functional requirement information: "{{natural language description}}"; output rules: give priority to methods in the static API, and automatically execute preset parallel code block logic when CPU / GPU / memory utilization is >85%.

[0093] S350 : In the process of generating a code module according to the prompt word by the large language model, the predicted resource consumption information corresponding to different execution algorithms using different interfaces is determined according to the dynamic data in the prompt word and the dynamic resource quantification model.

[0094] After obtaining the prompt word, the large language model generates different candidate algorithm combinations based on the functional requirement information in the prompt word. Each candidate algorithm combination uses different execution algorithms with different interfaces. The output results corresponding to different candidate algorithm combinations are determined based on the dynamic resource quantification model to determine the predicted resource consumption information.

[0095] Since users use natural language to define functional requirements, there is uncertainty in the functional description. During the code generation process, a hardware resource consumption prediction model is established and the resource consumption quantification capability of the dynamic resource quantification model is used to predict the resource consumption corresponding to the custom function. The prediction of resource consumption is crucial to ensuring that the generated code module can be successfully executed in the target system.

[0096] S360: Determine a target interface and a target execution algorithm according to the predicted resource consumption information and the system resource constraint information, and generate a code module based on the target interface and the target execution algorithm.

[0097] The system resource constraint information is pre-set resource usage upper limit information, such as CPU usage cannot exceed 90%, memory usage cannot exceed 80%, and other upper limit information.

[0098] The system resource constraint information and the predicted resource consumption information obtained by the dynamic resource quantification model are input into the large model to guide the generation of the code module, so that the resource consumption brought by the generated code module when running in the target system meets the system resource constraint information, ensuring the safe operation of the code.

[0099] This embodiment guides the large model to predict consumed resources when generating code, so that the actual resource consumption of each node in the target system meets the resource constraints.

[0100] Optionally, new dynamic data (such as actual memory consumption deviation) generated when the code module generated by the large language model is actually executed in the sandbox environment is fed back to the input context of the large language model prompt word in real time, triggering the large language model to iteratively optimize the code module based on the new dynamic data, thereby allowing the large language model to generate more adaptable code modules.

[0101] Optionally, to make the target system more robust and ensure that the context input can guide the model to generate code modules that meet user requirements, the user's data manual update mechanism supports updates to preset conditions, such as static data, dynamic data, and other feature information.

[0102] Specifically, a user feedback interface and review process are designed to support users in submitting suggestions for correction of abnormal scenarios or new function templates (such as adaptation of specific industry protocols), forming an artificial optimization ecosystem for feature information, and solving the problem of knowledge lag caused by version iteration in the system.

[0103] The dynamic update mechanism is conducive to the continuous accumulation and optimization of knowledge. With the continuous development of software and the diversification of user needs, the feature information knowledge base is constantly enriched and improved, and can generate more complex code modules that better meet specific needs.

[0104] This embodiment uses a dual-channel knowledge base self-evolution system that combines automated collection with manual feedback to capture system runtime data in real time, and combines version control technology to achieve incremental automatic updates of the knowledge base; combining a user feedback interface with a multi-level review process, it supports users to submit correction suggestions for abnormal scenarios or new function templates, forming a closed-loop optimization of the knowledge base in feature information.

[0105] The technical solution of this embodiment uses a multi-source context-driven code module generation mechanism, based on structured system metadata dynamic fusion technology, to multi-dimensionally associate static data with dynamic data, and combine code templates with exception data to construct multi-source context prompt words; and through resource prediction, dynamically screen the optimal interface and algorithm combination to improve the adaptability of the generated code module to actual scenario requirements.

[0106] Figure 4This is a schematic diagram of the structure of a code generation device based on natural language provided by an embodiment of the present invention. Figure 4 As shown, the device includes:

[0107] The user function requirement acquisition module 410 is used to obtain the function requirement information described in natural language determined by the user based on the candidate functions provided by the target system;

[0108] a target information determination module 420, configured to determine target information from feature information according to the function requirement information; wherein the feature information is determined in advance according to the candidate functions;

[0109] The code module generation module 430 is used to generate prompt words according to the functional requirement information and the target information, input the prompt words into the large language model to generate a code module for executing the functional requirement information, and integrate the code module into the target system.

[0110] The technical solution of this embodiment guides the generation of code modules that execute user-defined functional requirements by combining the feature metadata corresponding to the candidate functions of the target system with the user's natural language information, allowing the user to generate code modules that can be integrated into the target system through natural language on-site, thereby improving the efficiency of processing user functional requirements.

[0111] Optionally, the feature information includes at least static data; the static data includes at least one of the following: function call interface information, variable information, target system function information, candidate function description information and target system deployment scenario knowledge information.

[0112] Optionally, the target information determination module is specifically used to:

[0113] Determining keyword information based on the semantic recognition result of the functional requirement information;

[0114] Matching data is determined from the static data according to the keyword information as target information.

[0115] Optionally, the characteristic information further includes at least dynamic data and a dynamic resource quantification model; the dynamic data includes at least one of the following: current data and historical data of system resource usage parameters, execution time parameters and network monitoring parameters.

[0116] Optionally, the target information includes at least the dynamic data and the dynamic resource quantification model;

[0117] The code module generation module includes a code generation unit for:

[0118] In the process of generating a code module according to the prompt word by the large language model, determining predicted resource consumption information corresponding to different execution algorithms using different interfaces according to the dynamic data in the prompt word and the dynamic resource quantification model;

[0119] A target interface and a target execution algorithm are determined according to the predicted resource consumption information and the system resource constraint information, and the code module is generated based on the target interface and the target execution algorithm.

[0120] Optionally, the feature information also includes exception data and code templates corresponding to basic functions; the exception data includes the exception type occurring during system operation and the corresponding processing mechanism.

[0121] Optionally, the device further includes a visual interaction module, which is used, after generating a code module for executing the functional requirement information, to:

[0122] The code module and the execution result of the code module are displayed through a visual interface, and user feedback information on abnormal execution results is received through the visual interface.

[0123] Optional user function requirement acquisition module, specifically used for:

[0124] Obtaining initial input information from the user, and determining candidate prompt information based on the candidate functions and the initial input information;

[0125] Determining target prompt information determined by the user from candidate prompt information, and determining first-round input information based on the initial input information and the target prompt information;

[0126] determining first-round response information according to a semantic recognition result of the first-round input information;

[0127] Obtain the next round of input information determined by the user based on the first round of response information, and determine the corresponding next round of response information based on the next round of input information, until the user's input completion instruction is obtained or the round number threshold is reached, and determine the function requirement information based on the user's input information of all rounds.

[0128] The natural language-based code generation device provided in the embodiment of the present invention can execute the natural language-based code generation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0129] The acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations and do not violate public order and good morals.

[0130] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0131] Figure 5 A schematic diagram of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.

[0132] like Figure 5 As shown, electronic device 10 includes at least one processor 11 and memory, such as read-only memory (ROM) 12 and random access memory (RAM) 13, communicatively connected to at least one processor 11. The memory stores computer programs executable by the at least one processor. Processor 11 can perform various appropriate actions and processes based on the computer programs stored in ROM 12 or loaded from storage unit 18 into RAM 13. RAM 13 can also store various programs and data required for the operation of electronic device 10. Processor 11, ROM 12, and RAM 13 are interconnected via bus 14. An input / output (I / O) interface 15 is also connected to bus 14.

[0133] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0134] Processor 11 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any other suitable processor, controller, microcontroller, etc. Processor 11 executes the various methods and processes described above, such as the method based on natural language code generation.

[0135] In some embodiments, the method for natural language-based code generation can be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the method for natural language-based code generation described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the method for natural language-based code generation in any other appropriate manner (e.g., via firmware).

[0136] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific reference products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0137] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0138] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or apparatus. A computer-readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0139] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device that has: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0140] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes switch components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, switch components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0141] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.

[0142] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product that includes a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication unit 19, or installed from the storage unit 18, or installed from the ROM 12. When the computer program is executed by the processor 11, the above-mentioned functions defined in the method of the embodiment of the present invention are performed.

[0143] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.

[0144] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

Claims

1. A code generation method based on natural language, characterized in that: The method includes: Obtain the functional requirement information described in natural language determined by the user based on the candidate functions provided by the target system; Determining target information from feature information according to the functional requirement information; wherein the feature information is determined in advance according to the candidate function; Prompt words are generated according to the functional requirement information and the target information, and the prompt words are input into a large language model to generate a code module for executing the functional requirement information, and the code module is integrated into the target system.

2. The method according to claim 1, characterized in that in, The feature information includes at least static data; the static data includes at least one of the following: function call interface information, variable information, target system function information, candidate function description information and target system deployment scenario knowledge information.

3. The method according to claim 2, characterized in that Determining target information from feature information according to the functional requirement information includes: Determining keyword information based on the semantic recognition result of the functional requirement information; Matching data is determined from the static data according to the keyword information as target information.

4. The method according to claim 2, characterized in that The characteristic information also includes at least dynamic data and a dynamic resource quantification model; the dynamic data includes at least one of the following: current data and historical data of system resource usage parameters, execution time parameters and network monitoring parameters.

5. The method according to claim 4, characterized in that The target information includes at least the dynamic data and the dynamic resource quantification model; Inputting the prompt word into the large language model to generate a code module for executing the functional requirement information includes: In the process of generating a code module according to the prompt word by the large language model, determining predicted resource consumption information corresponding to different execution algorithms using different interfaces according to the dynamic data in the prompt word and the dynamic resource quantification model; A target interface and a target execution algorithm are determined according to the predicted resource consumption information and the system resource constraint information, and the code module is generated based on the target interface and the target execution algorithm.

6. The method according to any one of claims 2 to 5, characterized in that: in, The feature information also includes exception data and code templates corresponding to basic functions; the exception data includes the exception type that occurs during system operation and the corresponding processing mechanism.

7. The method according to any one of claims 2 to 5, characterized in that: After generating a code module for executing the functional requirement information, the method further includes: The code module and the execution result of the code module are displayed through a visual interface, and user feedback information on abnormal execution results is received through the visual interface.

8. The method according to claim 1, characterized in that Obtain the functional requirements information described in natural language determined by the user based on the candidate functions provided by the target system, including: Obtaining initial input information from the user, and determining candidate prompt information based on the candidate functions and the initial input information; Determining target prompt information determined by the user from candidate prompt information, and determining first-round input information based on the initial input information and the target prompt information; determining first-round response information according to a semantic recognition result of the first-round input information; Obtain the next round of input information determined by the user based on the first round of response information, and determine the corresponding next round of response information based on the next round of input information, until the user's input completion instruction is obtained or the round number threshold is reached, and determine the function requirement information based on the user's input information of all rounds.

9. A code generation device based on natural language, characterized in that: The device includes: The user function requirement acquisition module is used to obtain the function requirement information described in natural language determined by the user based on the candidate functions provided by the target system; a target information determination module, configured to determine target information from feature information according to the functional requirement information; wherein the feature information is determined in advance according to the candidate functions; A code module generation module is used to generate prompt words according to the functional requirement information and the target information, input the prompt words into a large language model to generate a code module for executing the functional requirement information, and integrate the code module into the target system.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the natural language-based code generation method according to any one of claims 1 to 8 when executed.

Citation Information

Patent Citations

  • Code generation method and device and electronic equipment

    CN117193790A

  • Interaction method and device based on large language model, medium and computing equipment

    CN117556008A

  • Code generation method and system based on large language model

    CN118210489A

  • Method and system for converting natural language demand into workable software

    CN119005131A

  • Visual intelligent programming method based on large language model

    CN119045806A

Cited By

  • Intelligent plug-in method and system based on large language model

    CN120780297A

  • Code generation method based on large language model and electronic equipment

    CN121092153A

  • Code generation method and system based on large model and medium

    CN121501267A