Natural language based code generation method, device and medium

By obtaining functional requirement information described by users in natural language, combining it with the target system feature information to generate code modules, and using a large language model to achieve efficient code integration on-site, the problem of low efficiency in developing new functional requirements in existing technologies is solved, and the user experience is improved.

CN120469666BActive Publication Date: 2025-10-14JINAN YUSHI INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In the existing technology, the development efficiency of users' new functional requirements for scene-based systems is low, resulting in poor user experience.

Method used

By obtaining the functional requirement information described by the user in natural language and combining it with the characteristic information of the target system, a code module is generated. The code module that executes the functional requirement is generated using a large language model and integrated into the target system.

Benefits of technology

It improves the processing efficiency of user functional requirements, realizes the generation of code modules that can be integrated into the target system through natural language on-site, and improves development efficiency and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120469666B_ABST
    Figure CN120469666B_ABST
Patent Text Reader

Abstract

A code generation method and device based on natural language and a medium are disclosed. The method comprises: obtaining function requirement information in natural language determined by a user based on a candidate function provided by a target system; determining target information from feature information according to the function requirement information; wherein the feature information is determined in advance according to the candidate function; generating a prompt word according to the function requirement information and the target information, inputting the prompt word into a large language model to generate a code module for executing the function requirement information, and integrating the code module in the target system. The present application combines the feature metadata corresponding to the candidate function of the target system with the natural language information of the user to guide the generation of the code module for executing the user-defined function requirement, allowing the user to generate the code module that can be integrated into the target system through natural language on the scene, and improving the processing efficiency of the user function requirement.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and particularly relates to a code generation method and device based on natural language and a medium. BACKGROUND

[0002] With the development of computer application, a unified system is used for management in different business scenarios, for example, a management system is used for unified management of all projects and personnel on a construction site.

[0003] However, with the development of business, users have new functional requirements for the system already deployed on the scene. In the prior art, when users have new functional requirements, the manufacturer needs to develop the target system again, and after the development is completed, the new target system is redeployed to the scene. This new function development method is low in efficiency, and causes poor user experience of the target system. SUMMARY

[0004] The present application provides a code generation method and device based on natural language and a medium to solve the problem of low development efficiency of new functional requirements for the system deployed on the scene.

[0005] According to an aspect of the present application, a code generation method based on natural language is provided, comprising:

[0006] obtaining natural language description of functional requirement information determined by a user based on a candidate function provided by a 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] generating a prompt word according to the functional requirement information and the target information, inputting the prompt word into a large language model to generate a code module for executing the functional requirement information, and integrating the code module in the target system.

[0009] According to another aspect of the present application, a code generation device based on natural language is provided, comprising:

[0010] a user functional requirement obtaining module for obtaining natural language description of functional requirement information determined by a user based on a candidate function provided by a target system;

[0011] a target information determining module for 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;

[0012] The code module generation module is configured to generate a prompt word according to the function requirement information and the target information, input the prompt word into a large language model to generate a code module for executing the function requirement information, and integrate the code module in the target system.

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

[0014] at least one processor; and a memory connected with the at least one processor in communication; 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 to enable the at least one processor to execute the natural language-based code generation method according to any one of the embodiments of the present application.

[0015] According to another aspect of the present application, a computer readable storage medium is provided, which stores computer instructions for enabling a processor to implement the natural language-based code generation method according to any one of the embodiments of the present application when executed.

[0016] The technical solution of the present embodiment combines the feature metadata corresponding to the candidate functions of the target system with the user natural language information to guide the generation of the code module for executing the user self-defined function requirement, thereby allowing the user to generate the code module that can be integrated into the target system through natural language on the scene, and improving the processing efficiency of the user function requirement.

[0017] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor to limit the scope of the present application. Other features of the present application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.

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

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

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

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

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

[0024] In order to make the personnel in the art better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should belong to the scope of protection of the present application.

[0025] It should be noted that the terms "candidate", "target" and the like in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not necessarily limit to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0026] Figure 1 A flowchart of a natural language based code generation method according to an embodiment of the present application is provided, the present embodiment can be applicable to the case of extending user-defined functions in a target system, the method can be executed by a natural language based code generation device, the natural language based code generation device can be realized in the form of hardware and / or software, and the natural language based code generation device can be configured in a server with computing capability. As shown in the figure, the method comprises: Figure 1

[0027] S110, obtaining the user based on the candidate function provided by the target system, determining the natural language description of the function requirement information.

[0028] ​The target system is a management framework of a target business scenario supporting user-defined function development, such as a construction site management system. The target system has integrated some basic functions, and supports user-defined function development for business expansion according to individual needs. The user-defined function development can be determined based on the application scenario of the target system. The candidate function is a reference function determined based on the application scenario of the target system to support user expansion. For example, the candidate function is a reference function that the target system supports for user-defined expansion. The candidate function can be determined based on the feature information in the target system, including but not limited to the capability of the target system. The natural language description of the function requirement information refers to the input of the function requirement information required for expansion by the user in the form of natural language description.

[0029] Specifically, a plurality of candidate functions that can be expanded are determined based on the business scenario and feature information of the target system. The user determines the basic reference function required for expansion based on the candidate function, expands on the basis of the basic reference function, and inputs the expansion content to the target system in the form of natural language. The input method can be voice or text, which is not limited herein.

[0030] For example, the target system is a construction site management system, and the candidate function includes a safety helmet detection function and a vehicle detection function. The user selects the safety helmet detection function as the basic reference function from the candidate function, expands on the basis of the basic reference function, and determines the function requirement information as "tracking the trajectory of the person wearing a white safety helmet". The natural language description of the function requirement information can more accurately express the user's overall requirements.

[0031] In a feasible embodiment, S110 includes:

[0032] Obtaining initial input information of the user, and determining candidate prompt information based on the candidate function and the initial input information;

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

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

[0035] Obtaining next-round input information determined by the user based on the first-round response information, and determining corresponding next-round response information based on the next-round input information, until an input completion instruction of the user is obtained or a round threshold is reached, and determining the function requirement information based on all rounds of input information of the user.

[0036] The initial input information is part of the function requirement information input by the user, that is, when the user does not input completely, candidate prompt information is determined for the user according to the part of the function requirement information and candidate functions supported by the target system, wherein the candidate prompt information is function description information supported by the target system and possibly extended by the user.

[0037] The user determines and customizes target prompt information matching the requirement from the candidate prompt information, and combines the initial input information and the candidate prompt information to obtain first-round input information, wherein the first-round input information is part of the function requirement information input by the user. In order to guide the user to express his / her requirement more fully and completely, a first-round response information is further determined according to the first-round input information of the user, wherein the first-round response information is prompt information further expanded according to the function requirement in the first-round input information, and the user determines next-round input information according to the prompt of the first-round response information, wherein the next-round input information can also be determined according to part of the input information of the user combined with next-round target prompt information. After multiple rounds of prompting and guiding the user, the user determines that the input is complete, or reaches a preset round threshold, and then complete function requirement information is determined according to the input information of all rounds of the user.

[0038] For example, when the user inputs part of natural language, an intelligent prompt function is provided to help the user express the requirement more accurately. For example, when the user inputs "detection", detection is taken as initial input information, candidate detection objects supported by the target system are determined as candidate prompt information according to the semantic recognition result of the initial input information and the matching result of the candidate functions, such as "open fire detection" and "person behavior detection". A multi-round dialogue protocol is designed: when the user inputs "detecting open fire and alarming", it is taken as first-round input information, and the system determines that the alarm mode can be expanded according to the keyword detection result in the first-round input information, and then determines the first-round response information as: "Please confirm the alarm mode: [1] trigger sound and light alarm [2] push SMS [3] link to fire extinguishing system", and the user further supplements and perfects the function requirement information according to the first-round response information until a preset round threshold is reached or the user triggers an input completion instruction.

[0039] In this embodiment, the intelligent prompt and multi-round dialogue guide are used to guide the user to input natural language conforming to the target system resources, so as to guarantee the effectiveness and function integrity of the generated code.

[0040] S120, determining target information from the feature information according to the function requirement information.

[0041] The characteristic information is determined in advance according to the candidate functions. The characteristic information is system metadata provided by the target system, that is, data information provided by the target system and directly usable when the user-defined function is expanded. For example, the characteristic information includes candidate function description information and target system basic function description information. Further, the characteristic information includes basic function call information corresponding to each candidate function.

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

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

[0044] Further, the characteristic information further includes syntax hard constraint information, specifically including prohibition of using unauthorized APIs, mandatory existence of variable references, and upper limit of loop times, to ensure the safety and standardization of the code.

[0045] In a feasible embodiment, the characteristic information further includes abnormal data; the abnormal data includes abnormal types occurring in the system running process and corresponding processing mechanisms.

[0046] The abnormal type refers to common error types occurring in the running process, which are determined according to historical running data of the target system, such as image acquisition failure and algorithm calculation timeout. The abnormal type can help the code module generated according to the user function requirement information to have better error recognition ability.

[0047] The characteristic information further includes a processing mechanism corresponding to each abnormal type, which helps the generated code module to take corresponding processing mechanisms according to the abnormal type when the abnormality is captured, to avoid affecting the running of the original main program of the target system and ensure the stability of the target system. For example, when the system has resource over-limit, it automatically degrades or alarms, that is, when the system memory is insufficient, the corresponding processing mechanism is to suspend the secondary function and prioritize the processing of critical tasks.

[0048] Specifically, the matching information of the function requirement information and the characteristic information is determined as target information. For example, the function requirement information is subjected to semantic recognition to obtain keyword information, and the keyword information and the code template and candidate function related information in the characteristic information are subjected to similarity matching, and the code template and candidate function related information matched successfully are taken as target information. In addition, since the code module may have various abnormal types in the execution process, all the abnormal data are taken as target information.

[0049] S130, generate a prompt word according to the function requirement information and the target information, input the prompt word into a large language model to generate a code module for executing the function requirement information, and integrate the code module in the target system.

[0050] Specifically, the function requirement information and the target information are filled in a preset prompt word template, the system metadata and the personalized requirements of the user are combined using a prompt word templating structure, and the large language model outputs the code module for executing the function requirement information according to the context information in the prompt word.

[0051] Optionally, the prompt word is generated according to the function requirement information, the target information and other constraint information.

[0052] The other constraint information refers to other information for prompting and constraining the generation of the code module, and includes role description constraint information, for example, you are an intelligent resource configuration engine, and the target is to generate high-performance code according to the following context, and output rule constraint information, for example, when the CPU / GPU / memory utilization rate is greater than 85%, automatically execute a preset parallel code block logic.

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

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

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

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

[0057] Specifically, the code module visualization is to display the generated code module program to the user in a visual way, so that the user can intuitively understand the structure and logic of the code module program. For example, the execution process of the code module is displayed in the form of a flowchart. The execution result visualization is to display the running result of the code module to the user in a visual way, for example, marking the detected abnormal area or personnel behavior on the image.

[0058] The execution result of the visual display includes a normal execution result and an abnormal execution result, and for the abnormal execution result, the user can determine feedback information of the abnormal execution result according to the code module of the visual display, so as to modify the code module according to the feedback information, and correct the abnormal execution result.

[0059] The generated code combines the visual interface and the function verification mechanism to guarantee the effectiveness of the generated code, and the visual interface enables the user to intuitively see the execution effect or the related output result of the code, facilitating the user to check and debug.

[0060] Further, the code module is called by a dynamic loading function preconfigured in the target system, so that the target system embeds the function requirement information.

[0061] Specifically, the dynamic loading mechanism provided by the programming language is used, such as the importlib module in Python, the class loader in Java, etc. Taking Python as an example, the importlib.import_module function reserved in the target system is used to dynamically load the code module generated by the large model at runtime, and the code module is integrated into the running environment of the existing target system.

[0062] Further, data backup and program recovery: the data of the target system are backed up regularly, including the feature information knowledge base, the function requirement information input by the user, the generated code module, etc. When the target system fails or data is lost, the program and data can be recovered in time.

[0063] The technical scheme of the embodiment guides the generation of the code module for executing the user-defined function requirement by combining the feature metadata corresponding to the candidate function of the target system with the user natural language information, realizes that the user can generate the code module that can be integrated into the target system on the scene through natural language on the scene, and improves the processing efficiency of the user function requirement.

[0064] Figure 2 The flowchart of another natural language-based code generation method provided by the embodiment of the present application is shown in the figure. Figure 2 The method comprises the following steps:

[0065] S210, obtaining the natural language described function requirement information determined by the user based on the candidate function provided by the target system.

[0066] S220, determining the keyword information according to the semantic recognition result of the function requirement information; and determining the matching data from the static data as the target information according to the keyword information.

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

[0068] The function call interface information is an interface dynamic index. By establishing an API management library, the input / output parameters, return value, permission level, QPS limit, and historical call performance data (such as average delay) of different function call interfaces are recorded, and a semantic label is added to the interface, so as to facilitate the large model to match user requirements through semantic retrieval.

[0069] The variable information is a variable dependency graph of a constructed data structure, which labels the real-time performance, read / write permission (such as alarm_status which is only readable) and description information of different variables, and provides comprehensive variable information for code generation.

[0070] The candidate function description information records the description information, applicable scene, and trigger rule of different candidate function algorithms. For example, for detection of personnel without safety helmet, the characteristics such as safety helmet type, color, and shape are recorded.

[0071] The function information of the target system introduces the detailed functions, purposes, and characteristics of the target system, including the configuration method and description of software and hardware. For example, the function introduction and configuration method of personnel without safety helmet detection.

[0072] The target system deployment scene knowledge information associates with the device deployment scene knowledge, and internally builds an industry standard library (such as GB / T28181 standard protocol and safety production operation manual), to ensure that the generated code meets the industry standards and actual scene requirements.

[0073] Specifically, various static data in the target system are pre-counted, 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 inputs the function requirement information, the keyword information in the function requirement information is determined according to the semantic recognition result of the function requirement information, the keyword information is matched with various data in the system multi-source metadata registration center, and the matching success is taken as the target information. The matching method can adopt similarity matching, that is, the keyword information and the keyword in the metadata are converted into word vectors, the cosine similarity between the word vectors is calculated as the similarity matching result between the function requirement information and the various data in the system multi-source metadata registration center, and the similarity matching result greater than a preset similarity threshold is taken as the target information; or the matching method can also adopt index matching, that is, the index relationship between a plurality of candidate keyword information and various data in the system multi-source metadata registration center is pre-determined, the metadata corresponding to the keyword information in the function requirement information is determined based on the index relationship, and is taken as the target information.

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

[0075] By controlling the user permissions of the candidate functions and / or the function call interfaces, different 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. For example, the user's function requirement information carries user permission information, and the matching data determined according to the function requirement information includes function call interfaces that do not match the user's permissions. The user is informed of the permission restrictions, and the generation fails. Information is further displayed to the user with matching candidate function description information.

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

[0077] The technical scheme of the embodiment, by combining the static data of the target system with the natural language information of the user as the input context information of the large language model, guides the large language model to generate a code module for executing the user's custom function requirement, improves the efficiency and quality of the code module generation.

[0078] Figure 3 Another flowchart of a natural language-based code generation method provided by the embodiment of the present application is provided. The embodiment further refines the feature information in the above-mentioned embodiment. As shown in Figure 3 The method comprises:

[0079] S310, obtaining candidate functions provided by the target system based on the user, and determining the function requirement information described in natural language.

[0080] S320, determining keyword information according to the semantic recognition result of the function requirement information; determining matching data from the static data as the first target information according to the keyword information.

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

[0082] S330, the dynamic data and the dynamic resource quantization model in the feature information are taken as the second target information.

[0083] The feature information at least further 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] The dynamic data refers to data that changes with the execution of the program, which is derived from user-set function combinations, executed click events, triggered unexpected events, interactions with external APIs or services, etc. They may frequently change 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 also increases, and the processing of a large amount of data may cause disk I / O read-write bottlenecks, database operation time changes, etc., in which the generated system resource usage parameters are dynamic data; in a high-concurrency environment, multiple users access or modify the same data resources at the same time, which may cause preemption and slow down the response speed, in which the generated dynamic data is the execution time parameter; the good or bad of the actual field environment network condition directly affects the speed and stability of data transmission, and further affects the response speed of the entire application, in which the generated network bandwidth peak is the network monitoring data, which can also be used as dynamic data.

[0085] Since the execution of a user's function requirement generally requires the combination of multiple algorithms or multiple function modules, and the resource consumption generated by the combination of multiple algorithms has a non-linear superposition effect, the embodiment quantifies the resource consumption result under the dynamic combination of multiple algorithms according to the pre-established dynamic resource quantification model. For example, the dynamic resource quantification model is a set of algorithm resource correspondence relationships under dynamic combination, which includes resource consumption results corresponding to different algorithm combinations, such as face detection model stacking workwear detection, occupying 200MB video memory, memory peak value 200MB, each frame image processing time 50ms / CPU core, consuming 0.5TOPS algorithm power, etc.; 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, the dynamic data of the program execution of different algorithm combinations in the target system is recorded, and the dynamic data record generally adopts the form of a log file. The log file is suitable for recording system monitoring information, application program logs, etc. The embodiment establishes a structured storage log according to algorithm function combinations, time, resource type, etc., to record resource consumption under different conditions.

[0087] In the dynamic data recording process, system monitoring tools are called, such as using top, htop, vmstat, iostat and other commands to obtain the usage of CPU, memory, disk I / O and other resources, writing scripts to execute these commands at regular intervals, and recording the output results in log files; integrate monitoring code in the application program to record key indicators such as function call time, database operation time, etc. For example, use the time module in Python to record the execution time of a function; enable the log function of the database to record read / write operations, transaction processing time and other information in all database operations. For example, in MySQL, you can enable slow query log to record SQL statements with execution time exceeding a certain threshold; use network monitoring tools to capture network packets, analyze network bandwidth, delay and other indicators, write scripts to run tools such as tcpdump regularly, and save the analysis results. During software operation, resource data often has periodic patterns, and recording these periodic changes is helpful for generating code to dynamically adjust resources. This embodiment records dynamic data in units of minutes, hours and days.

[0088] According to the recorded historical dynamic data of different algorithm combinations during execution, the dynamic resource quantization model is trained, and the input of the trained dynamic resource quantization 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 quantization model can predict the resource consumption information of the user-defined functional requirement information, therefore, the dynamic data and the dynamic resource quantization model are related to the generation of the code module, and the dynamic data and the dynamic resource quantization model are taken as the second target information.

[0090] S340, generating a prompt word according to the functional requirement information, the first target information and the second target information.

[0091] The prompt word is constructed in steps, the system role, the output rule, the static data encapsulation, the dynamic data injection and the functional requirement information are integrated, the template prompt word structure is used, and the dynamic data and the static data are combined into the context. Among them, the system role and the output rule are other constraint information, the static data is the first target information, and the dynamic data is the second target information.

[0092] Specifically, the prompt words include: system role description: you are an intelligent resource allocation engine, the goal is to generate high-performance code according to the following context; static data encapsulation: function call interfaces and their descriptions, variable descriptions, and other information of the target system; 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}} past 1 hour CPU core average utilization: {dynamic_data.cpu_hour_average last_hour_}, past 1 hour CPU core peak utilization: {{dynamic_data.cpu_perk_last_hour_}}; user's functional requirement information: "{{natural language description}}"; output rules: prefer using methods in static API, and automatically execute preset parallel code block logic when CPU / GPU / memory utilization > 85%.

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

[0094] After the large language model obtains the prompt words, different candidate algorithm combinations are generated according to the functional requirement information in the prompt words, each candidate algorithm combination uses different execution algorithms using different interfaces, and the predicted resource consumption information corresponding to the output results of different candidate algorithm combinations is determined according to the dynamic resource quantification model.

[0095] Since the user defines the functional requirement information using natural language, the functional description has uncertainty, and in the code generation process, the hardware resource consumption prediction model is established to predict the resource consumption corresponding to the self-defined function using the resource consumption quantification capability of the dynamic resource quantification model. The prediction of resource consumption is crucial to ensure that the generated code module can be successfully executed in the target system.

[0096] In S360, the target interface and the 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.

[0097] The system resource constraint information is pre-set resource usage upper limit information, such as CPU usage rate cannot exceed 90%, memory usage rate 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 quantization model are input into the large model to guide the generation of the code module, so that the resource consumption caused by the running of the generated code module in the target system meets the system resource constraint information, and safe running of the code is ensured.

[0099] The embodiment guides the large model to predict the consumed resources when generating the code, so that the resource consumption of each node of the actual target system conforms to the resource constraint.

[0100] Optionally, new dynamic data (such as actual memory consumption deviation value) generated when the code module generated by the large language model is actually executed in a sandbox environment is fed back to the input context in the prompt word of the large language model in real time, triggering the large language model to iteratively optimize the code module according to the new dynamic data, so that the large language model generates a more adaptive code module.

[0101] Optionally, in order to make the target system have better robustness and ensure that the context input can guide the model to generate a code module that meets the user's requirements, a user data manual update mechanism is supported to update the preset conditions, such as static data, dynamic data and other feature information.

[0102] Specifically, a user feedback interface and an audit process are designed to support users to submit abnormal scene correction suggestions or add new function templates (such as specific industry protocol adaptation), forming an artificial optimization ecology of feature information, and solving the problem of knowledge lag caused by version iteration of the system.

[0103] The dynamic update mechanism is conducive to continuous accumulation and optimization of knowledge. With the continuous development of software and the diversification of user needs, the feature information knowledge base is continuously enriched and improved, and more complex and specific demand-compliant code modules can be generated.

[0104] The embodiment realizes incremental automatic updating of the knowledge base by automatically collecting and combining the double-channel knowledge base self-evolution system of artificial feedback, capturing system runtime data in real time, combining version control technology, and realizing incremental automatic updating of the knowledge base; combining a user feedback interface and a multi-level audit process, supporting users to submit abnormal scene correction suggestions or add new function templates, and forming a closed-loop optimization of the knowledge base in feature information.

[0105] The technical scheme of the embodiment realizes a code module generation mechanism driven by multi-source context, dynamically fuses structured system metadata based on the multi-dimensional association of static data and dynamic data, and constructs a multi-source context prompt word in combination with a code template and abnormal data; and through resource prediction, dynamically selects the optimal interface and algorithm combination to improve the adaptability of the generated code module to the actual scene demand.

[0106] Figure 4A structural schematic diagram of a code generation device based on natural language is provided for an embodiment of the present application. As shown in the figure, the device comprises: Figure 4

[0107] A user function requirement acquisition module 410 is configured to acquire a natural language description of function requirement information determined by a user based on a candidate function provided by a target system;

[0108] A target information determination module 420 is 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 function;

[0109] A code module generation module 430 is configured to generate a prompt word according to the function requirement information and the target information, input the prompt word into a large language model to generate a code module for executing the function requirement information, and integrate the code module in the target system.

[0110] The technical solution of the embodiment guides the generation of a code module for executing a user-defined function requirement by combining feature metadata corresponding to a candidate function of a target system with user natural language information, realizes allowing a user to generate a code module that can be integrated into a target system through natural language on the scene, and improves the processing efficiency of user function requirements.

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

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

[0113] determine keyword information according to a semantic recognition result of the function requirement information;

[0114] determine matching data from the static data as target information according to the keyword information.

[0115] Optionally, the feature information at least further includes dynamic data and a dynamic resource quantization model; and 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 at least includes the dynamic data and the dynamic resource quantization model.

[0117] The code module generation module comprises a code generation unit configured to:

[0118] ​In the process that the large language model generates the code module according to the prompt word, the dynamic data in the prompt word and the dynamic resource quantization model are used to determine the predicted resource consumption information corresponding to different execution algorithms using different interfaces;

[0119] The target interface and the target execution algorithm are determined according to the predicted resource consumption information and 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 further includes a code template corresponding to abnormal data and basic functions; the abnormal data includes an abnormal type occurring in a system running process and a corresponding processing mechanism.

[0121] Optionally, the device further includes a visual interaction module, configured to, after the code module for executing the function requirement information is generated:

[0122] display the code module and an execution result of the code module through a visual interface, and receive feedback information of the user on the abnormal execution result through the visual interface.

[0123] Optionally, the user function requirement acquisition module is specifically configured to:

[0124] acquire initial input information of the user, and determine candidate prompt information according to the candidate function and the initial input information;

[0125] determine target prompt information selected by the user from the candidate prompt information, and determine first-round input information according to the initial input information and the target prompt information;

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

[0127] acquire next-round input information determined by the user according to the first-round response information, and determine corresponding next-round response information according to the next-round input information, until an input completion instruction of the user is acquired or a round threshold is reached, and determine function requirement information according to all-round input information of the user.

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

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

[0130] According to embodiments 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 structural schematic diagram of an electronic device 10 that can be used to implement embodiments of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular telephones, smart phones, wearable devices (e.g., headsets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present application described and / or claimed in this document.

[0132] As shown in Figure 5 The electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., connected in communication with the at least one processor 11, wherein the memory stores a computer program executable by the at least one processor 11, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or loaded into the random access memory (RAM) 13 from the storage unit 18. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0133] A plurality of 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 through a computer network, such as the Internet, and / or various telecommunications networks.

[0134] The processor 11 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the 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, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, and the like. The processor 11 performs various methods and processes described above, such as the method for natural language based 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 the storage unit 18. In some embodiments, parts or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded onto the RAM 13 and executed by the processor 11, one or more steps of the method for natural language based code generation described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the method for natural language based code generation by other any suitable means, such as by means of firmware.

[0136] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a complex programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0137] Computer programs used to implement the methods of the application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the computer program, when executed by the processor of the machine, implements the functions / acts specified in the flowcharts and / or block diagrams. The computer program can be executed entirely on a machine, partially on a machine and partially on a remote machine or entirely on a remote machine or server.

[0138] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer-readable storage medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium will include one or more lines of a program of instructions in a transitory signal, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0139] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having 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 a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, 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, speech, or tactile input.

[0140] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, 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] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. A server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.

[0142] In particular, the processes described above with reference to the flow charts can be implemented as computer software programs in accordance with embodiments of the application. For example, embodiments of the application include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program comprising program code for executing the methods illustrated by the flow charts. In such embodiments, 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-described functions defined in the methods of the embodiments of the application are performed.

[0143] It should be understood that the various forms of flow shown above can be re-ordered, added to, or deleted from without departing from the scope of the present application. For example, the steps recited in the present application can be performed in parallel, in series, or in a different order, without departing from the desired results of the technical solutions of the present application, and this is not limited herein.

[0144] The above detailed description does not constitute a limitation on the protection scope of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present application shall be included in the protection scope of the present application.

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; generating prompt words according to the functional requirement information and the target information, inputting the prompt words into a large language model to generate a code module for executing the functional requirement information, and integrating the code module into the target system; The target information includes at least dynamic data and a dynamic resource quantification model; dynamic data refers to data that changes as the program is executed; 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.

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 any one of claims 2 to 4, 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.

6. The method according to any one of claims 2 to 4, 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.

7. 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.

8. 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, configured to generate prompt words based on 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; The target information includes at least dynamic data and a dynamic resource quantification model; dynamic data refers to data that changes as the program is executed; The code module generation module includes a code generation unit for: 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.

9. 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 7 when executed.

Citation Information

Patent Citations

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

    CN119005131A

  • Implementation method for controlling office software to execute target operation through natural language

    CN119105832A