Code document generation method and device based on large model, equipment and storage medium
Patent Information
- Application Number
- CN202610822273.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-08
- Publication Date
- 2026-10-13
AI Technical Summary
然而现有技术在实际应用中仍存在显著不足:一是高度依赖人工编写的注释,若代码缺乏规范注释则无法生成有效文档,导致文档与代码严重脱节;二是文档生成能力单一,多基于规则或模板进行文本拼接,无法真正理解代码逻辑、业务流程与系统架构,生成内容流于表面、缺乏关联性;三是以单文件为单位处理,缺乏对项目整体结构、模块间调用关系及数据流转路径的全局感知,导致文档碎片化、难以形成完整技术体系;四是面对大量无注释、低规范性、多语言混合(Python/SQL/JS等)的代码文件,传统工具识别能力薄弱,无法有效提取关键信息,文档生成质量低下
[0009]上述基于大模型的代码文档生成方法、装置、设备及存储介质,接收由预设接口输入的初始代码文档,并按照预设文件粒度提取所述初始代码文档中的文件数据;所述初始代码文档中设置有项目文件格式数据;通过调用的预设大模型和预设提示词工程策略将所述文件数据与所述初始文档对应的项目文件格式数据进行上下文结合,以在完成语义理解与信息识别后,生成语义识别代码文档;将所述语义识别代码文档返回至与所述预设接口对应的前端进行渲染处理后,生成显示在前端上的目标代码文档。本方案通过系统自动识别语义识别代码文档和自动生成目标代码文档的方式,无需人工编写注释,即可实现对项目代码的自动文档化,通过调用的预设大模型预设提示词工程策略去理解文件数据和项目文件格式数据,实现全局上下文理解,文档内容与代码内容保持高度一致,有效解决文档滞后于代码与文档与代码脱节等长期痛点,保证上下文理解的准确性与文档理解的完整性,最终生成的目标代码文档可保证文档提取的信息是关键重要的,保证文档生成质量。
Smart Images

Figure CN122903038A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of development assistance, and more particularly to a method, apparatus, device, and storage medium for generating code documentation based on a large model. Background Technology
[0002] With the development of automation and intelligence in software engineering, automatic code documentation generation technology has gradually become an important direction for improving R&D efficiency and reducing the cost of knowledge accumulation. Currently, tools such as Doxygen, Javadoc, Sphinx, and Swagger support annotation-based documentation generation, and some platforms are also trying to introduce AI capabilities to assist in code understanding. In particular, in business scenarios such as financial risk control, intelligent customer service, and IoT platforms, it is necessary to quickly develop corresponding platform tools. However, existing technologies still have significant shortcomings in practical applications: First, they heavily rely on manually written comments. If the code lacks standardized comments, effective documentation cannot be generated, leading to a serious disconnect between documentation and code. Second, the documentation generation capabilities are limited, often relying on rules or templates to splice text, failing to truly understand code logic, business processes, and system architecture, resulting in superficial and unrelated content. Third, they process data on a single file basis, lacking a global understanding of the overall project structure, inter-module call relationships, and data flow paths, leading to fragmented documentation and difficulty in forming a complete technical system. Fourth, when faced with a large number of uncommented, poorly standardized, and multi-language mixed (Python / SQL / JS, etc.) code files, traditional tools have weak recognition capabilities, failing to effectively extract key information and resulting in low-quality documentation.
[0003] Therefore, it is urgent to find a new technical solution to solve the above-mentioned technical problems. Summary of the Invention
[0004] Based on this, a method, apparatus, device, and storage medium for generating code documentation based on a large model are provided to solve the technical problem that current technologies struggle to achieve the goal of "automatically, accurately, and multidimensionally generating high-quality technical documentation starting from code content".
[0005] A document generation method based on a large model includes: Receive an initial code document input from a preset interface, and extract file data from the initial code document according to a preset file granularity; the initial code document contains project file format data. By invoking a preset large model and a preset prompt word engineering strategy, the file data is combined with the project file format data corresponding to the initial document in context, so as to generate a semantic recognition code document after completing semantic understanding and information recognition; After the semantic recognition code document is returned to the front end corresponding to the preset interface for rendering, a target code document is generated and displayed on the front end.
[0006] A code documentation generation device based on a large model, comprising: The extraction module is used to receive an initial code document input from a preset interface and extract file data from the initial code document according to a preset file granularity; the initial code document contains project file format data. The module is used to combine the file data with the project file format data corresponding to the initial document in context by calling the preset large model and preset prompt word engineering strategy, so as to generate a semantic recognition code document after completing semantic understanding and information recognition; The generation module is used to return the semantic recognition code document to the front end corresponding to the preset interface for rendering processing, and then generate the target code document displayed on the front end.
[0007] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the above-described document generation method based on a large model.
[0008] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described document generation method based on a large model.
[0009] The aforementioned code documentation generation method, apparatus, device, and storage medium based on a large model receive an initial code document input through a preset interface and extract file data from the initial code document according to a preset file granularity. The initial code document contains project file format data. By invoking a preset large model and a preset prompt word engineering strategy, the file data is contextually combined with the project file format data corresponding to the initial document to generate a semantically recognized code document after semantic understanding and information recognition are completed. The semantically recognized code document is then returned to the front-end corresponding to the preset interface for rendering processing, generating a target code document displayed on the front-end. This solution achieves automatic documentation of project code by automatically recognizing the semantically recognized code document and automatically generating the target code document, eliminating the need for manual annotation. By invoking a preset large model and a preset prompt word engineering strategy to understand the file data and project file format data, global contextual understanding is achieved. The document content maintains a high degree of consistency with the code content, effectively solving long-standing pain points such as document lag behind code and document-code disconnect, ensuring the accuracy and completeness of contextual understanding. The final generated target code document ensures that the extracted information is critical and important, guaranteeing the quality of document generation. Attached Figure Description
[0010] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a schematic diagram of an application environment for a document generation method based on a large model according to an embodiment of the present invention; Figure 2 This is a process diagram of a document generation method based on a large model in one embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a code document generation device based on a large model in one embodiment of the present invention; Figure 4 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0013] The document generation method based on a large model provided by this invention can be applied to, for example... Figure 1 In this application environment, the client communicates with the server via a network. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be a standalone server or a server cluster consisting of multiple servers; for example, this invention can be applied to the server corresponding to a data middleware platform.
[0014] In one embodiment, such as Figure 2 As shown, a document generation method based on a large model is provided, which is then applied to... Figure 1 Taking the server where the system resides as an example, the system can be a financial insurance system. The method includes the following steps S10 to S50: S10, receive the initial code document input from the preset interface, and extract the file data in the initial code document according to the preset file granularity; the initial code document contains project file format data.
[0015] Understandably, the preset interface is a preset large model interface called under the deployed target microservice entity. Through this interface, automatic scanning, semantic understanding, and structured document generation of project code can be achieved. The initial code document sets the corresponding original file data. In this document, it may be a source document code file, a code file without comments, with low standardization, mixed language, a fragmented code file that is difficult to form a complete technical system, a code file that lacks contextual relevance and logical integrity, a code file that is seriously disconnected from effective code, or a code file that arbitrarily combines the above-mentioned problems. The file data represents the corresponding source code data, comment data, etc. in the document (which may include absolute file path, relative file path (relative to the project root directory), language type, file content (truncated), file size (bytes), and number of lines). The project file format data represents the planning requirements for forming the final document data, which may include directory structure, file name naming conventions, and project configuration files, etc. The preset file granularity can be understood as one initial code document being extracted once, that is, the system will extract the content of each file in the initial code document individually.
[0016] In this embodiment, after receiving all the corresponding document data through a pre-built interface, the required file data is extracted from each document data according to the granularity requirements, and after favorable data filtering, the file data is used for identification in the future.
[0017] S20: By invoking the preset large model and preset prompt word engineering strategy, the file data is combined with the project file format data corresponding to the initial document in context, so as to generate a semantic recognition code document after completing semantic understanding and information recognition.
[0018] Understandably, there is a correspondence between the preset large model and the preset interface. Asynchronous transmission is performed by calling the interface corresponding to the preset large model. That is, the system will not send all files to the preset large model at once, but will adopt an asynchronous + batch + rate limiting strategy to avoid overload of a single request and improve processing stability. The preset prompt word engineering strategy generates key data by constructing preset prompt word templates. After combining the context data of file data and project file format data, a semantic recognition code document is generated. The semantic recognition code document is a structured analysis result document generated after the large model inference, such as the analysis result document of all files in the interface document, the analysis result document of the Service layer + Controller layer in the business logic description document, and the analysis result document of the global context + configuration file in the technical framework document, etc.
[0019] In this embodiment, when calling the high-performance preset large model, a preset prompt word engineering strategy is adopted. The file data is combined with the project file format data as the context input of the preset large model, so that the preset large model has the ability to understand the whole world, thereby accurately identifying the semantic recognition code document.
[0020] S30, the semantic recognition code document is returned to the front end corresponding to the preset interface for rendering processing, and then the target code document displayed on the front end is generated.
[0021] Understandably, the semantic recognition code document is returned in JSON format to the front end corresponding to the preset interface through the target microservice. The front end dynamically renders the document into a front-end document page, which can support the display of functions such as directory navigation, code highlighting, collapsing and expanding, and search and positioning.
[0022] In this embodiment, data can be clearly visualized through rendering to improve readability and user experience; the front end supports rich text rendering and interactive browsing to enhance the document usage experience.
[0023] In the scenarios of steps S10 to S30, business scenarios such as financial risk control, intelligent customer service, and IoT platforms will build corresponding platform tools. The preset prompt word engineering strategies are different in different business scenarios, that is, the prompt word templates are different, so that the preset large model can adapt to different business scenarios and accurately provide the corresponding processing strategies.
[0024] In the embodiments where steps S10 to S30 are located, the system automatically identifies semantic recognition code documents and automatically generates target code documents, achieving automatic documentation of project code without the need for manual annotation. By calling the preset large model preset prompt word engineering strategy to understand file data and project file format data, global contextual understanding is achieved. The document content is highly consistent with the code content, effectively solving long-standing pain points such as document lagging behind code and document being disconnected from code, ensuring the accuracy of contextual understanding and the completeness of document understanding. The final generated target code document ensures that the information extracted from the document is critical and important, guaranteeing the quality of document generation.
[0025] Furthermore, before receiving the initial code document input from the preset interface, the process also includes: An interface-based design is used to construct the target microservice entity; the target microservice entity is used to generate the target code document on the front end in subsequent steps. The method of constructing the target microservice entity using an interface-based design includes: Configure a unified request and response format for all preset interfaces, expose the preset interfaces, and configure the access authentication mechanism for the preset interfaces to obtain the first microservice entity; The preset interface is configured to be callable by a preset external system to obtain the second microservice entity; The first microservice entity and the second microservice entity are used as the target microservice entity.
[0026] Understandably, the request and response format can be an HTTP request from an external system such as a front-end system or a CI / CD pipeline; the default interfaces can provide interfaces for task submission, status query, and result retrieval; the access authentication mechanism can be a multi-layered access authentication mechanism, such as API Key + JWT Token. After the authentication request reaches the gateway, it first checks whether there is an Authorization: Bearer in the Header. <token>If present, verify the JWT token (check signature, expiration time, and permission scope); otherwise, check if the X-API-Key exists in the header. If the API key exists, query the Redis cache to verify its existence and whether it is disabled. If not, return a 401 Unauthorized status. After successful verification, check user role permissions. If permissions are granted, allow access to the route processing function; otherwise, return a 403 status. The first microservice entity can have features such as unified request format, unified response format, and two-layer authentication. The interface exposure methods include automatically exposing all routes, and each preset interface has a clear HTTP method + path + parameter description. The second microservice entity further configures all preset interfaces to make them truly usable after seamless invocation by external systems. The target microservice entity can be an independent Python-based microservice, which can include a model API management module, instruction control module, code scanning module, structure output module, etc. It supports RESTful API interface exposure and can be seamlessly invoked by external systems such as front-end systems and CI / CD pipelines, with good integrability and scalability. Specifically, after configuring the target microservice entity, the system can run as follows: the microservice is called through a command / interface. The microservice identifies the specific task to be executed according to the command, scans the contents of the initial code document's project path (the project path can be specified as an input parameter), and calls the interface corresponding to the configured preset large model according to file shards (sharded calls can prevent the preset large model from timeout and also solve the problem of excessively long context). The preset large model summarizes and outputs the specific semantic recognition code document based on the context. Finally, the microservice formats the target code document output by the preset large model and returns it to the front end for corresponding rendering and display. In this embodiment, a document generation microservice is pre-built, automating the entire process from code scanning to document generation. It automatically scans and concurrently calls a pre-defined large model to output the target code document in a standardized manner, resulting in both high output speed and high accuracy. Furthermore, the independent microservice architecture supports high availability, reusability, and integrability. This means the document generation capability is encapsulated as an independent microservice, accessible to other systems through pre-defined interfaces, avoiding coupling with the main business system, reducing maintenance costs, and making it suitable for various development environments.
[0027] It should be noted that the system has a built-in file hash verification mechanism that only reprocesses the modified initial code file to avoid full scanning; at the same time, the generated result - target code document - is cached in a preset database such as Redis to improve the performance of subsequent calls.
[0028] Further, receiving the initial code document input from the preset interface includes: Obtain the preset target path corresponding to the preset interface, and use the target path as the starting point for scanning; After traversing each folder storing the initial code document downwards from the starting point, a complete file list is obtained; Construct a preset directory tree structure based on the file list, and record the hierarchical position of each initial code document in the preset directory tree structure; Obtain each of the initial code documents from the said hierarchical location.
[0029] Understandably, the preset target path can be the root directory path of a project entered or selected by the user on the system interface. After receiving this path, the system uses it as the starting point for scanning, and all subsequent operations revolve around this root directory. The complete file list is obtained by the system starting a recursive scanning engine, traversing each subfolder storing the initial code documents layer by layer from the starting point at the root directory. During the scanning process, the system filters files based on their file extensions, retaining only common source code file formats such as .py, .js / .ts, .java, .sql, .xml, .yml / .yaml, etc. A complete file list might show 156 files scanned, including 80 Java files, 20 SQL files, and 10 YAML files. The preset directory tree structure records the hierarchical position of each initial code document within the project, for example: src / main / java / com / example / controller / OrderController.java; The default directory tree structure will later be used as part of the context content and provided to the default large model; In this embodiment, a scanning mechanism under microservices is constructed to enable the system to automatically and recursively scan all initial code documents under a specified project path.
[0030] Further, the step of extracting file data from the initial code document according to a preset file granularity includes: Read all the contents of the initial code document according to the preset file granularity; Based on the size of all the content, determine whether the content of the initial code document is too long; If the content of the initial code document exceeds the preset length, the preset number of lines will be automatically truncated as valid content in chronological order. The extracted valid content is packaged into a standard file data.
[0031] Understandably, preset file granularity refers to extracting all content corresponding to the file data for each initial code document in the list individually, with the extraction granularity being "one file, one time"; preset length can refer to the line length of the corresponding file; the preset line length is less than the preset length, which is beneficial for automatic truncation in subsequent judgment processes; standard file data can be a JSON data packet, which encapsulates the data of the required fields; Specifically, for each initial code document, the system performs the following operations: The system opens the file in UTF-8 encoding and reads all text content. Based on the file extension, it automatically determines the programming language of the file; for example, .java extension → language type = Java; .py extension → language type = Python; .yml extension → language type = YAML. If the initial code document is too long (e.g., exceeding 2000 lines), the system automatically truncates the first 2000 lines as valid content to avoid excessively large data packets in a single transmission, which could cause the preset interface to time out or reject the request. The extracted information is encapsulated into a standard JSON data packet, which may contain the following fields: project_name, project name; root_dir, root directory path; total_files, total number of files scanned; directory_tree, directory tree structure (JSON format); and languages_detected, a list of detected languages. In this embodiment, the content of each initial code document is extracted at the "file granularity" level, encapsulated in a structured data packet, and then asynchronously transmitted by calling a preset large model. This avoids content overload in a single request and ensures the stability of system processing.
[0032] Furthermore, after extracting file data from the initial code document according to a preset file granularity, the process further includes: Group all file data according to the preset batch number to obtain the grouping results; Using a preset semaphore mechanism to control the sending of a preset number of requests for each group result, and encapsulating the file data in each initial code document into a request for a model call.
[0033] Understandably, the preset batch number can be divided according to the number of files corresponding to the file data, such as grouping all files into batches of 10; the grouping result is the grouping result obtained after the batch is divided; the preset semaphore mechanism can prevent the preset interface from being rate-limited or the service from crashing due to too many instantaneous requests, and the preset quantity can be a pre-set number of requests, and the preset semaphore mechanism can be one of process or thread; the file data of each file will be encapsulated into an independent call request (encapsulated into an asynchronous call request of a model call), and the request adopts a streaming response mode. After all requests in each batch are completed, the system will collect the returned analysis results in a unified manner, classify and store them according to the file path, and wait for subsequent summarization to generate target code documents; In this embodiment, requests are made in batches. That is, the results of the preset large model are returned word by word / segment by segment, rather than all at once after all the data has been generated. This significantly reduces waiting time and improves user experience. In addition, a "file-dimensional" transmission strategy is adopted, which ensures the processing efficiency of the preset large model and avoids request failures due to excessive content. At the same time, asynchronous queues are used to implement model calls, improving system throughput and fault tolerance.
[0034] Furthermore, the process of combining the file data with the project file format data corresponding to the initial document through the invoked preset large model and preset prompt word engineering strategy, in order to generate a semantic recognition code document after completing semantic understanding and information recognition, includes: Build a preset prompt word template; The file data and the project file format data corresponding to the initial document are passed to the preset prompt word template; After the preset large model receives the preset prompt word template, it executes a preset reasoning process to generate a semantic recognition code document corresponding to semantic understanding and information recognition.
[0035] Understandably, the preset prompt template can define roles, project context (such as project name, project root directory structure, and detected language), current file content, and task requirements (combined with the project context (directory structure, naming conventions, configuration files), analyze and generate the following three types of documents: Interface Document: lists all interfaces, request parameters, and response formats defined in the file; Business Logic Description: describes the business process and state transitions corresponding to the interface; Technical Framework Description: explains the position and role of the file in the overall technical architecture). Project file format data can include directory structure - the folder hierarchy of the entire project (tree-like JSON), file naming conventions - such as all Controller files ending with Controller, DAO files ending with Dao, and configuration file content - for example, application.yml defines database connections and Redis. Configuration and related file hints - for example, if the current file is OrderController.java, the system will also pass in the summaries of OrderService.java and OrderMapper.xml; the preset hint template integrates file data and project file format data, which allows the preset large model to have the ability to understand globally; 1. Reasoning process: Identify interface definition and parameters, scan annotations (such as @PostMapping, @GetMapping) and method signatures in the file, and extract: Interface path: / api / orders / create; Request method: POST; Request parameters: OrderDTO (including fields such as order amount, user ID, product list, etc.); Response format: Result (including code, message, data); 2. Reasoning process: Identify core business processes and state transitions, combine the project context, analyze the position of the preset interface in the whole business, and reason out the complete business process, such as user placing an order → Validate parameters → Validate inventory → Deduct inventory (inventory status: available → locked) → Create order (order status: pending payment) → Send order success message → Return result; Reasoning Process: Identifying technology selection and framework hierarchy, access layer, business layer, persistence layer, and database caching; Semantic recognition code documentation can be divided into interface definition and parameter description (generating interface documentation), core business process and state transition (generating business logic description documentation), and technology selection, framework hierarchy, and component relationships (generating technical framework documentation). Specifically, the preset large model outputs three types of structured documents according to instructions. The program can be run locally by inputting "@create project path interface / business / architecture" to scan project content, call the corresponding preset interface of the preset large model to generate the corresponding document, or request specific interfaces through preset interface calls to achieve different types of document output: 1. Interface Document: Includes interface path, request method, parameter description, return example, and error code description; 2. Business Logic Description Document: Uses flowcharts and natural language descriptions to outline the core business chain and key judgment logic; 3. Technical Framework Document: Analyzes technology stack usage, core component dependencies, design pattern applications, system layering structure, etc. In this embodiment, when calling the preset large model, a prompt word engineering optimization strategy—preset prompt word templates—is adopted. The file content, combined with the project context, serves as the context input for the preset large model, enabling it to possess global understanding capabilities. It not only understands the content of a single file but also, in conjunction with the project structure and file relationships, achieves cross-file and cross-module context modeling. This allows for accurate identification and the generation of corresponding semantic recognition code documents, ensuring logical coherence and system integrity in the generated documents, truly realizing an intelligent closed loop of "code as documentation." Furthermore, the same input can simultaneously generate interface, business, and technical documents, meeting the reading needs of different roles (developers, testers, architects, product managers). Moreover, it overcomes the limitations of traditional rule-based or comment-based document generation, leveraging the powerful semantic understanding capabilities of the preset large model to directly extract logical structure, interface definitions, and business intent from uncommented code, achieving "high-quality documentation even with zero comments," significantly improving document coverage and accuracy.
[0036] Furthermore, the construction of the preset prompt word template includes: Obtain pre-configured prompt word template parameters, and obtain pre-configured system prompt words and knowledge bases corresponding to multiple preset large models; automatically switch between the preset large models; The preset prompt word template is dynamically constructed based on the configuration information; the configuration information includes prompt word template parameters, system prompt words, and a knowledge base.
[0037] Understandably, the prompt word template parameters can cover different values in different business scenarios, which mainly include role settings, task descriptions, output format requirements, contextual prompts, etc.; Configure AgentId, each AgentId corresponds to an intelligent agent that has been pre-trained on a large model platform, and has its own exclusive system prompt words and knowledge base; Model configuration can automatically switch models. Specifically, when switching preset large models, only two key values need to be changed: model.provider and model.name, and the system will automatically route to the new model. In addition, it is also necessary to perform business scenario-specific configurations, such as the currently active business scenario, the prompt word template key used in the default scenario, the Agent Key used in the default scenario, the Model Key used in the default scenario, the prompt word key for the financial risk control scenario, the Agent Key for the financial risk control scenario, and the Model Key for the financial risk control scenario, etc. Specifically, the process of assembling preset prompt word templates is as follows: Based on the same set of code, the prompt word template parameters, system prompt words, and knowledge base are set into the preset prompt word template, and completely different preset prompt word templates are generated by switching the scenario parameter, such as scenario="default" → generating a document generation type preset prompt word template, scenario="finance" → generating a financial risk control type preset prompt word template, and scenario="cs" → generating an intelligent customer service type preset prompt word template; In this embodiment, a preset prompt word template is pre-built to provide corresponding contextual understanding for the preset large model, thereby further enhancing the analysis output capability of the preset large model; dynamic loading and version control of prompt word templates are supported, making it easy to customize according to different projects or industry scenarios; the preset large model call interface is open, making it easy to access more advanced large model versions and continuously optimize the generation quality.
[0038] Furthermore, the system features an extended plug-in interface for prompt word management and model switching. Prompt word templates support configurable management, allowing integration with the Apollo unified configuration platform to configure different prompt word parameters and different agentIds to connect to different intelligent agents. Different models can be configured to connect to different underlying models, enabling customized prompt words for various business scenarios (such as financial risk control, intelligent customer service, and IoT platforms). The model call interface has reserved extension points, supporting switching between preset large models from different vendors or versions, ensuring technological evolution capabilities.
[0039] In summary, the above provides a document generation method based on a large model. It receives an initial code document input through a preset interface and extracts file data from the initial code document according to a preset file granularity. The initial code document contains project file format data. By invoking a preset large model and a preset prompt word engineering strategy, the file data is contextually combined with the project file format data corresponding to the initial document to generate a semantically recognized code document after semantic understanding and information recognition are completed. The semantically recognized code document is then returned to the front-end corresponding to the preset interface for rendering processing, generating a target code document displayed on the front-end. This solution achieves automatic documentation of project code by automatically recognizing the semantically recognized code document and automatically generating the target code document, eliminating the need for manual annotation. By invoking a preset large model and a preset prompt word engineering strategy to understand the file data and project file format data, it achieves global contextual understanding. The document content maintains a high degree of consistency with the code content, effectively solving long-standing pain points such as document lag behind code and document-code disconnect, ensuring the accuracy and completeness of contextual understanding. The final generated target code document ensures that the extracted information is critical and important, guaranteeing the quality of document generation. New members can quickly understand the project structure and core logic through the system-generated target code documentation, shortening the learning cycle and improving the overall R&D efficiency of the team. An initial code document can be entered into a preset number of ports to generate target code documentation applicable to development, testing, architecture, and product teams, reducing repetitive work and improving cross-functional collaboration efficiency. The target microservice architecture facilitates deployment, monitoring, and upgrades. Preset prompts, engineering strategies, and preset large models are configurable and manageable, adapting to future technological evolution and business changes to ensure long-term system availability. Document generation is automatically triggered after the initial code document is submitted, achieving full-chain automation of "code submission - automatic document generation - document release," helping enterprises move towards a new paradigm of intelligent R&D.
[0040] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0041] In one embodiment, a code documentation generation apparatus based on a large model is provided, which corresponds one-to-one with the document generation method based on a large model in the above embodiments. For example... Figure 3 As shown, the code documentation generation device based on a large model includes an extraction module 11, a combination module 12, and a generation module 13. Detailed descriptions of each functional module are as follows: Extraction module 11 is used to receive an initial code document input by a preset interface and extract file data from the initial code document according to a preset file granularity; the initial code document contains project file format data. Combined with module 12, it is used to combine the file data with the project file format data corresponding to the initial document in context by calling the preset large model and preset prompt word engineering strategy, so as to generate a semantic recognition code document after completing semantic understanding and information recognition; The generation module 13 is used to return the semantic recognition code document to the front end corresponding to the preset interface for rendering processing, and then generate the target code document displayed on the front end.
[0042] Furthermore, the code documentation generation device based on the large model also includes: A building module is used to construct the target microservice entity using an interface-based design; the target microservice entity is used to generate the target code document on the front end in subsequent steps. The building module includes: The configuration submodule is used to configure a unified request and response format for all preset interfaces, expose the preset interfaces, and configure the access authentication mechanism of the preset interfaces to obtain the first microservice entity; The submodule is invoked to configure the preset interface to be invoked by a preset external system, thereby obtaining the second microservice entity; As a submodule, it is used to use the first microservice subject and the second microservice subject as the target microservice subject.
[0043] Furthermore, the extraction module includes: The first acquisition submodule is used to acquire the preset target path corresponding to the preset interface and use the target path as the starting point of the scan; The second acquisition submodule is used to traverse each folder storing the initial code document downwards from the starting point and obtain a complete file list; The recording submodule is used to construct a preset directory tree structure based on the file list, and record the hierarchical position of each of the initial code documents in the preset directory tree structure; The third acquisition submodule is used to acquire each of the initial code documents from the hierarchical positions.
[0044] Furthermore, the extraction module includes: The reading submodule is used to read all the contents of the initial code document according to the preset file granularity. The judgment submodule is used to determine whether the content of the initial code document is too long based on the size of all the content. The truncation submodule is used to automatically truncate a preset number of lines of content as valid content in chronological order if the file content of the initial code document exceeds a preset length. The encapsulation submodule is used to encapsulate the extracted valid content into a standard file data.
[0045] Furthermore, the code documentation generation device based on the large model includes: The grouping module is used to group all file data according to a preset batch number and obtain the grouping results; The encapsulation module is used to control the sending of a preset number of requests for each grouping result using a preset semaphore mechanism, and to encapsulate the file data in each initial code document into a request for a model call.
[0046] Furthermore, the combining module includes: The construction submodule is used to build preset prompt word templates; The input submodule is used to input the file data and the project file format data corresponding to the initial document into the preset prompt word template; The generation submodule is used to execute a preset inference process after the preset large model receives the preset prompt word template, and generate a semantic recognition code document corresponding to semantic understanding and information recognition.
[0047] Furthermore, the construction submodule includes: The acquisition unit is used to acquire pre-configured prompt word template parameters, and to acquire pre-configured system prompt words and knowledge bases corresponding to multiple preset large models; the preset large models are automatically switched; The assembly unit is used to dynamically construct the preset prompt word template according to the configuration information; the configuration information includes prompt word template parameters, system prompt words, and a knowledge base.
[0048] Specific limitations regarding the code documentation generation device based on large models can be found in the limitations of the document generation method based on large models mentioned above, and will not be repeated here. Each module in the aforementioned code documentation generation device based on large models can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0049] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data involved in a large-model-based document generation method. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a large-model-based document generation method.
[0050] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the document generation method based on a large model described in the above embodiments, for example... Figure 2 Steps S10 to S50 are shown below; Alternatively, when the processor executes a computer program, it implements the functions of each module / unit of the code document generation device based on the large model in the above embodiments, for example... Figure 3 The functions of modules 11 to 15 are shown. To avoid repetition, they will not be described again here.
[0051] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program implements the steps of the document generation method based on a large model described in the above embodiments, for example... Figure 2 Steps S10 to S50 are shown below; Alternatively, when the computer program is executed by the processor, it implements the functions of each module / unit of the code document generation device based on the large model in the above embodiments, for example... Figure 3 The functions of modules 11 to 15 are shown. To avoid repetition, they will not be described again here.
[0052] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0053] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0054] It should be noted that any AI models, software tools, or components not belonging to this company appearing in the embodiments of this application are merely illustrative examples and do not represent actual use. All user personal information involved in the embodiments of this application has been authorized (with the knowledge and consent) by the relevant parties or has been fully authorized by all parties, and the executing entity may obtain it through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.
[0055] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.< / token>
Claims
1. A document generation method based on a large model, characterized in that, include: Receive an initial code document input from a preset interface, and extract file data from the initial code document according to a preset file granularity; The initial code document contains project file format data; By invoking a preset large model and a preset prompt word engineering strategy, the file data is combined with the project file format data corresponding to the initial document in context, so as to generate a semantic recognition code document after completing semantic understanding and information recognition; After the semantic recognition code document is returned to the front end corresponding to the preset interface for rendering, a target code document is generated and displayed on the front end.
2. The document generation method based on a large model according to claim 1, characterized in that, Before receiving the initial code document input from the preset interface, the method further includes: An interface-based design is used to construct the target microservice entity; the target microservice entity is used to generate the target code document on the front end in subsequent steps. The method of constructing the target microservice entity using an interface-based design includes: Configure a unified request and response format for all preset interfaces, expose the preset interfaces, and configure the access authentication mechanism for the preset interfaces to obtain the first microservice entity; The preset interface is configured to be callable by a preset external system to obtain the second microservice entity; The first microservice entity and the second microservice entity are used as the target microservice entity.
3. The document generation method based on a large model according to claim 1, characterized in that, The receiving of the initial code document input from the preset interface includes: Obtain the preset target path corresponding to the preset interface, and use the target path as the starting point for scanning; After traversing each folder storing the initial code document downwards from the starting point, a complete file list is obtained; Construct a preset directory tree structure based on the file list, and record the hierarchical position of each initial code document in the preset directory tree structure; Obtain each of the initial code documents from the said hierarchical location.
4. The document generation method based on a large model according to claim 1, characterized in that, The step of extracting file data from the initial code document according to a preset file granularity includes: Read all the contents of the initial code document according to the preset file granularity; Based on the size of all the content, determine whether the content of the initial code document is too long; If the content of the initial code document exceeds the preset length, the preset number of lines will be automatically truncated as valid content in chronological order. The extracted valid content is packaged into a standard file data.
5. The document generation method based on a large model according to claim 1 or 4, characterized in that, After extracting file data from the initial code document according to a preset file granularity, the method further includes: Group all file data according to the preset batch number to obtain the grouping results; Using a preset semaphore mechanism to control the sending of a preset number of requests for each group result, and encapsulating the file data in each initial code document into a request for a model call.
6. The document generation method based on a large model according to claim 1, characterized in that, The process involves combining the file data with the project file format data corresponding to the initial document using a pre-defined large model and pre-defined prompt word engineering strategy to generate a semantic recognition code document after semantic understanding and information recognition are completed. This includes: Build a preset prompt word template; The file data and the project file format data corresponding to the initial document are passed to the preset prompt word template; After the preset large model receives the preset prompt word template, it executes a preset reasoning process to generate a semantic recognition code document corresponding to semantic understanding and information recognition.
7. The document generation method based on a large model according to claim 6, characterized in that, The construction of the preset prompt word template includes: Obtain pre-configured prompt word template parameters, and obtain pre-configured system prompt words and knowledge bases corresponding to multiple preset large models; automatically switch between the preset large models; The preset prompt word template is dynamically constructed based on the configuration information; the configuration information includes prompt word template parameters, system prompt words, and a knowledge base.
8. A code documentation generation device based on a large model, characterized in that, include: The extraction module is used to receive an initial code document input by a preset interface and extract file data from the initial code document according to a preset file granularity. The initial code document contains project file format data; The module is used to combine the file data with the project file format data corresponding to the initial document in context by calling the preset large model and preset prompt word engineering strategy, so as to generate a semantic recognition code document after completing semantic understanding and information recognition; The generation module is used to return the semantic recognition code document to the front end corresponding to the preset interface for rendering processing, and then generate the target code document displayed on the front end.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the document generation method based on a large model as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the document generation method based on a large model as described in any one of claims 1 to 7.