Code service providing method, device, system and equipment and storage medium

Generating semantic vectors and querying vector libraries through natural language processing technology, combined with generative models, solves the problem in the existing technology that code search tools are difficult to understand code semantics and context, and achieves more accurate and efficient code service provision.

CN118708159APending Publication Date: 2024-09-27THE FOURTH PARADIGM BEIJING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311808105.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-26
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

Existing code search tools are difficult to provide accurate search results when processing complex programming queries. In particular, the semantic understanding and contextual understanding of the code are insufficient, which increases the threshold for developers to use them.

Method used

Code service requests are processed through natural language processing technology, semantic vectors are generated, and matching semantic vectors are queried in the vector library to obtain semantic information corresponding to the code fragments, and input prompts are generated to generate a generative model to generate more accurate Reply message.

Benefits of technology

It improves the effectiveness of code services, improves the efficiency and accuracy of code analysis and search, and provides developers with more intelligent and convenient programming assistance tools.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708159A
    Figure CN118708159A
Patent Text Reader

Abstract

The invention relates to a code service providing method, device and system, equipment and a storage medium. Obtaining a code snippet matched with the code service request from a code library; based on the code snippets and the code service request, generating an input prompt which is used for indicating the generative model to generate response information for the code service request based on the code snippets; and inputting the input prompt into the generative model to obtain response information output by the generative model. By combining the code snippets and the code service requests, the generative model can generate more accurate and specific answers, so that the effectiveness of the provided code service can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer programming technology, and in particular to a method, apparatus, system, device and storage medium for providing a code service. Background Art

[0002] The core purpose of code analysis and processing is to improve the efficiency and quality of software development. In the actual software development process, developers often need to understand the existing code base, find the implementation method of a specific function, or find possible errors and improvement points. Effective code analysis tools can help developers quickly locate relevant code segments, thereby speeding up the development process, improving code quality, and even assisting in error diagnosis and performance optimization. Summary of the invention

[0003] A technical problem to be solved by the present disclosure is how to improve the effectiveness of the provided code service.

[0004] According to a first aspect of the present disclosure, a code service providing method is provided, comprising: obtaining a code snippet matching a code service request from a code library; generating an input prompt based on the code snippet and the code service request, wherein the input prompt is used to instruct a generative model to generate response information for the code service request based on the code snippet; and inputting the input prompt into the generative model to obtain response information output by the generative model.

[0005] Optionally, obtaining a code snippet that matches the code service request from a code library includes: processing the code service request using natural language processing technology to obtain a first semantic vector; querying a second semantic vector that matches the first semantic vector in a vector library, the vector library including multiple second semantic vectors, each second semantic vector corresponding to a code snippet, the second semantic vector being a semantic vector that is obtained by performing semantic analysis on the code snippet and can characterize semantic information of the code snippet; and obtaining a code snippet corresponding to the queried second semantic vector from the code library.

[0006] Optionally, the method further includes: processing the code snippet in the code library using natural language processing technology to obtain a second semantic vector corresponding to the code snippet.

[0007] Optionally, searching a vector library for a second semantic vector that matches the first semantic vector includes: calculating, for at least part of the second semantic vectors in the vector library, the similarity between each of the second semantic vectors and the first semantic vector; and taking a first number of second semantic vectors with top similarity rankings as second semantic vectors that match the first semantic vector.

[0008] Optionally, the method further includes: receiving the code service request input by a user; and / or outputting the response information.

[0009] Optionally, the code service request is a code generation request, and the response information is the code generated by the generative model.

[0010] Optionally, the step of outputting the response information includes: outputting the code, the code fragment and / or the file path of the code fragment in association.

[0011] According to a second aspect of the present disclosure, a code generation system is provided, comprising: a natural language processing system, a code search engine, and a dialogue system, wherein the natural language processing system processes the code generation request in response to a code generation request input by a user using a natural language processing technique to obtain the first semantic vector, the code search engine queries a second semantic vector matching the first semantic vector in a vector library, and obtains a code snippet corresponding to the queried second semantic vector from the code library, wherein the vector library comprises a plurality of second semantic vectors, each of which corresponds to a code snippet, and the second semantic vector is a semantic vector obtained by semantically analyzing the code snippet and capable of characterizing semantic information of the code snippet, the dialogue system generates an input prompt based on the code snippet corresponding to the queried second semantic vector and the code generation request, inputs the input prompt into a generative model to obtain code output by the generative model, and outputs the code, wherein the input prompt is used to instruct the generative model to generate code for the code generation request based on the code snippet.

[0012] According to a third aspect of the present disclosure, a code service providing device is provided, including: an acquisition module, used to acquire a code snippet matching a code service request from a code library; a generation module, used to generate an input prompt based on the code snippet and the code service request, wherein the input prompt is used to instruct a generative model to generate response information for the code service request based on the code snippet; and a response module, used to input the input prompt into the generative model to obtain response information output by the generative model.

[0013] Optionally, the acquisition module includes: a first processing module, used to process the code service request using natural language processing technology to obtain a first semantic vector; a first query module, used to query a second semantic vector matching the first semantic vector in a vector library, the vector library including multiple second semantic vectors, each second semantic vector corresponding to a code snippet, the second semantic vector being a semantic vector that is obtained by performing semantic analysis on the code snippet and can characterize the semantic information of the code snippet; a second query module, used to obtain a code snippet corresponding to the queried second semantic vector from the code library.

[0014] Optionally, the device further includes: a second processing module, configured to process the code snippet in the code library using natural language processing technology to obtain a second semantic vector corresponding to the code snippet.

[0015] Optionally, the first query module calculates the similarity between each of the second semantic vectors and the first semantic vector for at least part of the second semantic vectors in the vector library, and takes a first number of second semantic vectors with top similarity rankings as second semantic vectors matching the first semantic vector.

[0016] Optionally, the device further includes: a receiving module for receiving the code service request input by a user; and / or an output module for outputting the response information.

[0017] Optionally, the code service request is a code generation request, and the response information is the code generated by the generative model.

[0018] Optionally, the output module outputs the code, the code snippet and / or the file path of the code snippet in a related manner.

[0019] According to a fourth aspect of the present disclosure, a computing device is provided, comprising: a processor; and a memory on which executable codes are stored, and when the executable codes are executed by the processor, the processor executes the method described in the first aspect above.

[0020] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising an executable code, which, when executed by a processor of an electronic device, causes the processor to execute the method described in the first aspect above.

[0021] According to a sixth aspect of the present disclosure, a non-temporary machine-readable storage medium is provided, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the method described in the first aspect above.

[0022] The present disclosure inputs the code snippet obtained from the code library and the code service request into the generative model together, so that the generative model can refer to the code snippet matching the code service request to generate more accurate and specific response information, thereby improving the effectiveness of the provided code service. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.

[0024] Figure 1 A schematic flowchart of a method for providing code services according to an embodiment of the present disclosure is shown.

[0025] Figure 2 A schematic diagram of the structure of a code generation system according to an embodiment of the present disclosure is shown.

[0026] Figure 3 A schematic structural diagram of a code service providing device according to an embodiment of the present disclosure is shown.

[0027] Figure 4 A schematic diagram of the structure of a computing device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0028] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred 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 limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0029] Those skilled in the art should understand that the terms "first", "second", etc. in the present disclosure are used to distinguish similar objects, rather than to describe a specific order or sequence, and have no additional limiting effect.

[0030] The present disclosure proposes a code service providing method, which is intended to provide code services to users in a dialog manner. That is, the present disclosure can answer code-related questions raised by users to provide code services to users. The code service can specifically be, but is not limited to, a code analysis service and a code generation service.

[0031] Figure 1 A schematic flowchart of a method for providing code services according to an embodiment of the present disclosure is shown. Figure 1The method shown can be implemented in software via a computer program, and can also be executed via a specifically configured computing device.

[0032] See also Figure 1 , in step S110 , a code snippet matching the code service request is obtained from a code library.

[0033] Before executing step S110, the present disclosure may also receive a code service request input by a user. The code service request is used to characterize the code service that the user desires to obtain. The user may generate a code service request by asking a question. That is, the code service request may be a question information input by the user through text, voice, etc., in which the user desires to obtain a code service.

[0034] The disclosure has no particular restrictions on the form and acquisition method of the code service request. Exemplarily, the form of the code service request may include, but is not limited to: text form, audio form, image form, video form, etc., which are not exhaustive.

[0035] Exemplarily, a question control can be displayed on the display interface of the terminal, so that a code service request can be obtained based on the data input by the user triggering the question control. Exemplarily, the question control can be displayed on any display interface of an electronic device, that is, the technical solution provided by the present disclosure can be applied to any human-computer interaction scenario; alternatively, the question control can be displayed only on a specified interface, such as a preset question-and-answer interface. The present disclosure has no particular restrictions on the type of display interface and the way in which the question control is displayed. The display interface may include, but is not limited to, at least one of the following: an application interface, a desktop display interface, a web browsing interface, a document display interface, etc., and the question control display method can be custom designed, for example, it can be displayed in the sidebar of the application interface, or it can be displayed in the taskbar of the desktop, etc., without exhausting them.

[0036] In one possible embodiment, the text data input by the user when triggering the text question control can be obtained to obtain a code service request (i.e., question information). Alternatively, in another possible embodiment, the voice data input by the user when triggering the voice question control can be obtained to obtain a code service request. Alternatively, in another possible embodiment, the image data input by the user when triggering the image question control can be obtained, and the image data can be parsed to obtain a code service request. Alternatively, in another possible embodiment, the video data input by the user when triggering the video question control can be obtained, and the questions contained in the video data or the specified questions can be parsed to obtain a code service request.

[0037] In each of the above possible embodiments, the question control may have different forms of expression. Exemplarily, it may be expressed as a "question button" or "question input box" displayed in the display interface of the electronic device. For example, the user may click or trigger the question button by other preset methods, and then enter the question interface or question input interface for user input. The question input box may be in the form of a text input box, a voice input button, a picture or video upload (or screenshot method) area, etc.

[0038] It should be understood that when the code service request is in audio form, the terminal or the terminal's external device needs to have audio collection capabilities. In this way, the aforementioned code service request can be collected by the terminal itself, or it can be collected through an external input device. For example, when the terminal is connected to a smart wearable device such as headphones and smart watches with audio collection capabilities, the smart wearable device can collect the code service request made by the user. Similarly, when the code service request is in the form of a video or picture, the terminal (or back-end server) needs to have the ability to parse the video (or picture) to parse the user's code service request, and the parsing method is not limited here.

[0039] In an optional embodiment, in order to facilitate subsequent processing, when a non-text type code service request is obtained, the collected code service request can also be processed into a text form to obtain question information in text form.

[0040] The type of code service request may be, but is not limited to, a code analysis request and a code generation request.

[0041] A code analysis request may be a question information entered by a user for the purpose of understanding the code, improving the code quality, etc. For example, a code analysis request may be, but is not limited to, a question information in the form of analyzing whether the code is wrong, analyzing defects in the code, analyzing the design principle of the code, etc. The code targeted by the code analysis request may be the code designed by the user or the code in the code library.

[0042] The code generation request may be a question information input by the user according to his / her own needs, in which the user desires to generate a code that can realize a specific function. For example, the code generation request may be a question information such as "generate a transaction for a points refund", which can reflect the function of the code that the user desires to generate.

[0043] A code library can also be called a code repository. There are multiple code snippets in the code library. The code library can be used to store and manage code for use in the development process. For example, the code library can store various types of code, including source code, documents, configuration files, etc.

[0044] After receiving the user's code service request, the code snippet matching the code service request can first be obtained from the code library according to the code service request. For example, the code snippet matching the code service request can be retrieved from the code library using retrieval technology. The code snippet matching the code service request is one or more code snippets related to the code service request (such as the most relevant). The purpose of obtaining the code snippet from the code library is to input the code snippet as background knowledge together with the code service request into the generative model so as to obtain more accurate response information.

[0045] When obtaining code snippets that match code service requests from the code base, keyword-based code search methods, although effective in simple scenarios, are often inadequate for complex programming queries. For example, when developers need to understand the specific role of a complex function or find the implementation of a specific algorithm, it is difficult to obtain accurate search results based on keywords alone. This limitation mainly stems from the lack of in-depth understanding of the nature and context of the code by these tools. In addition to the limitations of relying on keywords, keyword-based code search methods are usually unable to effectively handle natural language queries. This means that users must know exactly what keywords they want to search for in order to obtain relevant results. For users who are unfamiliar with a specific code base or have little programming experience, this undoubtedly increases the threshold for use.

[0046] In view of the many shortcomings of the keyword-based code search method, the present disclosure proposes that semantic vectors can be embedded in code snippets in the code library, so that searches can be performed based on the actual meaning of the code (i.e., semantic vectors) rather than just keywords, thereby improving the relevance and accuracy of the search.

[0047] In some embodiments, the code service request can be first processed using natural language processing (NLP) technology to obtain a first semantic vector, and then a second semantic vector matching the first semantic vector is queried in the vector library, and finally a code snippet corresponding to the queried second semantic vector is obtained from the code library. The vector library includes multiple second semantic vectors, each second semantic vector in the vector library corresponds to a code snippet, and the second semantic vector is a semantic vector that can characterize the semantic information of the code snippet obtained by semantically analyzing the code snippet. The present disclosure can also pre-process the code snippets in the code library using natural language processing technology to obtain a second semantic vector corresponding to the code snippet, and then store the second semantic vectors of the multiple code snippets in the vector library. The natural language processing technology used to generate the first semantic vector and the second semantic vector can be, but is not limited to, a text embedding model such as Word2Vec, GloVe, BERT, etc. The text embedding model can convert text and / or code into a corresponding vector representation. Exemplarily, HuggingFaceEmbeddings can be used to convert the code service request or the code snippet in the code library to obtain a first semantic vector or a second semantic vector. HuggingFaceEmbeddings is a feature in the Hugging Face model library that provides a variety of pre-trained text embedding models.

[0048] When searching for a second semantic vector that matches a first semantic vector in a vector library, the second semantic vector that matches the first semantic vector can be queried by calculating vector similarity. That is, the second semantic vector that matches the first semantic vector can refer to a second semantic vector that has a high degree of similarity to the first semantic vector. Exemplarily, the similarity between each second semantic vector and the first semantic vector can be calculated for at least part (such as all) of the second semantic vectors in the vector library, and a first number of second semantic vectors with the highest similarity rankings are used as second semantic vectors that match the first semantic vector.

[0049] In step S120 , an input prompt is generated based on the code snippet and the code service request.

[0050] The input prompt is used to instruct the generative model to generate response information for the code service request based on the retrieved code snippet. The code snippet and the code service request can be used directly as the input prompt; or the code snippet and the code service request can be assembled according to a pre-set structural input template to obtain the input prompt.

[0051] In step S130, the input prompt is input into the generative model to obtain response information output by the generative model.

[0052] A generative model is a generative model that is built using machine learning techniques and includes a large number of parameters, such as a large language model. The input of a generative model can be unimodal data (such as one of text, images, audio, and video) or multimodal data (such as at least two of text, images, audio, and video); the output of a generative model can be unimodal data or multimodal data. In other words, a generative model can support the processing of data of one or more modalities and generate one or more modal data. For example, a generative model can be a large model with multimodal data processing capabilities and multimodal data generation capabilities.

[0053] In the present disclosure, the generative model can adopt a generative model commonly used in the industry, such as a GPT model. Of course, a new generative model can also be trained. In addition, it should be noted that considering the high overhead (time overhead and cost overhead) of training a new model, the generative model can be obtained by fine-tuning the general model, that is, the general model can be adjusted based on the existing general model according to the feature processing scale and computing power requirements, so as to obtain the generative model used in the present disclosure. This can effectively reduce the model training overhead.

[0054] The response information can be regarded as the reply obtained by the generative model after processing the code service request with the code snippet in the code base that matches the code service request as the background information. After obtaining the response information output by the generative model, the response information can also be output (visually). By combining the user question (i.e., the code service request) and the relevant code snippet, the generative model can generate more accurate and specific answers, thereby improving the effectiveness of the provided code service.

[0055] In some embodiments, the code service request may refer to a code generation request, and the response information may be the code generated by the generative model. When the response information is output, the code, the code snippet, and / or the file path of the code snippet may be output in association. This makes it convenient for the user to refer to the original code snippet based on which the generated code is based.

[0056] Taking providing a code generation service for a user as an example, the present disclosure can also be implemented as a code generation system. The code generation system can play the role of a "code robot" to interact with the user to provide the user with a code generation service.

[0057] Figure 2 A schematic diagram of the structure of a code generation system according to an embodiment of the present disclosure is shown.

[0058] See also Figure 2The code generation system 200 mainly includes three functional modules, namely, a natural language processing system 210, a code search engine 220, and a dialogue system 230. The system architecture of the code generation system 200 can ensure the scalability and maintainability of the system by adopting a modular design. At the same time, the accuracy and timeliness of the system can be ensured by continuously optimizing the algorithms and / or models used in each module. The code generation system 200 can have environmental adaptability, such as being able to adapt according to different hardware configurations (such as CPU or GPU).

[0059] The natural language processing system 210 can use natural language processing technology (such as Hugging Face Embeddings) to perform in-depth analysis on the code base, convert the code in the code base into semantic vector embeddings, that is, generate a semantic vector of the code (corresponding to the second semantic vector mentioned above). The generated semantic vector of the code can then be stored in a vector repository to prepare for subsequent search and matching operations. The vector repository corresponds to the vector repository mentioned above. The vector repository can be understood as a huge code semantic map, and each vector in the vector repository is at a specific position in the code semantic map, representing different code segments and their semantic content.

[0060] Exemplarily, the natural language processing system 210 can use a large language model of an easy-to-understand programming language to perform a deep analysis of the code base. This process includes parsing each file in the code base and extracting key structural and semantic information. For example, for a function, a large language model can be used to analyze its name, parameters, return type, and internal logical structure. That is, a large language model can be used to perform vector conversion based on information such as the name, parameters, return type, and internal logical structure of the code to obtain a semantic vector that can reflect the semantic content of the code. This analysis not only takes into account the textual surface meaning of the code, but also deeply explores the functions and behavior patterns of the code. The result of the deep analysis is an abstract representation of each piece of code, namely a semantic vector. These vectors are points in a high-dimensional space that represent the semantic content of the code. Advanced machine learning models, such as deep neural networks, can be used to generate these vectors. This process involves a lot of mathematical operations, and the model will "learn" how to convert the code into a vector form that can express its deep semantics. For example, suppose there is a simple function whose function is to calculate the sum of two numbers. In traditional keyword searches, only words such as "calculation" and "sum" may be concerned. However, through the analysis of the deep learning model, the function is converted into a vector containing information such as its calculation function, input-output relationship, etc. This vector is a point in a multidimensional space, and its position is close to the vector positions of other similar function codes.

[0061] The dialogue system 230 is used to interact with the user in the form of dialogue (i.e., question and answer). The dialogue system 230 may also be referred to as a chatbot or a question and answer system. The dialogue system 230 may receive a code generation request in the form of a question input by the user. The natural language processing system 210 may perform vector conversion on the code generation request input by the user to obtain a semantic vector of the code generation request (corresponding to the first semantic vector mentioned above).

[0062] The code search engine 220 can perform a similarity search in the vector repository based on the semantic vector of the code generation request to find one or more code vector representations related to (such as most related to) the semantic vector of the code generation request. The code vector representation is also the semantic vector of the code. After finding the code vector representation related to the semantic vector of the code generation request, the actual code snippet corresponding to the found code vector representation can be obtained from the code repository.

[0063] For example, when a user asks a query, such as "how to calculate the sum of two numbers", the natural language processing system 210 can first convert the query into a semantic vector, and then the code search engine 220 searches for the vector closest to the semantic vector in the vector repository. After finding the most similar vectors, the actual code snippets corresponding to these vectors are retrieved, thereby providing code that is highly relevant to the query.

[0064] After the code search engine 220 finds the relevant code snippet, the dialogue system 230 can generate an input prompt based on the found code snippet and the code generation request, input the input prompt into the generative model, obtain the code output by the model, and output the code. The input prompt is used to instruct the generative model to generate code for the code generation request based on the code snippet.

[0065] The code generation system 200 can also track the interaction between the user and the dialogue system 230 (i.e., the chatbot) through a session management mechanism. The interaction history between the user and the dialogue system 230 can be saved in the session, allowing the previous dialogue to be referenced. When answering the user's current question, the dialogue system 230 can also refer to the previous historical session information (such as historical questions and answer information). In terms of interface and interaction, the code generation system 200 can provide a RESTful API to allow the user to interact with the dialogue system 230. In addition, the code generation system 200 can also provide functional APIs (Application Programming Interface, application programming interface) such as a chat interface, a session management interface, a history record interface, and a code search interface. The chat interface allows users to send questions and receive answers. The session management interface can provide the functions of creating, managing, and deleting sessions. The history record interface can allow users to retrieve the history records of a specific session. The code search interface can provide a code search function based on user queries. The code generation system 200 can implement the corresponding functions by calling these functional interfaces.

[0066] In summary, the present disclosure relates to the field of natural language processing and artificial intelligence technology, and can be implemented as a chatbot system for code analysis and search. The system mainly includes a natural language processing system, a code search engine and an artificial intelligence chatbot. The natural language processing system is responsible for code semantic understanding, and can perform semantic analysis on the code base through a deep learning model, generate semantic vector embedding of the code, and realize search based on the actual meaning of the code. The natural language processing system can apply advanced language models to process and understand the user's natural language query, and provide accurate and relevant code snippets. The chatbot combines natural language processing and code semantic understanding technology, and the robot can understand complex queries related to programming and provide effective solutions and code examples. In addition, the chatbot can combine the latest language model to provide accurate and relevant code snippets according to the user's natural language query, greatly improving the user experience. The code search engine uses semantic vector embedding technology, combined with natural language queries, to quickly locate the most relevant code documents and snippets, greatly improving the retrieval efficiency. The present disclosure can improve the effectiveness of the code services provided, such as improving the efficiency and accuracy of code analysis and search, and providing developers and programming enthusiasts with more intelligent and convenient programming assistance tools.

[0067] The code service providing method disclosed in the present invention may also be implemented as a code service providing device. Figure 3 The structure diagram of the code service providing device according to an embodiment of the present disclosure is shown. The functional units of the code service providing device can be implemented by hardware, software, or a combination of hardware and software that implements the principles of the present disclosure. It can be understood by those skilled in the art that Figure 3 The functional units described can be combined or divided into sub-units to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional units described herein. The following is a brief description of the functional units that the code service providing device can have and the operations that each functional unit can perform. For the details involved, please refer to the relevant description above, which will not be repeated here.

[0068] See also Figure 3 , the code service providing device 300 may include an acquisition module 310, a generation module 320 and a response module 330. The acquisition module 310 is used to acquire a code snippet matching the code service request from the code library. The generation module 320 is used to generate an input prompt based on the code snippet and the code service request, and the input prompt is used to instruct the generative model to generate response information for the code service request based on the code snippet. The response module 330 is used to input the input prompt into the generative model to obtain the response information output by the generative model.

[0069] In some embodiments, the acquisition module 310 may include a first processing module, a first query module, and a second query module. The first processing module is used to process the code service request using natural language processing technology to obtain a first semantic vector. The first query module is used to query the vector library for a second semantic vector that matches the first semantic vector. The vector library includes multiple second semantic vectors, each second semantic vector corresponds to a code snippet, and the second semantic vector is a semantic vector that can characterize the semantic information of the code snippet by performing semantic analysis on the code snippet. The second query module is used to obtain a code snippet corresponding to the queried second semantic vector from the code library.

[0070] Exemplarily, the code service providing device 300 may further include a second processing module. The second processing module is used to process the code snippet in the code library using natural language processing technology to obtain a second semantic vector corresponding to the code snippet. Exemplarily, the first query module may calculate the similarity between each second semantic vector and the first semantic vector for at least part of the second semantic vectors in the vector library, and use the first number of second semantic vectors with the highest similarity ranking as the second semantic vector matching the first semantic vector.

[0071] In some embodiments, the code service providing device 300 may further include a receiving module and an output module. The receiving module is used to receive a code service request input by a user. The output module is used to output a response message. Exemplarily, the code service request is a code generation request, and the response message is the code generated by the generative model. The output module may output the code, the code snippet, and / or the file path of the code snippet in association.

[0072] Figure 4 A schematic diagram of the structure of a computing device that can be used to implement the above-mentioned code service providing method according to an embodiment of the present disclosure is shown.

[0073] See also Figure 4 , the computing device 400 includes a memory 410 and a processor 420 .

[0074] Processor 420 may be a multi-core processor or may include multiple processors. In some embodiments, processor 420 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, processor 420 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).

[0075] The memory 410 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 420 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 410 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 410 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.

[0076] The memory 410 stores executable codes, and when the executable codes are processed by the processor 420 , the processor 420 can execute the code service providing method mentioned above.

[0077] The code service providing method, device and apparatus according to the present disclosure have been described above in detail with reference to the accompanying drawings.

[0078] In addition, the method according to the present disclosure may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present disclosure.

[0079] Alternatively, the present disclosure may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present disclosure.

[0080] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.

[0081] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the system and method according to multiple embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive 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 implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0082] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A method for providing a code service, characterized in that: include: Get the code snippet matching the code service request from the code repository; Based on the code snippet and the code service request, generating an input prompt, wherein the input prompt is used to instruct the generative model to generate response information for the code service request based on the code snippet; The input prompt is input into the generative model to obtain response information output by the generative model.

2. The method according to claim 1, characterized in that Get code snippets from the code repository that match the code service request, including: The code service request is processed using natural language processing technology to obtain a first semantic vector; Querying a second semantic vector matching the first semantic vector in a vector library, wherein the vector library includes a plurality of second semantic vectors, each of which corresponds to a code snippet, and the second semantic vector is a semantic vector obtained by semantically analyzing the code snippet and capable of representing semantic information of the code snippet; A code snippet corresponding to the queried second semantic vector is obtained from the code base.

3. The method according to claim 2, characterized in that Also includes: The code snippet in the code library is processed using natural language processing technology to obtain a second semantic vector corresponding to the code snippet.

4. The method according to claim 2, characterized in that: Querying a vector library for a second semantic vector that matches the first semantic vector includes: For at least part of the second semantic vectors in the vector library, calculating the similarity between each of the second semantic vectors and the first semantic vector; A first number of second semantic vectors with higher similarity rankings are used as second semantic vectors matching the first semantic vector.

5. The method according to claim 1, characterized in that Also includes: receiving the code service request input by a user; and / or The response information is output.

6. The method according to claim 5, characterized in that The code service request is a code generation request, and the response information is the code generated by the generative model.

7. A code generation system, characterized in that: include: Natural language processing systems, code search engines, and dialogue systems, The natural language processing system responds to a code generation request input by a user, processes the code generation request using natural language processing technology to obtain the first semantic vector, The code search engine searches for a second semantic vector matching the first semantic vector in a vector library, and obtains a code snippet corresponding to the searched second semantic vector from the code library, wherein the vector library includes a plurality of second semantic vectors, each of which corresponds to a code snippet, and the second semantic vector is a semantic vector obtained by performing semantic analysis on the code snippet and capable of representing semantic information of the code snippet. The dialogue system generates an input prompt based on the code snippet corresponding to the queried second semantic vector and the code generation request, inputs the input prompt into the generative model to obtain the code output by the generative model, and outputs the code, wherein the input prompt is used to instruct the generative model to generate code for the code generation request based on the code snippet.

8. A code service providing device, characterized in that: include: The acquisition module is used to obtain the code snippet matching the code service request from the code library; A generating module, configured to generate an input prompt based on the code snippet and the code service request, wherein the input prompt is used to instruct the generative model to generate response information for the code service request based on the code snippet; The response module is used to input the input prompt into the generative model to obtain response information output by the generative model.

9. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 6.

10. A non-transitory machine-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 6.