Code generation device and code generation method

The code generation device addresses the issue of undetected API parameter defects by integrating error detection and correction, ensuring reliable code generation through iterative execution and learning.

WO2026042268A1PCT designated stage Publication Date: 2026-02-26NT T INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
PCT/JP2024/030045
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-08-23
Publication Date
2026-02-26

AI Technical Summary

Technical Problem

Existing code generation methods using Large Language Models (LLM) fail to detect and correct defects in API parameter settings, leading to undetected errors during execution.

Method used

A code generation device and method that incorporates API error detection code into the generated code, executes it, and if errors are detected, creates a prompt for the LLM to correct the code based on execution results, ensuring corrected parameter settings.

Benefits of technology

Generates code free from defects in API parameter settings by detecting and correcting errors through iterative execution and learning, enhancing code reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure JP2024030045_26022026_PF_FP_ABST
    Figure JP2024030045_26022026_PF_FP_ABST
Patent Text Reader

Abstract

A code generation device 1 which generates code in which parameter setting in an API call has been corrected comprises: a detection code addition unit 11 which generates second code by adding API error detection code for detecting an error related to a defect in API parameter setting to first code containing API call processing; a code execution unit 12 which executes the second code, and if said error is not detected, outputs the second code as code in which parameter setting in the API call has been corrected, and if said error is detected, stores the execution result of the code containing the error; a prompt creation unit 13 which creates a prompt containing the second code, the code execution result, and an instruction text for correcting the second code on the basis of the code execution result, and which inputs the prompt to a learning server; and a corrected code re-input unit 14 which re-inputs the corrected code output from the learning server to the code execution unit as second code.
Need to check novelty before this filing date? Find Prior Art

Description

Code generation device and code generation method

[0001] The present disclosure relates to a code generation device and a code generation method.

[0002] There is a demand for technology that links ICT (Information and Communications Technology) resources. Specifically, there is a demand for technology that can generate code that links the API (Application Programming Interface) functions of ICT resources.

[0003] Therefore, the generation of such code using an LLM (Large Language Model) has been studied. Non-Patent Document 1 describes a method for generating code by correcting defects in the code generated by the LLM by executing the code generated by the LLM and inputting an error message and the code into the LLM when an error occurs.

[0004] Tianyu Zheng and 7 others, "OpenCodeInterpreter: Integrating Code Generation with Execution and Refinement," arXiv:2402.14658v2, February 28, 2024

[0005] However, if the defect in the code is in the API parameter settings, it will not cause a syntax error or a runtime error, so the execution results related to the defective part will not be detected when the code is executed, and code will be generated without correcting the defect.

[0006] The present disclosure has been made in consideration of the above circumstances, and an object of the present disclosure is to provide a technology that can generate code that is free from defects in parameter settings for calling an API.

[0007] A code generation device of one aspect of the present disclosure is a code generation device that generates code in which parameter settings of an API call have been corrected, and includes: a detection code addition unit that generates a second code by adding an API error detection code for detecting errors related to defects in API parameter settings to a first code that includes a process for calling an API; a code execution unit that executes the second code, and if the error is not detected, outputs the second code as code in which the parameter settings of the API call have been corrected, and if the error is detected, saves the code execution result including the error; a prompt creation unit that creates a prompt including the second code, the code execution result, and an instruction for correcting the second code based on the code execution result, and inputs the prompt to a learning server; and a correction code re-input unit that re-inputs the correction code output from the learning server as the second code into the code execution unit.

[0008] A code generation method of one embodiment of the present disclosure is a code generation method for generating code in which parameter settings of an API call have been corrected, in which a detection code addition unit generates a second code by adding an API error detection code for detecting errors related to defects in API parameter settings to a first code including a process for calling an API, a code execution unit executes the second code, and if the error is not detected, outputs the second code as code in which the parameter settings of the API call have been corrected, and if the error is detected, saves the code execution result including the error, a prompt creation unit creates a prompt including the second code, the code execution result, and an instruction for correcting the second code based on the code execution result, and inputs the prompt to a learning server, and a correction code re-input unit re-inputs the correction code output from the learning server into the code execution unit as a second code.

[0009] According to the present disclosure, it is possible to provide a technique that can generate code without defects in parameter settings for calling an API.

[0010] FIG. 1 is a diagram illustrating an example of the configuration of a code generation system. FIG. 2 is a diagram illustrating an example of the operation of a detection code addition unit. FIG. 3A is a diagram illustrating an example of a second code. FIG. 3B is a diagram illustrating an example of a second code. FIG. 4 is a diagram illustrating an example of the operation of a code execution unit. FIG. 5 is a diagram illustrating an example of an API request and an API response. FIG. 6 is a diagram illustrating an example of a code execution result. FIG. 7 is a diagram illustrating an example of the operation of a prompt creation unit. FIG. 8 is a diagram illustrating an example of a directive. FIG. 9 is a diagram illustrating an example of the operation of a correction code re-input unit. FIG. 10A is a diagram illustrating a correction result of a first code in this embodiment. FIG. 10B is a diagram illustrating a correction result of a first code in a conventional system. FIG. 11 is a diagram illustrating an example of the hardware configuration of a code generation device.

[0011] Hereinafter, embodiments of the present disclosure will be described with reference to the drawings. In the description of the drawings, the same parts are designated by the same reference numerals and the description thereof will be omitted.

[0012] [Summary of the present disclosure] The goal of the present disclosure is to enable the generation of code (code that integrates the API functions of ICT resources) that enables the deployment and operation of ICT resources in accordance with the needs of the person in charge, without human intervention.

[0013] The present disclosure aims to enable the generation of code that is free from defects in parameter settings for calling APIs. To achieve this objective, the present disclosure is characterized by enabling execution results related to defects in API parameter settings to be detected during code execution.

[0014] Specifically, API error detection code for detecting errors related to faulty API parameter settings is added to the code generated by the LLM. The added code is then executed, and if an error is detected, a prompt containing the error is input to the LLM. As a result, the LLM outputs code in which the error related to the faulty API parameter settings has been corrected (corrected).

[0015] [System Configuration] FIG. 1 is a diagram showing an example of the configuration of a code generation system according to this embodiment.

[0016] The code generation system includes a code generation device 1, an API server 2, and an LLM server 3.

[0017] The code generation device 1 is a device that generates code that enables API functions of ICT resources to be linked together, and that uses the code execution results to generate code in which parameter settings of API calls have been corrected.

[0018] As shown in FIG. 1, the code generating device 1 includes a detection code adding unit 11, a code executing unit 12, a prompt creating unit 13, and a correction code re-input unit 14.

[0019] The detection code addition unit 11 has the function of generating a second code by adding an API error detection code for detecting errors related to defects in API parameter settings to a first code including a process for calling an API.

[0020] The code execution unit 12 executes the second code, and if the error is not detected, outputs the second code from the code generation device 1 as a code in which the parameter settings of the API call have been corrected, and if the error is detected, has the function of saving the code execution result including the error (an error related to a defect in the parameter settings of the API).

[0021] The prompt creation unit 13 has the function of creating a prompt including the second code, the execution result of the code, and an instruction for modifying the second code based on the execution result of the code, and inputting (transmitting) the prompt to the LLM server 3.

[0022] The modified code re-input unit 14 has a function of re-inputting the modified code output (transmitted) from the LLM server 3 into the code execution unit 12 as a second code.

[0023] The API server 2 is a server of ICT resources and includes an API. The API server 2 may be a server of external ICT resources or a server of internal ICT resources. If the first code includes multiple API calls, there may be multiple API servers 2, or one server may include multiple APIs.

[0024] The LLM server 3 is an example of a learning server.

[0025] [Operation of the Code Generator] FIG. 2 is a diagram showing an example of the operation of the detection code adding unit 11. As shown in FIG.

[0026] The detection code adding unit 11 acquires a first code including a process for calling an API of an ICT resource (API server 2) (step S101).

[0027] The first code is, for example, code that includes a process for calling APIs of external and / or internal ICT resources, ICT services, microservices, and web services. The first code is, for example, code that is initially created by the LLM server 3, but may also be code that is created by a party other than the LLM server 3.

[0028] The detection code adding unit 11 generates a second code by combining the first code and the API error detection code as text data (step S102).

[0029] The API error detection code is code that has the function of outputting an error message related to a defect in the API parameter settings if the status line of the API response indicates an error when the code is executed.

[0030] The detection code adding unit 11 stores the second code (step S103).

[0031] The detection code adding unit 11 transmits the second code to the code executing unit 12 (step S104).

[0032] 3A and 3B are diagrams showing an example of the second code.

[0033] The second code is generated by prepending API error detection code to the first code, as shown in Figures 3A and 3B.

[0034] In the API error detection code shown in Figure 3A, the part enclosed by the dashed line is a function for outputting data based on the API request and data based on the API response as an error message, and the part enclosed by the dashed line is code for replacing the API call function with the corresponding function.

[0035] In the first code shown in Figure 3B, the part surrounded by a dashed line is the API call function. The part surrounded by a dashed line is the defective part of the parameter setting. The 'edges' list ([ ]) is empty. The value included in the response (info_management_response) from the API server should be set in this list as the parameter setting of the EquipmentInformation API.

[0036] FIG. 4 is a diagram showing an example of the operation of the code execution unit 12.

[0037] The code execution unit 12 receives the second code (step S201).

[0038] The code execution unit 12 executes the second code (step S202).

[0039] For example, based on the second code shown in Figures 3A and 3B, the code execution unit 12 sends the API request shown in Figure 5(a) to the API server 2 and receives the API response shown in Figure 5(b) from the API server 2.

[0040] An API request is some or all of the data contained in the request line, header line, and message body sent to the API server 2. An API response is some or all of the data contained in the status line, header line, and message body received from the API server 2.

[0041] Since the second code includes an API error detection code, if an error is detected, the API response received from the API server 2 will include not only an API response indicating the error, but also the API request that caused the error in an error message, making it easier to identify the problem area in the API call code.

[0042] The code execution unit 12 determines whether or not an error related to the API call has been detected as a result of executing the second code (step S203).

[0043] If an error is detected, the code execution unit 12 saves the error message and the variable list as text data as the code execution result (step S204), and sends the code execution result to the prompt creation unit 13 (step S205).

[0044] If no error is detected, the code execution unit 12 outputs the second code from the code generation device 1 as code in which the parameter setting of the API call has been corrected (step S206).

[0045] FIG. 6 is a diagram showing an example of a code execution result.

[0046] The code execution result is text data based on an error message and a variable list.

[0047] The error message stores a stack trace and error information.

[0048] The variable list stores pairs of variables (variable names) from the first code used when the second code is executed and the variable values ​​stored in the variables when the second code is executed. The variables are global variables, local variables, and global and local variables.

[0049] Here, the reason for adding the variable list will be explained.

[0050] As in the past, if the LLM server was asked to correct the code based only on an error message (only an error in the API response), the error would be resolved, but since the error message only contains information about a single API, the corrections would likely ignore pre-processing.

[0051] Therefore, in order to make the LLM server recognize the preprocessing, necessary variables and variable values ​​are extracted from error messages detected by the API error detection code (including API responses indicating the error and API requests that caused the error), and a variable list containing those variables and variable values ​​is generated. The necessary variables and variable values ​​are the variables stored in the API call result when the second code is executed.

[0052] FIG. 7 is a diagram showing an example of the operation of the prompt generating unit 13. As shown in FIG.

[0053] The prompt generator 13 acquires the instruction statement, the code execution result, and the second code as text (step S301).

[0054] The directive is a directive written to modify the second code by referring to the code execution result, as shown in FIG.

[0055] The prompt generator 13 generates a prompt by combining the instruction statement, the code execution result, and the second code as text data (step S302).

[0056] The prompt generator 13 uses the API of the LLM server 3 to send the prompt to the LLM server 3 (step S303).

[0057] FIG. 9 is a diagram showing an example of the operation of the correction code re-input unit 14. In FIG.

[0058] The correction code re-enter unit 14 receives the correction code from the LLM server 3 (step S401).

[0059] The modification code re-input unit 14 transmits the modification code to the code execution unit 12 as a second code (step S402).

[0060] If there are defects in multiple locations in the initially input first code, only the defective locations related to the detected execution result may be corrected, and other defective locations may remain, so the correction code re-input unit 14 transmits the correction code to the detection code addition unit 11 as the first code.

[0061] 10A shows the results of modifying the first code in this embodiment. The area enclosed by the dashed line shows that the parameter value for 'edges' is set appropriately in the response (info_management_response) from the API server 2. This is thought to be the result of including in the prompt not only an error message (API response error) but also a list of variables related to the API request that caused the error.

[0062] On the other hand, when the first code was corrected based only on the error message (API response error), the correction result shown in Figure 10B was obtained. The area surrounded by the dashed line shows that a fixed value unrelated to the response from the API server 2 was set as the parameter value for 'edges'. This is thought to be because the LLM server 3 did not recognize the data flow in the code and made corrections solely to resolve the error.

[0063] [Effects] According to this embodiment, the code generation device 1 generates second code by adding API error detection code to the first code for detecting errors related to defects in API parameter settings, and when the second code is executed and an error is detected, a prompt including the second code, the code execution result including the error, and a correction instruction is created and input to the LLM server 3, thereby making it possible to generate code without defects in parameter settings for calling the API.

[0064] Furthermore, according to this embodiment, the code execution result is an error message, the variables of the first code used when the code was executed, and the variable values ​​stored in those variables when the code was executed, so that it is possible to generate code that is reliably free of defects in the parameter settings for calling the API.

[0065] [Others] The present disclosure is not limited to the above-described embodiments, and various modifications are possible within the scope of the gist of the present disclosure.

[0066] The code generation device 1 of the present embodiment described above can be realized, for example, by using a general-purpose computer system including a CPU 901, a memory 902, a storage 903, a communication device 904, an input device 905, and an output device 906, as shown in Fig. 11. The memory 902 and the storage 903 are storage devices. In this computer system, the CPU 901 executes a predetermined program loaded onto the memory 902, thereby realizing each function of the code generation device 1.

[0067] The code generation device 1 may be implemented by one computer, or by multiple computers, or may be a virtual machine implemented on a computer.

[0068] The program for the code generation device 1 can be stored in a computer-readable recording medium such as a HDD, SSD, USB memory, CD, or DVD. The computer-readable recording medium is, for example, a non-transitory recording medium. The program for the code generation device 1 can also be distributed via a communication network.

[0069] REFERENCE SIGNS LIST 1 Code generation device 11 Detection code addition unit 12 Code execution unit 13 Prompt creation unit 14 Correction code re-input unit 2 API server 3 LLM server 901 CPU 902 Memory 903 Storage 904 Communication device 905 Input device 906 Output device

Claims

1. A code generation device that generates code with corrected parameter settings for API calls, comprising: a detection code addition unit that generates second code by adding API error detection code to first code that includes processing for calling an API, the detection code addition unit detecting errors related to defects in API parameter settings; a code execution unit that executes the second code, and if no error is detected, outputs the second code as code with corrected parameter settings for API calls, and if an error is detected, saves the code execution result including the error; a prompt creation unit that creates a prompt including the second code, the code execution result, and an instruction for correcting the second code based on the code execution result, and inputs the prompt to a learning server; and a correction code re-input unit that re-inputs the correction code output from the learning server as second code into the code execution unit.

2. The code generation device according to claim 1, wherein the API error detection code is code that outputs an error message including an API response indicating an error and an API request that caused the error if the status line of the API response contains an error.

3. The code generation device according to claim 1, wherein the code execution results are a message of the error, variables of the first code used during code execution of the second code, and variable values ​​stored in the variables during code execution of the second code.

4. A code generation method for generating code in which parameter settings for API calls have been corrected, wherein a detection code addition unit generates a second code by adding API error detection code for detecting errors related to defects in API parameter settings to a first code including a process for calling an API; a code execution unit executes the second code, and if the error is not detected, outputs the second code as code in which parameter settings for API calls have been corrected, and if the error is detected, saves the code execution result including the error; a prompt creation unit creates a prompt including the second code, the code execution result, and an instruction for correcting the second code based on the code execution result, and inputs the prompt to a learning server; and a correction code re-input unit re-inputs the correction code output from the learning server into the code execution unit as the second code.

Citation Information

Patent Citations

  • Code updating method and device, electronic equipment, computer readable storage medium and computer program product

    CN118245087A

  • Interface calling method and device, equipment, medium and program product

    CN118377558A