Code editing method and apparatus, and device and storage medium

By sending an editing request to the target model and analyzing the response content to generate editing results, the problems of high cost and poor stability of code editing in the prior art are solved, and efficient and accurate code editing is achieved.

WO2025171714A1PCT designated stage Publication Date: 2025-08-21BEIJING ZITIAO NETWORK TECH CO LTD

Patent Information

Application Number
PCT/CN2024/123076
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-08-21

AI Technical Summary

Technical Problem

The existing technology requires rewriting the entire code file during the code editing process, resulting in high cost of generated code, easy introduction of syntax errors, and poor stability, which affects editing efficiency.

Method used

Send an edit request to the target model, instructing the output of the code snippet to be edited and the updated code snippet, obtain the response content of the target model and parse it to generate editing results, simplifying the code editing process.

Benefits of technology

Improves the efficiency and accuracy of code editing, and achieves efficient and accurate code editing by specifying output formats and formatted information parsing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024123076_21082025_PF_FP_ABST
    Figure CN2024123076_21082025_PF_FP_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure relate to a code editing method and device, and a device and a storage medium. The method provided herein comprises: sending to a target model an editing request which is associated with a target code, wherein the editing request indicates an output format of the target model, and the output format instructs the target model to output a code snippet, which needs to be replaced, and a code snippet, which needs to be updated, in a code file to be edited; acquiring response content which is output by the target model on the basis of the output format, wherein the response content comprises a first snippet to be replaced, and a second snippet used for replacing the first snippet; and generating an editing result of the target code by means of parsing the response content. In this way, the embodiments of the present disclosure can improve the output efficiency and accuracy of a target model.
Need to check novelty before this filing date? Find Prior Art

Description

Code editing method, device, equipment and storage medium Technical Field

[0001] Example embodiments of the present disclosure generally relate to the field of computers, and more particularly, to a method, apparatus, device, and computer-readable storage medium for code editing. Background Art

[0002] With the development of computer technology, generative models are gradually being applied in various scenarios. For example, some generative models can provide automatic code editing, code generation, and code repair capabilities for integrated development tools (IDEs). People hope to improve the code editing efficiency of such generative models.

[0003] Summary of the Invention

[0004] In a first aspect of the present disclosure, a method for editing code is provided. The method comprises: sending an edit request associated with target code to a target model, the edit request indicating an output format of the target model, the output format instructing the target model to output: a code segment to be replaced and an updated code segment in a code file to be edited; obtaining response content output by the target model according to the output format, the response content including a first segment to be replaced and a second segment used to replace the first segment; and generating an edit result for the target code by parsing the response content.

[0005] In a second aspect of the present disclosure, a device for code editing is provided. The device includes: a request sending module configured to send an edit request associated with a target code to a target model, the edit request indicating an output format of the target model, the output format indicating that the target model outputs: a code segment to be replaced and an updated code segment in a code file to be edited; a content acquisition module configured to acquire response content output by the target model according to the output format, the response content including a first segment to be replaced and a second segment used to replace the first segment; and a result generation module configured to generate an edit result of the target code by parsing the response content.

[0006] In a third aspect of the present disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit. When executed by the at least one processing unit, the instructions cause the device to perform the method of the first aspect.

[0007] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and the computer program can be executed by a processor to implement the method of the first aspect.

[0008] In a fifth aspect of the present disclosure, a computer program product is provided, which includes computer-executable instructions, which, when executed by a processor, implement the method according to the first aspect of the present disclosure.

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

[0010] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0011] FIG1 shows a schematic diagram of an example environment in which embodiments according to the present disclosure may be implemented;

[0012] FIG2 shows a flowchart of an example process of code editing according to some embodiments of the present disclosure;

[0013] FIG3 is a schematic diagram showing an example process of code editing according to some embodiments of the present disclosure;

[0014] FIG4 shows a schematic structural block diagram of an example apparatus for code editing according to some embodiments of the present disclosure; and

[0015] FIG5 shows a block diagram of an electronic device capable of implementing various embodiments of the present disclosure. DETAILED DESCRIPTION

[0016] The following describes embodiments of the present disclosure in more detail with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of protection of the present disclosure.

[0017] It should be noted that the titles of any section / subsection provided herein are not limiting. Various embodiments are described throughout this document, and any type of embodiment may be included under any section / subsection. Furthermore, the embodiments described in any section / subsection may be combined in any manner with any other embodiments described in the same section / subsection and / or in different sections / subsections.

[0018] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". Other explicit and implicit definitions may be included below. The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may be included below.

[0019] The embodiments of the present disclosure may involve user data, data acquisition and / or use, etc. These aspects shall comply with the corresponding laws, regulations and relevant provisions. In the embodiments of the present disclosure, all data collection, acquisition, processing, processing, forwarding, use, etc. are carried out on the premise that the user is aware of and confirms them. Accordingly, when implementing the various embodiments of the present disclosure, the types, scope of use, and usage scenarios of the data or information that may be involved should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with the relevant laws and regulations. The specific notification and / or authorization method may vary according to the actual situation and application scenario, and the scope of the present disclosure is not limited in this respect.

[0020] If this specification and the solutions in the examples involve the processing of personal information, such processing will be done only with a legitimate basis (such as with the consent of the subject of personal information or as necessary for the performance of a contract) and only within the prescribed or agreed scope. A user's refusal to process personal information other than that required for basic functions will not affect the user's use of basic functions.

[0021] Traditional approaches require agents to rewrite the entire code file during code editing, and the code format is strictly enforced. This results in high code generation costs, the introduction of new syntax errors, and poor stability, which in turn affects code editing efficiency.

[0022] Embodiments of the present disclosure propose a code editing solution. According to the solution, an edit request associated with a target code can be sent to a target model, where the edit request indicates the output format of the target model, where the output format instructs the target model to output: a code snippet to be replaced and an updated code snippet in the code file to be edited; response content output by the target model according to the output format is obtained, where the response content includes a first snippet to be replaced and a second snippet used to replace the first snippet; and the edit result of the target code is generated by parsing the response content.

[0023] In this way, the embodiments of the present disclosure can specify the code editing output format of the model, and achieve more efficient and accurate code editing through formatted information parsing, thereby improving the efficiency and accuracy of code editing.

[0024] Various example implementations of this solution are described in detail below in conjunction with the accompanying drawings.

[0025] Sample Environment

[0026] FIG1 shows a schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented. As shown in FIG1 , the example environment 100 may include an electronic device 110 .

[0027] In this example environment 100, electronic device 110 may run an application 120 that supports interface interaction. Application 120 may be any suitable type of application for interface interaction, examples of which may include, but are not limited to, code editing applications, video applications, social applications, or other suitable applications. User 140 may interact with application 120 via electronic device 110 and / or its attached devices.

[0028] In the environment 100 of FIG. 1 , if the application 120 is in an active state, the electronic device 110 may present an interface 150 for supporting interface interaction through the application 120 .

[0029] In some embodiments, the electronic device 110 communicates with the server 130 to enable the provision of services for the application 120. The electronic device 110 can be any type of mobile terminal, fixed terminal or portable terminal, including a mobile phone, a desktop computer, a laptop computer, a notebook computer, a netbook computer, a tablet computer, a media computer, a multimedia tablet, a handheld computer, a portable game terminal, a VR / AR device, a personal communication system (PCS) device, a personal navigation device, a personal digital assistant (PDA), an audio / video player, a digital camera / camcorder, a positioning device, a television receiver, a radio broadcast receiver, an e-book device, a gaming device or any combination thereof, including accessories and peripherals of these devices or any combination thereof. In some embodiments, the electronic device 110 can also support any type of interface for the user (such as a "wearable" circuit, etc.).

[0030] The server 130 may be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks, and big data and artificial intelligence platforms. The server 130 may include, for example, a computing system / server such as a mainframe, an edge computing node, a computing device in a cloud environment, etc. The server 130 may provide background services for the application 120 that supports content presentation in the electronic device 110.

[0031] A communication connection may be established between the server 130 and the electronic device 110. The communication connection may be established in a wired or wireless manner. The communication connection may include, but is not limited to, a Bluetooth connection, a mobile network connection, a Universal Serial Bus (USB) connection, a Wireless Fidelity (WiFi) connection, etc., and the embodiments of the present disclosure are not limited in this respect. In the embodiments of the present disclosure, the server 130 and the electronic device 110 may implement signaling interaction through the communication connection between the two.

[0032] It should be understood that the structure and function of the various elements in the environment 100 are described for illustrative purposes only and do not imply any limitation on the scope of the present disclosure.

[0033] Some example embodiments of the present disclosure will be described below with continued reference to the accompanying drawings.

[0034] Example Process

[0035] FIG2 shows a flow chart of an example code editing process 200 according to some embodiments of the present disclosure. Process 200 may be implemented at electronic device 110. Process 200 is described below with reference to FIG1.

[0036] As shown in Figure 2, in box 210, the electronic device 110 sends an editing request associated with the target code to the target model, and the editing request indicates the output format of the target model, and the output format indicates that the target model outputs: code snippets that need to be replaced and updated code snippets in the code file to be edited.

[0037] In some embodiments, the target model can be a language model. In addition, the target model can be associated with an agent or a bot. For example, the agent or bot can process user input editing requests based on configured knowledge information, plug-in information, system prompts, etc.

[0038] In some embodiments, the electronic device 110 may send an editing request associated with the target code to the target model in response to the agent calling the editing tool associated with the target code.

[0039] In some embodiments, the agent can retrieve the target code that needs to be edited from the code file to be edited based on a code retrieval tool. Such a code file to be edited can, for example, be a code file that has problems or defects and needs to be modified or replaced. In some embodiments, in response to receiving the target code that needs to be edited, the agent can call the editing tool associated with the target code. Furthermore, in response to the agent calling the editing tool associated with the target code, the electronic device 110 can send an editing request associated with the target code to the target model, thereby enabling debugging and repair of the target code.

[0040] In some embodiments, the edit request may indicate an output format of the target model. Such an output format may consist of a code snippet to be replaced in the code file to be edited (the second content portion) and an updated code snippet (the third content portion). In addition, such an output format may also include a file identifier of the code file to be edited (the first content portion). As an example, such a file identifier may be information such as the storage path of the code file to be edited or the name of the code file to be edited.

[0041] As an example, the output format of the target model can be specified by using the prompt words sent to the target model. As an example, such an output format can be:

[0042] In the above output format example, " <file>XXX.py< / file> " can be used to fill in the file identifier of the code file to be edited (i.e., the first content part); "{exact copy of old line(s) you would like to change}" can be used to fill in the code fragment to be replaced (i.e., the second content part); "new line(s) to replace" can be used to fill in the updated code fragment (i.e., the third content part).

[0043] In some embodiments, the editing request may also include task description information, which may include, for example, the file identification, error information, running command, problem description, and related code of the code file to be edited, thereby making it easier for the intelligent agent to identify and edit the file.

[0044] In this way, the electronic device 110 can obtain response content with a simpler output format based on the editing request associated with the target code, thereby reducing the magnitude of the content output by the model and improving the efficiency of code processing.

[0045] In block 220 , the electronic device 110 obtains response content output by the target model according to the output format, where the response content includes a first segment to be replaced and a second segment for replacing the first segment.

[0046] As discussed above, since the target model's prompt word can specify the output format of the content to be output by the target model, the target model can output response content that matches the output format example described above. Specifically, the target model can fill in corresponding content in the three content sections of the output format to indicate the code file to be edited, the code snippet to be replaced (i.e., the first snippet), and the updated code snippet (i.e., the second snippet).

[0047] In some embodiments, such a first segment may include one or more lines of code that need to be edited, and correspondingly, the second segment may include the same number of lines of code for replacement.

[0048] In summary, the electronic device 110 can obtain the response content including the file identification information of the code file to be edited, the first segment to be replaced, and the second segment for replacement.

[0049] During this process, the intelligent agent only needs to output the code part that needs to be edited without rewriting the code file to be edited, thereby improving the processing efficiency of code editing.

[0050] In block 230 , the electronic device 110 generates an editing result of the target code by parsing the response content.

[0051] In some embodiments, the electronic device 110 may parse the response content according to the output format to extract the first segment to be replaced and the second segment for replacing the first segment. As an example, the electronic device 110 may parse the output response content to extract the first segment and the second segment.

[0052] Taking the exemplary output format given above as an example, the electronic device 110 may locate and extract the corresponding file identifier, the first segment, and the second segment based on the output format.

[0053] In some scenarios, the first segment filled in by the target model may not necessarily be consistent with the code segment in the original code file. In some embodiments, the electronic device 110 can further determine whether the target code includes a target portion that matches the first segment. As an example, the electronic device 110 can determine the similarity between the code segment in the target code (or the code file to be edited) and the first segment, and further determine the relationship between the similarity and a similarity threshold, thereby determining whether the target code includes a code segment that matches the first segment.

[0054] In some embodiments, in response to the target code not including the target part (e.g., the similarity is less than a similarity threshold), the electronic device 110 may provide a feedback message about editing failure to the target model to indicate that the code snippet does not exist in the code file currently to be edited.

[0055] In some embodiments, in response to the target code including the target portion (e.g., the similarity is greater than a similarity threshold), the electronic device 110 can replace the target portion with the second segment to generate an edited result of the target code. In some embodiments, such an edited result can be presented in the form of a difference comparison (e.g., unified diff text).

[0056] In some embodiments, the target code editing result may retain the replaced target portion and the second segment for comparison. For example, electronic device 110 may generate a unified diff file between the target code and the modified target code for comparison, indicating the addition, deletion, and modification operations performed by the agent on the code segment in the target code.

[0057] In order to detect the editing result, the electronic device 110 can also detect the editing result to improve the accuracy of code editing. The detection of the editing result will be introduced below.

[0058] In some embodiments, the electronic device 110 can determine whether the editing result of the target code meets preset constraints. Such preset constraints can be, for example, that the editing result does not have syntax errors, type errors, naming errors, semantic errors, style and formatting issues, security issues, performance issues, potential errors, code complexity issues, and dependency issues, etc.

[0059] In some embodiments, the electronic device 110 may utilize a static checking tool to determine whether the edit result includes syntax errors and / or any of the above-mentioned types of errors. As an example, such a static checking tool may be a language service, a linter, or other tool.

[0060] In some embodiments, in response to the editing result satisfying the preset constraint, the electronic device 110 may provide the editing result to the target model and save the edited target code for user viewing.

[0061] In some embodiments, in response to the edit result not satisfying the preset constraints, the electronic device 110 may provide a description of the edit result not satisfying the preset constraints to the target model and cancel the edit of the target code. As an example, if the edit result fails the static check, the electronic device 110 may return a static check error message to the agent and undo the previous changes to the target code, i.e., not save the current modification. Furthermore, the agent may continue to perform the next round of code editing operations based on the error message, the target code, and the task description information until the static check passes and the final edit result is obtained.

[0062] FIG3 shows a schematic diagram of an example process of code editing according to some embodiments of the present disclosure. As shown in FIG3 , in block 310, the agent may receive an editing request, a target code, and task description information. In block 311, the electronic device 110 may obtain corresponding response content based on the received content, wherein such response content may include file identification information of the file to be edited, a code segment to be replaced (a first segment), and an updated code segment (a second segment).

[0063] Furthermore, in block 312, the electronic device 110 may parse the response content to extract the first segment and the second segment. In block 313, the electronic device 110 may determine a segment in the target code (or code file to be edited) whose similarity to the first segment is greater than a similarity threshold, and replace the segment to obtain an editing result.

[0064] Furthermore, at block 314, electronic device 110 can perform a static check on the edit results. At block 315, if the edit results pass the static check, the final edit text can be generated. At block 316, if the edit results fail the static check, the above steps need to be continued until the final edit text is generated. Thus, the target model can call agent 310 to complete the editing operation on the code file to be edited.

[0065] In this way, the embodiments of the present disclosure can simplify the code editing process and provide a simpler output format for the response content. Furthermore, the electronic device can also perform static checking on the editing results of the target code, thereby improving the output efficiency and accuracy of the target model.

[0066] In addition, by encapsulating the above code editing capabilities into a code editing tool that can be called by the intelligent agent, the embodiments of the present disclosure can further improve the accuracy and reliability of the intelligent agent's code editing and improve the efficiency of code development.

[0067] Example devices and equipment

[0068] Embodiments of the present disclosure also provide corresponding apparatuses for implementing the above-described methods or processes. FIG4 shows a schematic structural block diagram of an example apparatus 400 for code editing according to certain embodiments of the present disclosure. Apparatus 400 may be implemented as or included in electronic device 110. Each module / component in apparatus 400 may be implemented by hardware, software, firmware, or any combination thereof.

[0069] As shown in Figure 4, the device 400 includes a request sending module 410, which is configured to send an editing request associated with the target code to the target model, where the editing request indicates the output format of the target model, and the output format indicates that the target model outputs: the code fragments that need to be replaced and the updated code fragments in the code file to be edited; a content acquisition module 420, which is configured to obtain the response content output by the target model according to the output format, where the response content includes the first fragment to be replaced and the second fragment for replacing the first fragment; and a result generation module 430, which is configured to generate the editing result of the target code by parsing the response content.

[0070] In some embodiments, the output format includes: a first content part for a file identifier of a code file to be edited; a second content part for filling in a code snippet to be replaced; and a third content part for filling in an updated code snippet.

[0071] In some embodiments, the apparatus 400 further includes a content parsing module configured to parse the response content according to the output format to extract the first segment to be replaced and the second segment for replacing the first segment.

[0072] In some embodiments, the result generation module 430 is further configured to determine whether the target code includes a target portion matching the first segment; and in response to the target code including the target portion, replace the target portion with the second segment to generate an editing result of the target code.

[0073] In some embodiments, the apparatus 400 further includes a message feedback module configured to provide a feedback message regarding editing failure to the target model in response to the target code not including the target portion.

[0074] In some embodiments, the editing result preserves both the replaced target portion and the second segment.

[0075] In some embodiments, the device 400 also includes a first processing module configured to determine whether the editing result of the target code satisfies the preset constraints; and in response to the editing result satisfying the preset constraints, provide the editing result to the target model and save the editing of the target code.

[0076] In some embodiments, the apparatus 400 further includes a second processing module configured to provide descriptive information about the editing result not satisfying the preset constraint to the target model in response to the editing result not satisfying the preset constraint, and cancel the editing of the target code.

[0077] In some embodiments, the first processing module is further configured to use a static checking tool to determine whether the editing result includes a grammatical error.

[0078] In some embodiments, the target model is associated with an agent, and the request sending module 410 is further configured to send an editing request associated with the target code to the target model in response to the agent calling an editing tool associated with the target code.

[0079] The modules included in the device 400 can be implemented in various ways, including software, hardware, firmware, or any combination thereof. In some embodiments, one or more units can be implemented using software and / or firmware, such as machine executable instructions stored on a storage medium. In addition to or as an alternative to machine executable instructions, some or all of the modules in the device 400 can be implemented at least in part by one or more hardware logic components. By way of example and not limitation, exemplary types of hardware logic components that can be used include field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0080] As shown in FIG5 , electronic device 500 is a general-purpose electronic device. Components of electronic device 500 may include, but are not limited to, one or more processors or processing units 510, memory 520, storage device 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. Processing unit 510 may be a real or virtual processor and is capable of performing various processes according to programs stored in memory 520. In a multi-processor system, multiple processing units execute computer-executable instructions in parallel to enhance the parallel processing capabilities of electronic device 500.

[0081] The electronic device 500 typically includes a plurality of computer storage media. Such media can be any accessible media that can be obtained by the electronic device 500, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 520 can be a volatile memory (e.g., registers, cache, random access memory (RAM)), a non-volatile memory (e.g., read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. The storage device 530 can be a removable or non-removable medium and can include a machine-readable medium, such as a flash drive, a disk, or any other medium that can be used to store information and / or data and can be accessed within the electronic device 500.

[0082] The electronic device 500 may further include additional removable / non-removable, volatile / non-volatile storage media. Although not shown in FIG. 5 , a disk drive for reading from or writing to a removable, non-volatile disk (e.g., a “floppy disk”) and an optical drive for reading from or writing to a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to a bus (not shown) by one or more data media interfaces. The memory 520 may include a computer program product 525 having one or more program modules configured to perform various methods or actions of various embodiments of the present disclosure.

[0083] The communication unit 540 enables communication with other electronic devices via a communication medium. Additionally, the functions of the components of the electronic device 500 can be implemented in a single computing cluster or multiple computing machines that can communicate via a communication connection. Thus, the electronic device 500 can operate in a networked environment using a logical connection with one or more other servers, a network personal computer (PC), or another network node.

[0084] Input device 550 may be one or more input devices, such as a mouse, keyboard, or trackball. Output device 560 may be one or more output devices, such as a display, a speaker, or a printer. Electronic device 500 may also communicate with one or more external devices (not shown) via communication unit 540 as needed, such as a storage device, a display device, or the like, with one or more devices that allow a user to interact with electronic device 500, or with any device that allows electronic device 500 to communicate with one or more other electronic devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface (not shown).

[0085] According to an exemplary implementation of the present disclosure, a computer-readable storage medium is provided, on which computer-executable instructions are stored, wherein the computer-executable instructions are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the method described above.

[0086] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, apparatuses, devices, and computer program products implemented according to the present disclosure. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.

[0087] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, such that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device is generated that implements the functions / actions specified in one or more blocks in the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium, where these instructions cause the computer, programmable data processing device, and / or other device to operate in a specific manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing various aspects of the functions / actions specified in one or more blocks in the flowchart and / or block diagram.

[0088] Computer-readable program instructions can be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0089] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple implementations of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a part for a module, program segment or instruction, and a part for a module, program segment or instruction comprises one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the function or action of the specification, or can be realized by a combination of special hardware and computer instructions.

[0090] While various implementations of the present disclosure have been described above, the foregoing description is intended to be illustrative, not exhaustive, and not limited to the disclosed implementations. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described implementations. The terminology used herein is selected to best explain the principles of the implementations, their practical applications, or improvements to existing technologies, or to enable others skilled in the art to understand the various implementations disclosed herein.

Claims

1. A code editing method, comprising: Sending an edit request associated with the target code to the target model, the edit request indicating an output format of the target model, the output format instructing the target model to output: a code segment that needs to be replaced and an updated code segment in a code file to be edited; Acquire response content output by the target model according to the output format, where the response content includes a first segment to be replaced and a second segment used to replace the first segment; as well as By parsing the response content, an editing result of the target code is generated.

2. The method according to claim 1, wherein the output format comprises: The first content part is used for the file identifier of the code file to be edited; The second content part is used to fill in the code snippet that needs to be replaced; as well as The third content portion is used to fill in the updated code snippet.

3. The method according to claim 1, further comprising: Parse the response content according to the output format to extract the first segment to be replaced and the second segment used to replace the first segment.

4. The method according to claim 1, wherein generating the editing result of the target code by parsing the response content comprises: determining whether the target code includes a target portion that matches the first segment; as well as In response to the target code including the target portion, the target portion is replaced with the second segment to generate the edited result of the target code.

5. The method according to claim 4, further comprising: In response to the target code not including the target portion, providing a feedback message regarding compilation failure to the target model. The method according to claim 4 , wherein the editing result preserves both the replaced target portion and the second segment.

7. The method according to claim 1, further comprising: Determining whether the editing result of the target code satisfies a preset constraint; as well as In response to the editing result satisfying the preset constraint, the editing result is provided to the target model, and the editing of the target code is saved.

8. The method according to claim 7, further comprising: In response to the editing result not satisfying the preset constraint, description information about the editing result not satisfying the preset constraint is provided to the target model, and editing of the target code is canceled.

9. The method according to claim 7, wherein determining whether the editing result of the target code satisfies a preset constraint comprises: Using a static checking tool, it is determined whether the editing result includes a syntax error.

10. The method of claim 1 , wherein the target model is associated with an agent, and sending an edit request associated with the target code to the target model comprises: In response to the agent calling the editing tool associated with the target code, the editing request associated with the target code is sent to the target model.

11. A device for code editing, comprising: a request sending module configured to send an editing request associated with a target code to a target model, wherein the editing request indicates an output format of the target model, and the output format indicates that the target model outputs: a code segment to be replaced and an updated code segment in a code file to be edited; a content acquisition module configured to acquire response content output by the target model according to the output format, the response content including a first segment to be replaced and a second segment for replacing the first segment; and The result generating module is configured to generate the editing result of the target code by parsing the response content.

12. An electronic device comprising: at least one processing unit; as well as At least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 10 when executed by the at least one processing unit.

13. A computer-readable storage medium having a computer program stored thereon, wherein the computer program can be executed by a processor to implement the method according to any one of claims 1 to 10.

14. A computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Text word replacement method and device, storage medium and electronic equipment

    CN115146623A

  • Communication method and device

    CN115802370A

  • Data processing method and device

    CN116306672A

  • Automated bug fixing using deep learning

    US20220083450A1

Cited By

  • Indoor decoration drawing dual-mode editing and consistent generation method and device and medium

    CN122047006A