AI auxiliary programming method and system, storage medium and program product

By listening to the document change events of the code editor and sending the request code to the server-side open source model, rendering and displaying code prompt information, the problem of high deployment cost of AI-assisted programming is solved, and the adoption rate and programming efficiency are improved.

CN119883226APending Publication Date: 2025-04-25BEIJING ZHONGQI YUNLIAN IND FINANCE TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411894314.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

In existing AI-assisted programming technologies, the cost of privatization deployment is high, and it is difficult to bear the burden of small and medium-sized companies, resulting in a low adoption rate.

Method used

By listening to document change events in the code editor, encapsulate the request code and transmit it to the server open source model for parsing, and receive and render multiple code prompt information to the code editor for users to choose.

Benefits of technology

It reduces the private deployment cost of AI-assisted programming, improves adoption rate, and enhances programming efficiency and system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883226A_ABST
    Figure CN119883226A_ABST
Patent Text Reader

Abstract

The invention provides an AI auxiliary programming method and system, a storage medium and a program product. A code editing auxiliary plug-in monitors a document change event generated when a current editing document in a code editor is input; packaging a preset application programming interface request parameter, a path of a current edited document, a code of a position of a cursor before and after a document change event is generated, and an AI prompt word for prompting a server open source model to program to obtain a request code; the AI prompt word comprises a code function realized by programming, a used development language and an output content format; converting the request code into a corresponding transmission format according to a transmission format requirement of a preset application programming interface, transmitting the request code to a server open source model for analysis, packaging a plurality of pieces of received code extraction information, creating an embedded interface, and executing a preset coding method to render a plurality of pieces of code prompt information to a code editor for display, and the code editor executes a code prompt information selection function and displays a final programming result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of assisted programming technology, and in particular to an AI assisted programming method, system, storage medium and program product. Background Art

[0002] With the rapid development of AI, various AI-based applications have emerged, including AI-assisted painting, AI image recognition and AI digital humans. AI-assisted programming is also an application that is widely loved by developers. There are many specific application scenarios for AI-assisted programming, including intelligent question and answer, automatic completion of inline code, automatic generation of block code, automatic generation of code based on comments, etc., and the scenarios of assisted development are constantly emerging; AI-assisted programming can improve the development efficiency of developers. Before the introduction of assisted programming, developers needed to manually type each logic on the keyboard to write a line of code.

[0003] In the existing technology, in the field of AI-assisted programming, the more well-known tools abroad are ChatGPT, GitHubCopilot and Tabnine; the more well-known tools in China are CodeGeeX and Tongyi Lingma, etc.; the current popular AI-assisted programming implementation scheme, the server is deployed on the server of the AI ​​service provider, the model is generally trained with a large amount of open source code, the accuracy of the code prompt can reach about 70%, but the adoption rate is very low, generally only 30%. If you want to increase the adoption rate, you must use the customer's proprietary code for training, and the server is in the AI ​​supplier, the customer code is in the customer, and generally involves commercial secrets, the code cannot be released externally, so there is a contradiction. Fortunately, subsequent AI suppliers also provided a solution, which is private deployment. However, at the current time when AI is emerging, the cost of this technology is unbearable for small and medium-sized companies. Summary of the invention

[0004] In view of this, the embodiments of the present invention provide an AI-assisted programming method, system, storage medium and program product to eliminate or improve one or more defects existing in the prior art, and solve the problem of high privatization cost of AI-assisted programming in the prior art.

[0005] One aspect of the present invention provides an AI-assisted programming method, the method comprising the following steps:

[0006] Monitor the currently edited document in the code editor and receive the document change event generated when the currently edited document has input, encapsulate the preset application programming interface request parameters used to transmit the request code to the server-side open source model, the path of the currently edited document, the code at the cursor position before and after the document change event is generated, and the AI ​​prompt word to obtain the request code; the AI ​​prompt word is used to prompt the server-side open source model to program, and the AI ​​prompt word includes the code function implemented by programming, the development language used, and the output content format;

[0007] The request code is converted into a corresponding transmission format according to the transmission format requirement of the preset application programming interface, and the request code is transmitted to the server-side open source model for parsing; the server-side open source model uses a large model supporting auxiliary programming to generate multiple code prompt information;

[0008] Receive and encapsulate the multiple code prompt information returned by the server-side open source model, create an embedded interface in the encapsulated multiple code extraction information and execute a preset encoding method to render the multiple code prompt information to the code editor for display, so that the code editor can execute the code prompt information selection function and display the final programming result.

[0009] In some embodiments, the method further comprises:

[0010] When monitoring the input of the currently edited document in the code editor, determine whether the code editor where the currently edited document is located is the main editor, if not the main editor, end the process, if yes, request to complete the currently edited document according to the existing code logic and obtain the document change event;

[0011] A new cursor position is obtained according to the original cursor position of the currently edited document and the length corresponding to the document change event, and it is determined whether the text input between the original cursor position and the new cursor position is a valid input; when the input is valid, the code editing auxiliary plug-in obtains the code prompt information from the local cache and renders the code prompt information on the code editor for display; if the code prompt information is not obtained, the request code is sent to the server-side open source model.

[0012] In some embodiments, the step of generating the AI ​​prompt word includes:

[0013] Obtain the code function that needs to be implemented by programming on the model server;

[0014] Describing the code function using natural language, and further understanding the code function based on the code at the cursor position before and after the document change event is generated;

[0015] The development language used by the model server for programming is set according to programming requirements, and the content format of the server-side open source model output programming is set.

[0016] In some embodiments, the request code is converted into a corresponding transmission format according to the transmission format requirements of a preset application programming interface, and transmitting the request code to the server-side open source model also includes: the code editing auxiliary plug-in calls the execution method of the http client to transmit the request code to the server-side open source model.

[0017] In some embodiments, receiving and encapsulating multiple code prompt information returned by the server-side open source model also includes: storing the multiple code prompt information in a local cache, and when the same request code exists, the code editing auxiliary plug-in directly calls the multiple code prompt information and renders it to the code editor for display.

[0018] In some embodiments, the code editor executes the code prompt information selection function and obtains the final programming result, including:

[0019] Conducting integrity review on the multiple code prompt information, and using code detection tools to perform syntax recognition and code style recognition;

[0020] Obtaining the running time and resource occupancy of the plurality of code prompt information through benchmark testing;

[0021] User feedback is collected to obtain readability and scalability of the plurality of code prompt information.

[0022] In some embodiments, the method also includes: the code editing auxiliary plug-in uses an asynchronous thread to simultaneously execute sending the request code to the server-side open source model, receiving multiple code prompt information returned by the server-side open source model, and rendering the code prompt information to the code editor.

[0023] Another aspect of the present invention provides an AI-assisted programming system, the system comprising:

[0024] A code editor, used for editing a currently edited document and constructing the content inputted in the currently edited document as a document change event; and for executing a code prompt information selection function;

[0025] A code editing auxiliary plug-in, used to execute any of the above-mentioned AI-assisted programming methods; used to monitor document change events in the code editor, encapsulate the preset application programming interface request parameters used to transmit the request code to the server-side open source model, the path of the currently edited document, the code at the cursor position before and after the document change event is generated, and the AI ​​prompt word to obtain the request code; convert the request code into a corresponding transmission format according to the transmission format requirements of the preset application programming interface, and transmit the request code to the server-side open source model for parsing; receive and encapsulate multiple code prompt information returned by the server-side open source model;

[0026] The server-side open source model is used to receive and parse the request code to obtain the multiple code prompt information.

[0027] On the other hand, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of any of the above methods when executed by a processor.

[0028] On the other hand, the present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of any of the above methods.

[0029] The beneficial effects of the present invention are at least:

[0030] In the AI-assisted programming method, system, storage medium and program product of the present invention, the AI ​​prompt word is used to prompt the coding content when the server-side open source model performs logical reasoning. The AI ​​prompt word can be modified and expanded according to the programming requirements and programming styles of different projects to obtain customized AI prompt words that meet the requirements. The preset application programming interface can associate the code editing auxiliary plug-in with the enterprise's internal development platform and code management system to achieve customized requirements; the request code is transmitted to the server-side open source model after the transmission format is converted using the preset application programming interface, and the instruction information and programming requirements contained in the request code are accurately transmitted to the server-side open source model; the embedded interface is a small prompt box for rendering the obtained multiple code prompt information The code is displayed in the code editor, which is convenient for users to select and present the programming results after AI-assisted programming on the code editor; the assisted programming infers the programming intention according to the current code context that has been input and returns multiple code prompt information. The user chooses whether to adopt and which code prompt information to adopt according to the code logic and semantic information, thereby improving the development efficiency of programming; the shortcut keys of the code selection function facilitate observation of the multiple code prompt information and selection to adopt or not adopt the code prompt information; the code editing auxiliary plug-in uses an asynchronous thread to simultaneously execute sending the request code to the server-side open source model, receiving multiple code prompt information returned by the server-side open source model, and rendering the code prompt information to the code editor, thereby improving the efficiency of AI-assisted programming and the performance of the system.

[0031] Additional advantages, purposes, and features of the present invention will be described in part in the following description, and will become apparent to those skilled in the art after studying the following, or may be learned from the practice of the present invention. The purposes and other advantages of the present invention may be achieved and obtained by the structures specifically indicated in the specification and the accompanying drawings.

[0032] Those skilled in the art will appreciate that the objectives and advantages that can be achieved with the present invention are not limited to the above specific description, and the above and other objectives that can be achieved by the present invention will be more clearly understood from the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of the present application, and do not constitute a limitation of the present invention. In the drawings:

[0034] Figure 1 Schematic diagram of the flow of the AI-assisted programming method according to one embodiment of the present invention.

[0035] Figure 2This is a schematic diagram of the structure of the AI-assisted programming system described in one embodiment of the present invention. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments and the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0037] It should also be noted that, in order to avoid obscuring the present invention due to unnecessary details, only structures and / or processing steps closely related to the solutions according to the present invention are shown in the accompanying drawings, while other details that are not closely related to the present invention are omitted.

[0038] It should be emphasized that the term “include / comprises” when used herein refers to the presence of features, elements, steps or components, but does not exclude the presence or addition of one or more other features, elements, steps or components.

[0039] It should also be noted that, unless otherwise specified, the term “connection” herein may refer not only to a direct connection but also to an indirect connection involving an intermediate.

[0040] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. In the accompanying drawings, the same reference numerals represent the same or similar components, or the same or similar steps.

[0041] In the existing technology, the server is deployed on the server of the AI ​​service provider. The model is generally trained with a large amount of open source code. The accuracy of the code prompt can reach about 70%, but the adoption rate is very low, generally only 30%. If you want to increase the adoption rate, you must use the customer's proprietary code for training. The server is in the AI ​​supplier, and the customer code is in the customer side. It generally involves commercial secrets and the code cannot be released externally. This creates a contradiction. Fortunately, subsequent AI suppliers have also provided a solution, which is private deployment. However, at a time when AI is emerging, the cost of this technology is unaffordable for small and medium-sized companies. The present invention proposes an AI-assisted programming method, system, storage medium and program product, which monitor the current editing document in the code editor and receive the document change event generated when the current editing document has input, and encapsulate the preset application programming interface request parameters, the path of the current editing document, the code of the cursor position before and after the document change event is generated, and the AI ​​prompt word to obtain the request code; the AI ​​prompt word is used to prompt the server-side open source model to program, and the AI ​​prompt word includes the code function implemented by programming, the development language used and the output content format; according to the transmission format requirements of the preset application programming interface, the request code is converted into a corresponding transmission format, and the request code is transmitted to the server-side open source model for parsing; multiple code prompt information returned by the server-side open source model is received and encapsulated, an embedded interface is created in the encapsulated multiple code extraction information, and a preset encoding method is executed to render the multiple code prompt information on the code editor for display, so that the code editor can execute the code prompt information selection function and display the final programming result.

[0042] Figure 1 Schematic diagram of the flow of the AI-assisted programming method according to one embodiment of the present invention. Figure 2 Schematic diagram of the structure of an AI-assisted programming system according to an embodiment of the present invention. Specifically, the present application provides an AI-assisted programming method, which includes the following steps S101 to S103:

[0043] Step S101: monitor the current editing document in the code editor and receive the document change event generated when the current editing document has input, and encapsulate the preset application programming interface request parameters used to transmit the request code to the server-side open source model, the path of the current editing document, the code of the cursor position before and after the document change event is generated, and the AI ​​prompt word to obtain the request code; the AI ​​prompt word is used to prompt the server-side open source model to program, and the AI ​​prompt word includes the code function implemented by the programming, the development language used, and the output content format.

[0044] Step S102: convert the request code into a corresponding transmission format according to the transmission format requirements of the preset application programming interface, and transmit the request code to the server-side open source model for parsing; the server-side open source model uses a large model that supports auxiliary programming to generate multiple code prompt information.

[0045] Step S103: Receive and encapsulate multiple code prompt information returned by the server-side open source model, create an embedded interface in the encapsulated multiple code extraction information, and execute a preset encoding method to render the multiple code prompt information to the code editor for display, so that the code editor can execute the code prompt information selection function and display the final programming result.

[0046] In step S101, the code editing auxiliary plug-in adopts the idea plug-in, which is installed in the idea integrated development environment and used to expand the functions of the idea integrated development environment. The development language and environment include java, jdk11 and HttpClient. The server-side open source model is deployed on the CPU using Ollama technology and is convenient for users to use and run. The server-side open source model includes codeqwen1.5 and CodeGeex4. The server-side open source model supports auxiliary programming including code completion and generation, code translation, automatic annotation and intelligent question and answer; the listener registered in the code editor listens to the document change (DocumentEvent) event triggered when the current editing document in the code editor has input, and executes the corresponding code logic after listening to the event. In some embodiments, the AI-assisted programming method also includes steps S1011 to S1012:

[0047] Step S1011: When the code editor monitors the input of the current editing document, determine whether the code editor where the current editing document is located is the main editor. If it is not the main editor, end the process. If it is, request to complete the current editing document according to the existing code logic and obtain a document change event.

[0048] Step S1012: Obtain a new cursor position based on the original cursor position of the currently edited document and the length corresponding to the document change event, and determine whether the text input between the original cursor position and the new cursor position is a valid input; when the input is valid, the code editing auxiliary plug-in obtains the code prompt information from the local cache and renders the code prompt information on the code editor for display; if the code prompt information is not obtained, a request code is sent to the server-side open source model.

[0049] Specifically, the newly input text information is intercepted and judged whether it is valid according to the original cursor position and the new cursor position; invalid input includes space, tab and carriage return; there are multiple editors in the idea integrated development environment, and different editing documents will be opened in their corresponding code editors. The main editor assumes the main editing function and is the editing area that the user focuses on and operates. Confirming the main editor ensures that auxiliary programming is performed in the core editing area later. The request code is the Codegeex completion request object (CodegeexCompleteReq) obtained after encapsulating the request information, so as to accurately convey the user's coding requirements to the server-side open source model; the preset application programming interface request parameters are provided by the server-side open source model and are used for the programming interface to transmit the request information. Table 1 is the application programming interface request parameter table. The editor position is obtained according to the path of the current editing document to ensure that the code prompt information is returned to the corresponding editor; the code of the cursor position before and after the document change event is generated is obtained according to the cursor offset and the text input in the document change event is obtained.

[0050] Table 1 Application programming interface request parameter table

[0051]

[0052] Table 1 Application programming interface request parameter table

[0053]

[0054] Table 1 Application programming interface request parameter table

[0055]

[0056] In some embodiments, the steps of generating AI prompt words include S11 to S13:

[0057] Step S11: Obtain the code functions that need to be implemented by programming on the model server.

[0058] Step S12: Describe the code function using natural language, and further understand the code function based on the code at the cursor position before and after the document change event occurs.

[0059] Step S13: Set the development language used by the model server for programming according to programming requirements, and set the content format of the server-side open source model output programming.

[0060] Specifically, AI prompt words are used to assist programming in function positioning, issue programming instructions to the server-side open source model to guide auxiliary programming, affect the accuracy of the server-side open source model's logical reasoning results and code prompt information, including the code function to be implemented in the request programming, the development language used in the request programming, and the content format presented after the programming output, for example: You are a code completion assistant. Please generate the most likely code based on the given context. The language is Java. Please do not output anything other than the generated code. The generated code is formatted correctly and follows best practices. Please do not output any comments or explanations about the generated code. Please only output the generated code. The generated code is a single line. The generated code does not contain any sensitive information, such as passwords, application programming interface keys, and personal data.

[0061] In step S102, the preset application programming interface uses the JSON application programming interface to convert the request code into a JSON string format, and then calls the execution method of the http client (HttpClient) to transmit the request code to the server-side open source model. HttpClient is a tool class used to implement http protocol communication in the java language, and initiates http requests to the server-side open source model, including get (GET) requests, submit (POST) requests, update (PUT) requests and delete (DELETE) requests; in some embodiments, the request code is converted into a corresponding transmission format according to the transmission format requirements of the preset application programming interface, and transmitting the request code to the server-side open source model also includes: the code editing auxiliary plug-in calls the execution method of the http client to transmit the request code to the server-side open source model.

[0062] In step S103, the server-side open source model parses the request code and returns the response code to the code editing auxiliary plug-in. The code editing auxiliary plug-in parses the response code and obtains multiple code prompt information. In some embodiments, receiving and encapsulating multiple code prompt information returned by the server-side open source model also includes: storing multiple code prompt information in a local cache, and when the same request code exists, the code editing auxiliary plug-in directly calls multiple code prompt information and renders it to the code editor for display. The multiple code prompt information returned by the server-side open source model is stored as a java.util.List collection, and the java.util.List collection is stored in the local cache. When the code editing auxiliary plug-in determines that the text input between the original cursor position and the new cursor position is valid and consistent with the previous request programming, the java.util.List collection is directly called from the local cache to improve programming efficiency and resource utilization. When multiple code prompt information is stored in the local cache, it is convenient to directly obtain results when the same request is triggered to improve the performance of auxiliary programming. After encapsulating multiple code prompt information, a CompletionPreview object is obtained, and an embedded interface is created in the CompletionPreview object. The embedded interface adopts the Inlay interface, and the execution logic defined by the Inlay interface is implemented through DefaultCompletionInlay. The multiple code prompt information is rendered on the code editor for display through the preset encoding method com.zqyl.aicoder.completion2.DefaultCompletionInlay#render. The current editing document of the code editor can see the rendering effect. Furthermore, DefaultCompletionInlay implements the execution logic of turning off the rendering effect defined by the Disposable interface.

[0063] In some embodiments, the steps of the code editor executing the code prompt information selection function and obtaining the final programming result include S1031 to S1033:

[0064] Step S1031: Conduct integrity review on multiple code prompt information, and use code detection tools to perform syntax recognition and code style recognition.

[0065] Step S1032: Obtain the running time and resource usage of multiple code prompt information through benchmark testing.

[0066] Step S1033: Collect user feedback to obtain readability and scalability of multiple code prompt information.

[0067] Specifically, after receiving multiple code prompt information transmitted by the code editing auxiliary plug-in, the code editor selects from the code prompt information and adopts one of the code prompt information or does not adopt any of the code prompt information. If one of the code prompt information is adopted, the rendered prompt information in gray italic state is added to the current editing document and presents the same form as normal code typing. If no code prompt information is adopted, the rendering effect is canceled. The code prompt information selection functions executed by the code editor include adopting code prompt information, canceling code prompt information, turning pages forward, and turning pages backward.

[0068] In some embodiments, the AI-assisted programming method also includes: the code editing auxiliary plug-in uses an asynchronous thread to simultaneously execute sending a request code to the server-side open source model, receiving multiple code prompt information returned by the server-side open source model, and rendering multiple code prompt information to the code editor. Specifically, the asynchronous thread method allows the three operations of sending a request, receiving multiple code prompt information returned by the server-side open source model response, and rendering to the code editor to be performed simultaneously, avoiding blockage when executing a certain operation and affecting other operations, improving feedback efficiency and resource utilization, and providing a flexible task scheduling mechanism to ensure the operating efficiency and function realization of the code editing auxiliary plug-in.

[0069] Another aspect of the present invention provides an AI-assisted programming system, the AI-assisted programming system comprising:

[0070] The code editor is used to edit the current document and construct the content entered in the current document into a document change event; it is used to execute the code prompt information selection function.

[0071] A code editing auxiliary plug-in is used to execute any of the above-mentioned AI-assisted programming methods; it is used to listen to document change events in the code editor, and encapsulate the preset application programming interface request parameters, the path of the currently edited document, the code of the cursor position before and after the document change event, and the AI ​​prompt words used to transmit the request code to the server-side open source model to obtain the request code; according to the transmission format requirements of the preset application programming interface, the request code is converted into the corresponding transmission format, and the request code is transmitted to the server-side open source model for parsing; and multiple code prompt information returned by the server-side open source model is received and encapsulated.

[0072] The server-side open source model is used to receive and parse the request code to obtain multiple code prompt information.

[0073] On the other hand, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of any of the above methods when executed by a processor.

[0074] On the other hand, the present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of any of the above methods.

[0075] The present invention is described below in conjunction with a specific embodiment:

[0076] This solution is divided into client and server. The client uses idea plug-in as the code editing auxiliary plug-in for AI-assisted programming, and the server uses open source models that support AI-assisted programming. The system environment uses Windwos 10, and the development tool uses Intellij Idea 2022.2.2. The development language and environment include java, jdk11 and http client (HttpClient). The model deployment hardware uses central processing unit (CPU), and the model deployment technology uses Ollama. The server open source models include codeqwen1.5 and CodeGeex4.

[0077] The client's code editing auxiliary plug-in monitors the current editing document. When there is input in the current editing document, the code editing auxiliary plug-in will receive the document change event, call the preset application programming interface according to the context parameters and other request parameters of the current editing document, and send the request code in the form of an http request to the server-side open source model. After receiving the request, the server-side open source model internally parses the request parameters and outputs the inference result after completing the inference, and then writes it to the http response and returns it; after receiving the response, the code editing auxiliary plug-in parses multiple code prompt information, builds an embedded interface, and writes the code prompt information to the embedded interface for display. The detailed process includes document monitoring logic, input acquisition logic, cache reading logic, request server-side application programming interface logic, cache writing logic, rendering logic, and shortcut key monitoring logic.

[0078] 1. Document listening logic and input acquisition logic. When a user edits the current document, a document change event (DocumentEvent event) is triggered. A listener for the document change event is registered in the code editing auxiliary plug-in. After listening to the document change event, the code logic corresponding to the listener is executed; it is determined whether the code editor where the current document is edited is the main editor, if not, the process ends; if yes, a request is made to complete the current document according to the existing code logic and obtain the document change event; then the current original cursor position is obtained, and the length corresponding to the document change event is added to obtain the new cursor position, and it is determined whether the text input between the original cursor position and the new cursor position is valid input; invalid input includes carriage return input, tab input, and space input.

[0079] 2. Read cache logic. After the text input is valid, the code editing auxiliary plug-in obtains the code prompt information from the local cache. If it exists, the rendering logic is executed; if it does not exist, the request logic is executed.

[0080] 3. Request the server-side API logic. Prepare the API request parameters according to the API request document provided by the server-side open source model; select https as the transmission method when transmitting the request code to the server-side open source model; use synchronous call to wait for the server-side open source model to complete execution and return the final result or server-sent event (SSE) call; use UTF-8 as the character encoding; use JSON as the interface request format; use JSON or standard Stream Event as the response format; use submit (POST) request as the interface request type; and use any development language that can initiate http requests as the development language. The API request parameters include model, request_id, do_sample, stream, temperature, top_p, max_tokens, stop, extra, target, language, code_prefix, code_suffix, contexts, path, code, and user_id.

[0081] According to the new cursor position offset, the code before and after the cursor are intercepted from the document object to obtain the code of the cursor position before the document change event is generated and the code of the cursor position after the document change event is generated; the code before the cursor String before = document.getText(new TextRange(begin,offset)); the code after the cursor String after = document.getText(new TextRange(offset,end)).

[0082] Get the path of the currently edited document according to String filePath = FileDocumentManager.getInstance().getFile(document).getPath().

[0083] Write AI prompt words. AI prompt words give the server-side open source model a functional positioning when assisting coding. The server-side open source model will use AI prompt words when performing logical reasoning. The accuracy of the prompt words determines the correctness of the code prompt information. The AI ​​prompt words given here are: You are a code completion assistant. Please generate the most likely code based on the given context. The language is Java. Please do not output anything other than the generated code. The generated code is well-formatted and follows best practices. Please do not output any comments or explanations about the generated code. Please only output the generated code. The generated code is a single line. The generated code does not contain any sensitive information, such as passwords, application programming interface keys, and personal data.

[0084] After the preset API request parameters, the path of the current editing document, the code of the cursor position before the document change event, the code of the cursor position after the document change event, and the AI ​​prompt words are prepared, create a Codegeex completion request object (CodegeexCompleteReq) to obtain the request code, and then use the JSON API to convert it into a JSON string format. Then call the execution method of the http client (HttpClient) to send the request code.

[0085] The sending, response, and rendering of the request code are all implemented through asynchronous threads, which does not block the editing of the current document. During the entire code completion process, users can still develop normally.

[0086] After receiving the response string returned by the server-side open source model, the code editing auxiliary plug-in converts it into a response class object to obtain multiple code prompt information, and then executes the rendering logic.

[0087] 4. Write cache logic and rendering logic. The multiple code prompt information returned by the server-side open source model is placed in a java.util.List collection, and the results are stored in the cache to facilitate direct acquisition of results when the same request is triggered again, thereby improving performance. The CompletionPreview class represents the preview encapsulation of code prompt information. Multiple code prompt information is encapsulated to obtain a CompletionPreview object. An Inlay object is created inside the CompletionPreview object. Inlay is actually an embedded interface. The actual implementation class of the Inlay interface is the extended DefaultCompletionInlay.

[0088] Execute the com.zqyl.aicoder.completion2.DefaultCompletionInlay#render method to render the code prompt information to the code editor, and the rendering effect can be seen in the current editing document; at the same time, DefaultCompletionInlay implements the Disposable interface, which means that the rendering effect can be turned off; the rendering effect is in gray italic state; after adoption, the effect is consistent with the normal typing code presentation state.

[0089] 5. Shortcut key monitoring logic. After the code prompt information is rendered on the page, if the code prompt information is not acceptable, the user can cancel the rendering; the implementation principle of canceling the rendering is to monitor keyboard and mouse events, and the defined rules are in line with the common programming habits in the industry, including: the tag key indicates the acceptance of the code prompt information. When this key is pressed, the code prompt information in the gray italic state can be adopted and then drawn to the cursor position of the currently edited document; the esc key indicates the cancellation of the code prompt information; the alt+[ key indicates turning the page forward, and the returned prompt information is a list collection. If there are multiple items, turning the page forward and backward is allowed; the alt+] key indicates turning the page backward.

[0090] In summary, the present invention provides an AI-assisted programming method, system, storage medium and program product, wherein a code editing auxiliary plug-in monitors a currently edited document in a code editor and receives a document change event generated when the currently edited document has input, and encapsulates a preset application programming interface request parameter, the path of the currently edited document, the code at the cursor position before and after the document change event is generated, and an AI prompt word to obtain a request code; the AI ​​prompt word is used to prompt a server-side open source model to perform programming, and the AI ​​prompt word includes the code function implemented by programming, the development language used, and the output content format; according to the transmission format requirements of the preset application programming interface, the request code is converted into a corresponding transmission format, and the request code is transmitted to the server-side open source model for parsing; multiple code prompt information returned by the server-side open source model is received and encapsulated, an embedded interface is created in the encapsulated multiple code extraction information, and a preset encoding method is executed to render the multiple code prompt information on the code editor for display, so that the code editor can execute the code prompt information selection function and display the final programming result.

[0091] The embodiment of the present invention also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the aforementioned edge computing server deployment method are implemented. The computer-readable storage medium can be a tangible storage medium, such as a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a floppy disk, a hard disk, a removable storage disk, a CD-ROM, or any other form of storage medium known in the technical field.

[0092] It should be understood by those skilled in the art that the exemplary components, systems and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software or a combination of the two. Whether it is performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier.

[0093] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.

[0094] In the present invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with features of other embodiments or replace features of other embodiments.

[0095] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. An AI-assisted programming method, characterized in that: The method is executed on a code editing auxiliary plug-in, and the method includes: Monitor the currently edited document in the code editor and receive the document change event generated when the currently edited document has input, encapsulate the preset application programming interface request parameters used to transmit the request code to the server-side open source model, the path of the currently edited document, the code at the cursor position before and after the document change event is generated, and the AI ​​prompt word to obtain the request code; the AI ​​prompt word is used to prompt the server-side open source model to program, and the AI ​​prompt word includes the code function implemented by programming, the development language used, and the output content format; The request code is converted into a corresponding transmission format according to the transmission format requirement of the preset application programming interface, and the request code is transmitted to the server-side open source model for parsing; the server-side open source model uses a large model supporting auxiliary programming to generate multiple code prompt information; Receive and encapsulate the multiple code prompt information returned by the server-side open source model, create an embedded interface in the encapsulated multiple code extraction information and execute a preset encoding method to render the multiple code prompt information to the code editor for display, so that the code editor can execute the code prompt information selection function and display the final programming result.

2. The AI-assisted programming method according to claim 1, characterized in that: The method further comprises: When monitoring the input of the currently edited document in the code editor, determine whether the code editor where the currently edited document is located is the main editor, if not the main editor, end the process, if yes, request to complete the currently edited document according to the existing code logic and obtain the document change event; A new cursor position is obtained according to the original cursor position of the currently edited document and the length corresponding to the document change event, and it is determined whether the text input between the original cursor position and the new cursor position is a valid input; when the input is valid, the code editing auxiliary plug-in obtains the code prompt information from the local cache and renders the code prompt information on the code editor for display; if the code prompt information is not obtained, the request code is sent to the server-side open source model.

3. The AI-assisted programming method according to claim 1, characterized in that: The steps of generating the AI ​​prompt words include: Obtain the code function that needs to be implemented by programming on the model server; Describing the code function using natural language, and further understanding the code function based on the code at the cursor position before and after the document change event is generated; The development language used by the model server for programming is set according to programming requirements, and the content format of the server-side open source model output programming is set.

4. The AI-assisted programming method according to claim 1, characterized in that: The request code is converted into a corresponding transmission format according to the transmission format requirements of a preset application programming interface, and the request code is transmitted to the server-side open source model, which also includes: the code editing auxiliary plug-in calls the execution method of the http client to transmit the request code to the server-side open source model.

5. The AI-assisted programming method according to claim 1, characterized in that: Receiving and encapsulating multiple code prompt information returned by the server-side open source model also includes: storing the multiple code prompt information in a local cache, and when the same request code exists, the code editing auxiliary plug-in directly calls the multiple code prompt information and renders it to the code editor for display.

6. The AI-assisted programming method according to claim 1, characterized in that: The steps of the code editor executing the code prompt information selection function and obtaining the final programming result include: Conducting integrity review on the multiple code prompt information, and using code detection tools to perform syntax recognition and code style recognition; Obtaining the running time and resource occupancy of the plurality of code prompt information through benchmark testing; User feedback is collected to obtain readability and scalability of the plurality of code prompt information.

7. The AI-assisted programming method according to claim 1, characterized in that: The method also includes: the code editing auxiliary plug-in uses an asynchronous thread to simultaneously execute sending the request code to the server-side open source model, receiving multiple code prompt information returned by the server-side open source model, and rendering the code prompt information on the code editor.

8. An AI-assisted programming system, characterized in that: The system comprises: A code editor, used for editing a currently edited document and constructing the content inputted in the currently edited document as a document change event; and for executing a code prompt information selection function; A code editing auxiliary plug-in, used to execute the AI-assisted programming method as claimed in any one of claims 1 to 7; used to monitor document change events in a code editor, encapsulate preset application programming interface request parameters for transmitting request codes to a server-side open source model, the path of the currently edited document, the code at the cursor position before and after the document change event is generated, and the AI ​​prompt word to obtain a request code; convert the request code into a corresponding transmission format according to the transmission format requirements of the preset application programming interface, and transmit the request code to the server-side open source model for parsing; receive and encapsulate multiple code prompt information returned by the server-side open source model; The server-side open source model is used to receive and parse the request code to obtain the multiple code prompt information.

9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Code editing method and device, server, user equipment and storage medium

    CN112817583A

  • LLM-based programming auxiliary method

    CN116974541A

  • Plug-in framework, plug-in, data processing method and device and electronic equipment

    CN117289929A

  • Code auxiliary system, code auxiliary processing method and device and electronic equipment

    CN117311683A

  • Code completion method and device, electronic equipment and storage medium

    CN119149000A

Cited By

  • Code change statistical method and system considering different editing scenes

    CN120973846A