Numerical control machining instruction automatic generation method and system based on large model inference and routing chain template matching

CN123010591APending Publication Date: 2026-10-30武汉智能设计与数控技术创新中心 +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510490683.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-18
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

然而,这些解决方案在交互灵活性、参数确定的智能化程度以及代码生成的适应性方面仍有明显不足,用户依然需要具备相当的专业知识

Benefits of technology

[0030]降低对人工经验的依赖。传统的数控加工代码编写高度依赖工程师的个人经验和技能,容易引入错误和不一致。而本申请利用大模型推理技术,通过结构化的提示词工程框架(图3)引导大模型理解零件加工描述,并自动分解为单一工步并提取关键信息,大大减少了对人工判断和经验的依赖,使得非专业人员也能快速准确地完成复杂零件的加工代码生成。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123010591A_ABST
    Figure CN123010591A_ABST
Patent Text Reader

Abstract

The application relates to the field of numerical control turning machining and large model application, and discloses a numerical control machining instruction automatic generation method and system based on large model reasoning and routing chain template matching. The method comprises the following steps: receiving a part machining description in a text format, decomposing the part machining description into multiple single working steps by using large model reasoning, extracting machining key information, and generating a working step list; taking the machining key information in the working step list as a primary key, searching for similar machining parameters from a local knowledge base by using RAG technology, and forming a working step parameter list; constructing a routing chain containing prompt templates for different machining types, identifying machining types by using a large model, matching corresponding templates, and generating a numerical control machining code list; introducing a Memory function, fine-tuning and correcting the code in an interactive dialogue mode, and generating final numerical control machining code. The method reduces the dependence on artificial experience, improves the accuracy of machining parameters and the efficiency of code generation, and realizes the full-process automation of numerical control machining code writing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of CNC machining technology, and in particular to an automatic CNC machining instruction generation technology based on artificial intelligence. Background Technology

[0002] In modern manufacturing, CNC machine tools, as core equipment, are hailed as the "mother machines of industry," and their operational quality directly affects the precision and efficiency of product manufacturing. CNC machining code is the core instruction that drives these machine tools. It not only determines the execution method of the machining process but also affects the precision and production efficiency of the final product. In fact, it plays a crucial bridging role between product design, process planning, and physical manufacturing.

[0003] Currently, CNC machining codes in industrial production are mainly obtained in two ways: one is through manual programming by experienced engineers, and the other is through automatic generation using computer-aided manufacturing (CAM) software. Each method has its limitations.

[0004] Manual programming relies heavily on engineers' expertise and experience, resulting in low efficiency and a high learning and application barrier. Research indicates that programming alone can account for approximately 35% of total machining time in aerospace component processing (Journal of Mechanical Engineering, 2023 data). More seriously, parameter errors during manual programming (such as inappropriate feed rates or tool compensation values) can lead to severe consequences such as machine tool collisions or workpiece deviations.

[0005] To alleviate these problems, many CNC system companies have developed conversational programming software, such as Heidenhain's smarT.NC and Siemens' Shopturn. This type of software guides users through interactive menus to input machining requirements, simplifying the programming process. However, these solutions still have significant shortcomings in terms of interactive flexibility, the intelligence of parameter determination, and the adaptability of code generation; users still need considerable professional knowledge.

[0006] On the other hand, while CAM software can automatically generate machining paths and codes based on 3D models, it is usually expensive, has a steep learning curve, and still requires a lot of manual intervention and experience-based judgment during use. In addition, the post-processing configurations of different machine tool systems also increase the complexity of use.

[0007] Therefore, the manufacturing industry urgently needs a new method for generating CNC machining codes that can reduce reliance on human experience, simplify operating procedures, and ensure high efficiency and high quality in code generation, fundamentally solving the shortcomings of existing technologies in terms of flexibility, efficiency, and versatility. Summary of the Invention

[0008] The purpose of this application is to provide a method and system for automatically generating CNC machining instructions based on large model reasoning and routing chain template matching, so as to solve the problems mentioned in the background art.

[0009] This application discloses an automatic generation method for CNC machining instructions based on large model inference and routing chain template matching, including the following steps:

[0010] Receive a part processing description in text format, use large model inference to decompose the part processing description into multiple single processing steps and extract the key processing information of each processing step to generate a processing step list;

[0011] Using the key processing information in the process step list as the primary key, similar processing parameters are retrieved from the local knowledge base using retrieval enhancement generation RAG technology. Processing parameters are then generated for each process step through large model inference, forming a process step parameter list.

[0012] Construct a routing chain, which includes CNC code generation prompt templates for different machining types. Input a single machining step from the machining step parameter list into the routing chain. The large model identifies the machining type and matches the corresponding CNC code generation prompt template to generate CNC machining code for the single machining step. Integrate the CNC machining code to form a CNC machining code list.

[0013] A memory function is introduced to cache the generated CNC machining code list. The CNC machining code list is fine-tuned and corrected through interactive dialogue. All the corrected single-step CNC machining codes are grouped and organized to generate the final CNC machining code.

[0014] In a preferred embodiment, in the step of receiving a text-formatted part machining description, decomposing the part machining description into multiple individual machining steps using large-scale model inference, extracting key machining information for each step, and generating a list of machining steps, a prompt word engineering framework is employed to enhance the large-scale model's inference capabilities. This prompt word engineering framework includes: an input / output example module providing typical machining part descriptions and corresponding machining step decomposition specification examples; a rule constraint module embedding formatted output rules, machining step decomposition principles, and key information extraction principles; a Few-shot CoT module guiding the large-scale model's thinking through step-by-step inference examples to improve the accuracy of machining step decomposition and key information extraction; and a ReAct module guiding the large-scale model to reflect on the generated results, reflecting on and constraining inference errors to achieve iterative optimization of dynamic inference and execution verification.

[0015] In a preferred embodiment, the process of decomposing the part processing description into multiple individual steps using large model reasoning includes: constructing a prompt containing the prompt engineering framework; and inputting the part processing description text into a large model with enhanced reasoning capabilities for step decomposition and extraction of key processing information.

[0016] In a preferred embodiment, the list of work steps is output as a list of dictionaries.

[0017] In a preferred embodiment, in the steps of using the key processing information in the process step list as the primary key, retrieving similar processing parameters from the local knowledge base using retrieval enhancement generation (RAG) technology, and generating processing parameters for each process step through large model inference to form a process step parameter list, a local knowledge base is constructed by collecting processing parameters under different materials and processing types. Similar processing parameters are retrieved according to the process step list and provided as context to the large model, which then infers and generates the processing parameters.

[0018] In a preferred embodiment, the construction of the local knowledge base includes: using the processing key information as the primary key, collecting processing parameters under different processing states, and organizing them into a local knowledge base.

[0019] In a preferred embodiment, the CNC code generation prompt template in the routing chain is selected from the following group: naming conventions for process parameters, processing feature description frameworks, process constraint sets, and typical parameter value ranges. The prompt templates are used to name and describe the parameters and create corresponding target chains to address the CNC code generation rules under different processing types.

[0020] In a preferred embodiment, the CNC code generation prompt template includes: CNC code writing rules and formatted output requirements corresponding to the machining type.

[0021] In a preferred embodiment, the process of constructing the routing chain includes: designing a description of a prompt template for each processing type, the description including the template name, the matching method between the processing type corresponding to the template and the work step list, and the prompt word name corresponding to the template; the large model dynamically selects the corresponding prompt word based on the description of the prompt template.

[0022] In a preferred embodiment, the Memory function uses ConversationBufferWindowMemory to buffer window memory, summarize the past k rounds of dialogue, compress dialogue token consumption, and enable users to interactively fine-tune and correct the generated CNC machining code through dialogue.

[0023] In a preferred example, the complex process of writing CNC machining code based on the part to be processed is decomposed into three modules in the form of a large model workflow AI Workflow: step decomposition and key information extraction, machining parameter recommendation and CNC machining code generation. Each module is introduced into the large model through different methods and technologies to complete the intelligent and automatic realization of this complex task.

[0024] This application also discloses an automatic CNC machining instruction generation system based on large model inference and routing chain template matching, including:

[0025] The process decomposition module is used to receive a part processing description in text format, decompose the part processing description into multiple single processes using large model inference, extract the key processing information of each process, and generate a process list.

[0026] The parameter generation module is used to take the key processing information in the process step list as the primary key, retrieve similar processing parameters from the local knowledge base using the search-enhanced generation RAG technology, and generate processing parameters for each process step through large model inference to form a process step parameter list.

[0027] The code generation module is used to construct a routing chain. The routing chain contains CNC code generation prompt templates for different machining types. A single machining step from the machining step parameter list is input into the routing chain. The large model identifies the machining type and matches the corresponding CNC code generation prompt template to generate CNC machining code for the single machining step. The CNC machining code is then integrated to form a CNC machining code list.

[0028] The code optimization module introduces a memory function to cache the generated CNC machining code list. Through an interactive dialogue, the CNC machining code list is fine-tuned and corrected. All the corrected single-step CNC machining codes are grouped and organized to generate the final CNC machining code.

[0029] Compared with the prior art, this application has the following beneficial effects:

[0030] Reduce reliance on human experience. Traditional CNC machining code writing heavily relies on the engineer's personal experience and skills, easily introducing errors and inconsistencies. This application, however, utilizes large-model reasoning technology, through a structured prompt-based engineering framework (…). Figure 3 It guides the large model to understand the part machining description and automatically decomposes it into individual steps and extracts key information, greatly reducing the reliance on human judgment and experience, enabling non-professionals to quickly and accurately generate machining codes for complex parts.

[0031] Improve the accuracy of machining parameter selection. Previously, engineers needed to manually consult numerous manuals to determine suitable machining parameters. This application employs RAG (Retrieval Enhanced Generation) technology to intelligently retrieve similar machining cases from a local knowledge base for reference. Figure 2 Then, the large model performs reasoning optimization based on specific working conditions, which can quickly derive safe and reliable processing parameters and reduce the risk of repeated trial cuts and scrap.

[0032] Improve the efficiency of CNC code generation. Different machining operations require different CNC code structures, which places high demands on programmers. This application pre-designs CNC code generation prompt templates for different machining types. Figure 4 By constructing routing chains to achieve automatic matching, and leveraging the generalization capabilities of large models to flexibly generate specific code according to template rules, the workload of programmers is greatly reduced and programming efficiency is significantly improved.

[0033] Improve the standardization of CNC code. Manually written code often suffers from issues such as non-standard formatting and unclear comments, hindering subsequent maintenance and optimization. The code generated in this application strictly adheres to the industry standards preset in the prompt template. Figure 4 This includes aspects such as program structure, comment format, and variable naming, ultimately resulting in standardized code with a consistent style and high readability, which helps improve code maintainability.

[0034] Enhance the flexibility of human-computer interaction. Previous CNC programming software had a relatively rigid human-computer interaction, making it difficult to meet users' needs for secondary modifications. This application introduces a memory function... Figure 4 By caching user feedback through ConversationBufferWindowMemory and linking it to previously generated code, users can submit modification suggestions in natural language. The system can understand the context and make targeted optimizations, greatly improving the system's usability and flexibility.

[0035] In summary, this application, based on advanced technologies such as large model inference and routing chain template matching, achieves full automation of CNC machining code writing. Figure 2 This invention overcomes key technical challenges in process decomposition, parameter selection, and code generation, ensuring both programming quality and efficiency, and providing an innovative solution for the intelligent upgrading of the CNC machining industry. This application demonstrates significant technological advancement and practical value, and is expected to be widely applied in the industrial sector.

[0036] The specification of this application contains numerous technical features distributed across various technical solutions. Listing all possible combinations of these technical features (i.e., technical solutions) would make the specification excessively lengthy. To avoid this problem, the various technical features disclosed in the above-described invention, the various technical features disclosed in the following embodiments and examples, and the various technical features disclosed in the accompanying drawings can be freely combined to form various new technical solutions (all of which are considered to have been described in this specification), unless such a combination of technical features is technically infeasible. For example, one example discloses feature A+B+C, and another example discloses feature A+B+D+E. Features C and D are equivalent technical means that serve the same function, and technically only one needs to be used; they cannot be used simultaneously. Feature E can technically be combined with feature C. Therefore, the solution A+B+C+D should not be considered as described because it is technically infeasible, while the solution A+B+C+E should be considered as described. Attached Figure Description

[0037] Figure 1 This is an overall schematic diagram of a method for automatically generating CNC machining instructions based on large model reasoning and routing chain template matching according to an embodiment of this application;

[0038] Figure 2 This is a flowchart illustrating an automatic CNC machining instruction generation method based on large model inference and routing chain template matching according to an embodiment of this application.

[0039] Figure 3 This is a schematic diagram illustrating how the prompt word engineering framework enhances the large model reasoning capability in the automatic generation method of CNC machining instructions based on large model reasoning and routing chain template matching according to an embodiment of this application.

[0040] Figure 4 This is a schematic diagram of the retrieval enhancement generation RAG technology and routing chain template matching and memory function in the automatic generation method of CNC machining instructions based on large model reasoning and routing chain template matching according to an embodiment of this application;

[0041] Figure 5 This is a schematic diagram of the structure of an automatic CNC machining instruction generation system based on large model reasoning and routing chain template matching according to an embodiment of this application. Detailed Implementation

[0042] In the following description, many technical details are presented to help the reader better understand this application. However, those skilled in the art will understand that the technical solutions claimed in this application can be implemented even without these technical details and various variations and modifications based on the following embodiments.

[0043] Explanation of some concepts:

[0044] Large models: refers to large language models (LLMs), which are artificial intelligence models trained based on deep learning technology. They have the ability to understand natural language, generate text, and reason, such as DeepSeek-R1, GPT-4, and Claude.

[0045] RAG technology: refers to Retrieval-Augmented Generation, a method that combines information retrieval with text generation, enhancing the output quality and accuracy of large models by retrieving relevant information from external knowledge bases.

[0046] Routing chain: refers to a decision-making process system that can automatically select an appropriate processing template or path based on the characteristics of the input content. In this application, it specifically refers to a system that can automatically match the corresponding CNC code to generate a prompt template based on the machining type.

[0047] Prompt engineering refers to the techniques for designing and optimizing prompts for inputs to large models in order to guide them to produce more accurate outputs that better meet specific requirements.

[0048] A machining step refers to a single operation unit in a CNC machining process, such as external turning, drilling, or tapping. Each machining step has a clear machining objective and corresponding machining parameters.

[0049] Memory function: refers to the function of saving dialogue history in an artificial intelligence system and using historical information to enhance subsequent interactions. In this application, it specifically refers to dialogue memory mechanisms such as ConversationBufferWindowMemory.

[0050] Few-shot CoT: Refers to Few-shot Chain of Thought, a cue word technique that guides a large model to perform similar step-by-step thinking by showing it a small number of examples containing reasoning processes.

[0051] ReAct: Refers to the Reflection-Action framework, a method to improve the reasoning ability of large models by guiding them to reflect on and correct their own outputs, thereby improving the accuracy of reasoning.

[0052] The following is a brief summary of some of the innovative aspects of this application:

[0053] In summary, the automatic CNC machining instruction generation method proposed in this application, based on large-model reasoning and routing chain template matching, cleverly solves the technical barriers of traditional CNC machining code generation, such as strong reliance on human experience, difficulty in parameter determination, and low programming efficiency, by constructing an unprecedented cross-domain fusion technology system. Specifically, in step S100, this application does not simply use a large model to process text input, but constructs a system consisting of an input / output example module, a rule constraint module, a Few-shot CoT module, and a ReAct module. Figure 3 A multi-layered, progressive prompting word engineering framework, consisting of [missing information], guides large models to overcome domain cognitive limitations, achieving precise deconstruction and key information extraction from complex processing descriptions; based on this, the RAG technology applied in step S200 [missing information]... Figure 2 The combination of this mechanism and a local knowledge base forms a nonlinear parameter retrieval-reasoning mechanism. By using the key processing information in the process step list as the retrieval key, it extracts professional parameter knowledge from the local knowledge base, providing domain constraints for the large model and thus avoiding the "illusion" problem in the generation of professional parameters in the large model; the routing chain structure designed in step S300 ( Figure 4 This achieves a technological breakthrough in dynamic perception and template matching, enabling the system to intelligently identify the machining type and call the corresponding CNC code to generate prompt templates based on the machining semantics contained in the step parameter list, forming a highly specific code generation mechanism; finally, the ConversationBufferWindowMemory function introduced in step S400 ( Figure 4 A context-aware interactive code optimization mechanism was constructed, which achieves efficient information exchange and iterative code optimization between users and the system by caching historical interaction information and extracting key semantics. The four steps described above form a progressive and mutually empowering technological synergy, organically integrating seemingly independent steps such as process decomposition, parameter recommendation, code generation, and interaction optimization into a self-consistent technical whole. This achieves fully automated conversion from part text description to final CNC machining code, significantly lowering the threshold for CNC programming and improving code generation efficiency and quality, providing a new paradigm for technological innovation in the field of CNC machining.

[0054] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0055] The first embodiment of this application relates to a method for automatically generating CNC machining instructions based on large model inference and routing chain template matching, the process of which is as follows: Figure 1 As shown, the method includes the following steps:

[0056] Example

[0057] This embodiment proposes an automatic generation method for CNC machining instructions based on large model inference and routing chain template matching, such as... Figure 1 As shown, it includes the following steps:

[0058] S100: Receive a part processing description in text format, use large model inference to decompose the part processing description into multiple single processing steps and extract the key processing information of each processing step to generate a processing step list.

[0059] S200: Using the key processing information in the process step list as the primary key, retrieve similar processing parameters from the local knowledge base using the retrieval enhancement generation RAG technology, and generate processing parameters for each process step through large model inference to form a process step parameter list.

[0060] S300: Construct a routing chain, which includes CNC code generation prompt templates for different machining types. Input a single machining step from the machining step parameter list into the routing chain. The large model identifies the machining type and matches the corresponding CNC code generation prompt template to generate CNC machining code for the single machining step. These are then integrated to form a CNC machining code list.

[0061] S400: Introduces a Memory function to cache the generated CNC machining code list. Through interactive dialogue, the CNC machining code list is fine-tuned and corrected. All the corrected single-step CNC machining codes are grouped and organized to generate the final CNC machining code.

[0062] In summary, the automatic CNC machining instruction generation method based on large model inference and routing chain template matching in this embodiment decomposes the complex CNC machining code generation process into four key steps. First, the large model intelligently parses the part description into structured machining step information; then, RAG technology accurately matches suitable machining parameters from a professional knowledge base; next, an adaptive routing chain generates corresponding CNC codes for different types of machining operations; finally, an interactive interface allows users to fine-tune and optimize the code, ensuring its accuracy and applicability. This method reduces the reliance on human experience in CNC programming, improves programming efficiency and quality, and provides an innovative automated solution for the CNC machining field.

[0063] The steps described above will be explained in further detail below.

[0064] Optional, such as Figure 3As shown, in step S100, a prompt word engineering framework is used to enhance the reasoning capability of the large model. The prompt word engineering framework includes: an input / output example module, which provides typical machining part descriptions and corresponding process step decomposition specification cases; a rule constraint module, which embeds formatted output rules, process step decomposition principles, and key information extraction principles; a Few-shot CoT module, which guides the large model to think through step-by-step reasoning examples, improving the accuracy of process step decomposition and key information extraction; and a ReAct module, which guides the large model to reflect on the generated results, reflects on and constrains the reasoning error part, and realizes iterative optimization of dynamic reasoning and execution verification.

[0065] Specifically, the prompting word engineering framework primarily addresses the issue of large models lacking sufficient understanding of CNC machining expertise. The input / output example module contains pre-defined part machining descriptions and corresponding step decomposition examples. For instance, a machining description like "turning a 50mm diameter 45 steel cylindrical blank into a stepped shaft, with the first segment having a diameter of 45mm and a length of 30mm; and the second segment having a diameter of 40mm and a length of 25mm" is decomposed into steps such as rough turning the outer diameter, finish turning the first segment, and finish turning the second segment. The rule constraint module explicitly stipulates that the output format must be JSON or a list of Python dictionaries, and each step must include key fields such as "machining type" and "blank material." The Few-shot CoT module demonstrates step-by-step reasoning through examples: "First, analyze the structural features of the part, identify two steps that need to be machined separately..." etc., helping large models understand the CNC machining process. The ReAct module sets up a reflection mechanism for common errors, such as "checking if the contour description is complete," "checking if the tool change point setting is missing," and "reconfirming if the feed direction is correct," improving the accuracy of the output results.

[0066] Optionally, the process of decomposing the part processing description into multiple individual steps using large model reasoning includes: constructing a prompt word Prompt containing the prompt word engineering framework; and inputting the part processing description text into a large model with enhanced reasoning capabilities for step decomposition and extraction of key processing information.

[0067] Specifically, in practice, the four modules mentioned above (input / output examples, rule constraints, Few-shotCoT, and ReAct) are first integrated into a structured prompt. This prompt typically contains 3-5 examples, clear formatting guidelines, and reasoning guidance statements, such as: "Please analyze the following part machining description step by step, extract key information, and break it down into single machining steps...". Then, the user-inputted part machining description, along with this prompt, is input into a large model like DeepSeek-R1. Guided by the prompt, the large model analyzes the part description text, identifies information such as material, dimensions, and precision, and decomposes the complex machining task into a series of logically coherent single machining steps, such as roughing, finishing, drilling, and tapping, while extracting the key parameters required for each step.

[0068] It should be noted that although the DeepSeek-R1 large model is used in this embodiment, those skilled in the art should understand that other large models with similar reasoning capabilities, such as GPT-4 and Claude, can also be used to achieve the same function.

[0069] Optionally, the list of work steps is output as a list of dictionaries. (Corresponding to...) Figure 3 )

[0070] Specifically, the work step list is output in a structured dictionary list format, where each work step is represented as a dictionary containing multiple key-value pairs. For example:

[0071]

[0072]

[0073] This dictionary list structure facilitates subsequent program processing and parameter retrieval. Each step dictionary contains all the key information for that step, which is beneficial for both data transfer and manual inspection and modification.

[0074] Optional, such as Figure 2 and Figure 4 As shown, in step S200, a local knowledge base is constructed by collecting processing parameters under different materials and processing types. Similar processing parameters are retrieved according to the process step list and provided as context to the large model, which then infers and generates the processing parameters.

[0075] Specifically, RAG (Retrieval Enhanced Generation) technology primarily addresses the issue of large models generating parameters that do not meet actual machining requirements. The local knowledge base contains recommended machining parameters for various materials (such as 45 steel, 304 stainless steel, aluminum alloys, etc.) under different machining types (such as roughing, finishing, drilling, etc.), including cutting speed, feed rate, and depth of cut. After obtaining the step list for step S100, the system retrieves the most similar machining cases from the knowledge base based on key fields such as "machining type" and "stock material." For example, if the step list contains "machining type: finishing outer diameter, stock material: 45 steel," the system will retrieve all recommended parameters for finishing outer diameter of 45 steel. These search results are input as contextual information into the large model. Based on these authoritative parameters, combined with specific workpiece dimensions and accuracy requirements, the large model generates specific parameters suitable for the current machining task, such as "spindle speed: 800 rpm, feed rate: 0.2 mm / r."

[0076] Optionally, the construction of the local knowledge base includes: using the processing key information as the primary key, collecting processing parameters under different processing states, and organizing them into a local knowledge base.

[0077] Specifically, the local knowledge base is organized in the form of text tables or CSV files, using combinations of key processing information as the primary key and corresponding processing parameters as the search values. For example, the primary key could be "45 steel, finish turning outer diameter (Ra1.6)", with corresponding values ​​being a set of recommended parameters such as "cutting speed": "120-150m / min", "feed rate": "0.1-0.15mm / r", and "depth of cut": "0.5-1.0mm". This data comes from professional CNC machining manuals, successful historical cases, and the experience of domain experts. By combining multi-dimensional information such as different materials, different machining types, and different precision requirements into primary keys, a comprehensive parameter knowledge base is formed, ensuring accurate parameter recommendations for various machining situations. In practical applications, the system constructs the query primary key based on the key information extracted by S100 and retrieves the most matching parameter record from the knowledge base.

[0078] Optional, such as Figure 4 As shown, the CNC code generation prompt templates in the routing chain are selected from the following group: naming conventions for process parameters, processing feature description frameworks, process constraint sets, and typical parameter value ranges. Based on these prompt templates, naming and description are performed, and corresponding target chains are created to address the CNC code generation rules under different processing types. (Corresponding to...) Figure 4 )

[0079] Specifically, the routing chain is a specialized template system designed for different machining types. For example, turning and drilling require different CNC code structures and parameter settings. The naming conventions for process parameters define the standard names of each parameter in the template; for example, "cutting speed" is uniformly named "CUT_SPEED," ensuring consistency in code generation. The machining feature description framework specifies how to describe various machining features, such as external turning and internal hole machining, including the expression of elements such as start point, end point, path, and parameters. These template elements collectively form the foundation of the routing chain, providing a customized code generation framework for different machining types.

[0080] Optionally, the CNC code generation prompt template includes: CNC code writing rules and formatted output requirements corresponding to the machining type.

[0081] Specifically, different machining types require different CNC code writing rules. For example, turning operations typically use linear and circular interpolation commands such as G01, G02, and G03, while drilling operations may use fixed cycle commands such as G81 and G83. The prompt template clearly specifies the rules for G-code selection, coordinate system, and tool compensation settings for various machining operations. Formatted output requirements specify the format standards for generated code, including program structure (such as program number, program start and end markers), comment format, and code indentation rules. For example, the template might specify: "Turning programs must begin with % and end with M30, and each machining step must be preceded by a comment explaining the function of that step." These rules and requirements ensure that the generated CNC code conforms to industry standards and machine tool requirements, and can be used directly or with only minor modifications.

[0082] Optionally, the process of constructing the routing chain includes: designing a description of a prompt template for each processing type, the description including the template name, the matching method between the processing type corresponding to the template and the work step list, and the prompt word name corresponding to the template; the large model dynamically selects the corresponding prompt word based on the description of the prompt template.

[0083] Specifically, the construction of the routing chain is a systematic process. First, prompt template descriptions are designed for common machining types such as external turning, face turning, threading, and drilling. For example, the template description for rough turning of external turning might be: "Name: External Turning Roughing Template; Matching Conditions: The 'Machining Type' in the step contains 'External Diameter' or 'External Diameter' and 'Roughing' or 'Rough Turning,' but does not contain 'Thread' or 'Forming,' and has no description of 'Retraction Amount' or 'Single-Step Cutting Depth'; Corresponding Prompt: od_single_cutting_template." These descriptions form the decision nodes of the routing chain. When the list of machining step parameters generated in step S200 is input into the routing chain, the large model analyzes the parameters of each machining step, especially the "Machining Type" field, and compares them with the matching conditions of each template description. For example, if the machining step contains "Machining Type: Finish Turning External Diameter," the large model will recognize that this is an external turning operation and automatically select "od_loop_cutting_template" as the prompt word for generating the CNC code for that machining step. This dynamic matching mechanism enables the system to intelligently handle various processing types and select the most suitable code generation template for each type.

[0084] Optional, such as Figure 4 As shown, the Memory function uses ConversationBufferWindowMemory to buffer window memory, summarize the past k rounds of dialogue, compress dialogue token consumption, and enable users to interactively fine-tune and correct the generated CNC machining code through dialogue.

[0085] Specifically, the Memory function is essentially a dialogue history management mechanism that allows the system to "remember" previous interactions. ConversationBufferWindowMemory is a specific type of memory mechanism that stores the most recent k rounds of dialogue (typically k = 3 to 5) and provides this history as context for each new dialogue. In practical applications, the system first displays the generated CNC machining code to the user, who can then provide modification suggestions via natural language, such as "Please change the feed rate of the first step to 0.15 mm / r" or "The safety height of the second step is too low; please increase it to Z50." The system remembers the user's requirements and the previously generated code, making targeted modifications instead of regenerating the entire code. This interactive modification process significantly improves the efficiency of code optimization, allowing even non-professionals to adjust technical parameters through simple dialogue. Simultaneously, by summarizing key points of the dialogue rather than storing the entire dialogue, token consumption can be effectively reduced, improving system response speed.

[0086] Optionally, in the form of a large-scale model AI Workflow, the complex process of writing CNC machining code based on the part to be processed can be decomposed into three modules: step decomposition and key information extraction, machining parameter recommendation and CNC machining code generation. These modules are then introduced into the large model through different methods and technologies to achieve the intelligent and automatic realization of this complex task.

[0087] Specifically, this application adopts a modular design approach, decomposing the complex CNC machining code generation task into three relatively independent but collaborative functional modules. The step decomposition and key information extraction module is responsible for understanding the user-input part description and breaking down the complex machining task into executable single steps; the machining parameter recommendation module provides reasonable process parameters for each step based on a professional knowledge base; and the CNC machining code generation module generates standard-compliant CNC code based on the outputs of the first two modules. These three modules form a complete workflow, with data transferred between modules in a structured form. Each module incorporates a large model but employs different techniques: the first module focuses on using prompt word engineering to enhance the understanding of the large model; the second module relies on RAG technology combined with a professional knowledge base to supplement the domain knowledge of the large model; and the third module utilizes routing chains and template matching to improve the accuracy of code generation. Finally, the entire system provides an interactive interface through a memory function, allowing users to easily adjust and optimize the generated results. This modular design not only makes the system structure clear but also facilitates future optimization or expansion for specific modules, improving the system's maintainability and scalability.

[0088] Application Examples

[0089] To more intuitively demonstrate the workflow and technical effects of this application, a complete application example is provided below, showcasing the entire process from user input to final CNC machining code generation:

[0090] Here is a complete application example:

[0091] The user input: "Machining a 60mm diameter, 80mm long 45 steel cylindrical blank into a stepped shaft, with the first section having a diameter of 50mm and a length of 30mm, the second section having a diameter of 40mm and a length of 25mm, and the third section having an M16×1.5 thread and a length of 20mm."

[0092] The system breaks down steps into a list of steps using step S100: [

[0094] {

[0095] "Work Step Number": 1,

[0096] "Processing type": "Rough turning of outer diameter"

[0097] "Raw material": "45 steel"

[0098] "Contour Description": "Straight line, [0, 50], [80, 50]"

[0099] },

[0100] {

[0101] "Process Step Number": 2

[0102] "Machining Type": "Precision turning of outer diameter (Ra1.6)"

[0103] "Raw material": "45 steel"

[0104] "Contour Description": "Contour 1, straight line, [0, 40], [25, 40]; Contour 2, straight line, [25, 40], [25, 50]; Contour 3, straight line, [25, 50], [55, 50];"

[0105] },

[0106] {

[0107] "Process Step Number": 3

[0108] "Machining Type": "M16×1.5 Thread Machining"

[0109] "Raw material": "45 steel"

[0110] "Outline Description": "Straight line, [55, 50], [75, 50]"

[0111] } ]

[0113] The S200 step generates machining parameters. RAG retrieves 45 steel machining parameters from the knowledge base and recommends the following process parameters for roughing: "cutting speed: 120m / min, feed rate: 0.2mm / r, depth of cut: 2mm", "cutting speed: 150m / min, feed rate: 0.1mm / r, depth of cut: 0.5mm" for finishing, and "cutting speed: 100m / min, thread cutting feed: 1.5mm / r" for threading.

[0114] The S300 process generates CNC codes for each step, and the routing chain intelligently identifies the type of each step and matches the appropriate code generation template, ultimately integrating them into a complete program.

[0115] %

[0116] O0001 (Stepped Shaft Machining Program)

[0117] N10 G21 G40 G90 G94 (Unit: mm, tool offset disabled, absolute coordinates, feed rate mm / min)

[0118] N20 G28 U0 W0 (Return to reference point)

[0119] N30 T0101 (Roughing Tool)

[0120] N40 G96 S10020 M03 (Constant surface speed cutting, 120m / min, spindle forward rotation)

[0121] N50 G00 X65 Z2 (Quickly move to the starting point)

[0122] N60 (Rough turning of the outer diameter)

[0123] N70 G71 U2 R1 (G71 cycle, depth of cut 2mm, retraction 1mm)

[0124] N80 G71 P90 Q130 U0.5 W0.1 F0.2 (Roughing cycle, leaving finishing allowance)

[0125] N90 G00 X52 Z0 (Outline Start Point)

[0126] N100 G01 Z-30F0.2 (First outline)

[0127] N110 X42 (Second outline)

[0128] N120 Z-55 (Second outline)

[0129] N130 X32 Z-75 (Third Segment Outline)

[0130] N140 G00 X100 Z100 (Retract the tool to a safe position)

[0131] (Subsequent finishing and threading codes)

[0132] N400 M30 (Program End)

[0133] %

[0134] The user adjusted the settings via the S400 steps: "Please increase the retraction amount of the threaded section; the original retraction amount was too small and may affect the thread quality."

[0135] The system responded: "I have increased the retraction amount of the threaded section from 0.5mm to 1mm and adjusted the code accordingly."

[0136] Ultimately, the system generated modified CNC machining code, resolving the user's concern about the retraction amount in thread machining and ensuring machining quality and safety.

[0137] This complete application example demonstrates how this application automatically transforms complex part machining tasks into accurate CNC machining code. The entire process not only reduces reliance on human experience but also provides flexibility and reliability through interactive adjustment functions, fully showcasing the technical advantages and application value of this application.

[0138] To better understand the technical solution of this application, a specific example is provided below. The details listed in this example are mainly for ease of understanding and are not intended to limit the scope of protection of this application.

[0139] This example addresses the problems of existing CNC machining practices, such as reliance on manual experience in CNC program writing, poor adaptability and complex operation of CAM software, and low code generation efficiency. It proposes an automatic CNC machining instruction generation method based on large-model reasoning and routing chain template matching. This method can autonomously extract machining processes and key information based on the part description input by process engineers or machining operators and the workflow designed in this example. It intelligently recommends machining process parameters, intelligently matches CNC machining code example templates, and automatically generates CNC machining code, thus solving the problems of difficult and inconvenient operation of CAM software to some extent. Furthermore, process engineers or machining operators do not need to manually write CNC machining code and can obtain guidance based on past experience in the large model and knowledge base. This can save time to a certain extent, reduce parameter errors (such as feed rate and tool compensation) introduced by manual intervention, and effectively lower the threshold for CNC machining code writing, improving the efficiency and quality of CNC code writing. Therefore, the proposed automatic CNC machining instruction generation method based on large-model reasoning and routing chain template matching leads to higher efficiency and quality in CNC machining code generation.

[0140] This example provides an automatic CNC machining instruction generation method based on large-model reasoning and routing chain template matching. The method includes: first, inputting a text description of the machining part with specific formatting requirements; leveraging the reasoning capabilities of the large model and the reasoning enhancement of prompt word engineering to decompose complex machining tasks and extract key machining information, with the decomposition results output in list form; then, using RAG (Retrieval Enhanced Generation) technology to intelligently match machining parameters from a local knowledge base to generate a list of machining step parameters; next, by designing a routing chain, different CNC code generation prompt templates are written for each machining type, and with the help of the large model, the corresponding CNC code generation template is intelligently matched to each column in the list of machining step parameters to complete the initial generation and integration of CNC machining codes for different machining types; finally, a Memory function is introduced, allowing users of this example to interact with the large model to fine-tune and modify the generated CNC machining codes until they are satisfied.

[0141] Preferably, in this example, a large-scale model workflow (AI Workflow) is adopted to decompose the complex process of writing CNC machining code based on the part to be processed into three modules: step decomposition and key information extraction, and machining parameter recommendation and CNC machining code generation. These modules are introduced into the large model through different methods and technologies to achieve intelligent and automated implementation of this complex task. This example decomposes the complex text-formatted part machining description into single steps, extracts effective content related to the CNC machining code according to the key machining information specified in the template, and uses a formatted information flow as the standard for information transmission between different modules. Then, RAG technology is used to recommend and determine the most critical machining parameters in the CNC machining code based on the professional knowledge of CNC machining provided by the local knowledge base. Finally, leveraging the routing chain and the perception capabilities of the large model, the CNC machining code for each single step is intelligently generated, and then merged according to the code standard to obtain the final code for the entire complex step.

[0142] Preferably, in this example, for the first working module, the decomposition of processing steps and extraction of key information employ a cue word engineering framework to enhance the reasoning capabilities of the large model:

[0143] 1. Input / Output Example Module: Provides typical machining part descriptions and corresponding process decomposition and key information extraction standard examples for reference in large model learning;

[0144] 2. Rule Constraint Module: Embeds formatted output rules, work step decomposition principles, and key information extraction principles;

[0145] 3. Few-shot Chain-of-Thought (Few-shot CoT) module: Guides the large model's thinking through step-by-step reasoning examples, demonstrations, and summaries of the thinking process, enhancing the large model's reasoning ability and improving the accuracy of step decomposition and key information extraction;

[0146] 4. ReAct (Reflection and Correction) Module: Through prompt word engineering, it guides the large model to reflect on and generate results, and applies reflective constraints to parts that are prone to inference errors in repeated experiments, realizing iterative optimization of dynamic inference and execution verification, and further improving the accuracy of step decomposition and key information extraction.

[0147] The above templates work together to guide the large model in generating a reasonable and accurate list of work steps.

[0148] Preferably, in this example, the RAG external knowledge base technology is used to build a local knowledge base by collecting processing parameters under different materials and processing types. Then, similar processing parameters are retrieved according to the process step list and provided as context to the large model. Finally, the large model infers and generates processing parameters, and combines the process step list to generate a process step parameter list.

[0149] Preferably, in this example, a routing chain architecture is adopted, defining prompt templates for different processing types, selected from the following group: naming conventions for process parameters, processing feature description frameworks, etc.; based on the prompt templates, naming and description are performed, and corresponding target chains are created to complete the construction of the routing chain, in order to cope with the rules for G-code generation under different processing types.

[0150] Preferably, in this example, the memory function of the Langchain framework is used. Using ConversationBufferWindowMemory, the summary of the previous k rounds of dialogue is compiled, reducing dialogue token consumption. This allows the user to interactively fine-tune and correct the generated CNC machining code through dialogue. After confirming that everything is correct, the CNC machining code generated from all the single-step parameter lists is grouped and organized to generate the final CNC machining code for complex machining steps that satisfies the user.

[0151] More specifically, Figure 2This example patent presents an overall flowchart. This implementation first takes a text description of the complex part's machining steps, formatted according to specific requirements, as input. Then, based on the principles of Prompt engineering and Prompt techniques such as Few-shot CoT and ReAct to enhance reasoning capabilities, a suitable Prompt is written. This guides the large model to decompose the complex machining step description into multiple individual steps according to the prompt rules, extracting key information such as "processing type" and "raw material." The large model is then specified to output a list of machining steps in the form of a dictionary. Next, using the key information from the previous step as the dataset's primary key, machining parameters are collected as a local knowledge base. Then, using RAG technology, similar machining parameters are retrieved for each step in the list and passed as context to the large model. The large model then infers the machining parameters for each step and outputs a list of machining parameters in list format. Next, based on different machining types and CNC machining code writing standards, different prompt templates for different machining types are designed. At the same time, referring to the large model Agent, a routing chain with autonomous perception and prompt template descriptions for different machining types are designed for intelligent perception. Then, the single machining step is input into the routing chain, and the large model performs template intelligent perception and matching, and generates the CNC machining code for this machining step according to the prompt template, and integrates them into a CNC machining code list. Finally, a memory function is introduced to provide an interface for users to interact with the large model. Users can continuously communicate and fine-tune the output CNC machining code until they are satisfied and output the final CNC machining code.

[0152] The entire implementation process is as follows:

[0153] First, the input part description is decomposed into work steps and key information is extracted using a large model. A standard input structure and examples are designed to specify the input specifications for work step descriptions. These must include structured fields such as blank material and dimension descriptions, machining type and step description for each step, tool change points, and safety distances, assisting users in inputting complete part work step descriptions. Next, a prompt is constructed for the large model to decompose work steps and extract key information. The large model often struggles to accurately distinguish between work steps and key information when decomposing complex steps, resulting in inconsistent output formats. Therefore, a prompt containing rules, examples, and reasoning enhancement hints is needed to guide the large model's reasoning. The rules specify formatted output and clearly state that the large model should not output redundant thinking, specifying the basis for work step decomposition and the key machining information to be extracted. Examples should conform to the rule-specified format and cover as many decomposition scenarios as possible for the large model to learn from. Reasoning enhancement hints utilize Few-shot CoT and ReAct technologies. Few-shot CoT is a prompt that guides a large model through step-by-step thinking. By prompting "Please think step by step and demonstrate your thought process," it enhances the model's reasoning ability. The thought process is then used as the context input for the Few-shot prompt, summarizing the final result and maximizing the model's reasoning capability while ensuring formatted output. ReAct technology summarizes error-prone parts from multiple decomposition steps and prompts the model to check these error-prone areas and determine whether to rethink based on relevant rules, improving the accuracy of the decomposition. DeepSeek-R1 is used as the core processing engine, inputting the part description text to be decomposed along with the prompt into the large model, ultimately outputting a high-precision list of steps. This step corresponds to... Figure 3 The part of the standardized complex process step input to output single process step flowchart.

[0154] Then, RAG (Retrieval-Generation Augmentation) technology is used to recommend processing parameters through a large model. RAG is an artificial intelligence technology that combines information retrieval with text generation. Its core idea is to retrieve relevant content from external knowledge bases (such as documents, databases, and the Internet) before generating an answer, and then generate a more accurate and credible answer based on the retrieved information. It can effectively solve the limitations of generative models. For example, traditional generative models (such as GPT) rely on knowledge in pre-trained parameters, which is prone to "illusions" (fabricating facts) or outdated knowledge. RAG enhances the reliability of the generated results by retrieving real-time data. The determination of processing parameters depends on human experience and actual processing results. In order to further reduce the dependence of CNC machining code writing on humans, this example uses the key information in step one as a marker to identify different processing states, collects processing parameters under different processing states, and organizes them into a local knowledge base. For the list of work steps output in step one, a single work step is extracted in a loop, and the key information in it is retrieved from the local knowledge base. The processing parameters of similar processing states retrieved are used as context input to the large model to infer the processing parameters of the current processing state and organize them into a list of work step parameters for output.

[0155] Then, a routing chain is constructed to assist the large-scale model in intelligently perceiving single machining step templates and generating CNC machining code. Referring to the large-scale model Agent framework, a routing chain is designed, and for each machining type, different code generation prompts and template descriptions are designed. The template description should include the template name, a description of how the template matches the machining type and the list of machining steps, and the corresponding prompt name. The large-scale model dynamically selects the corresponding prompt based on the template description. The code generation prompt should include the CNC machining code writing rules and formatted output requirements for that machining type. The system sequentially identifies the input single machining step through the intelligent perception module, dynamically matches it within the routing chain, calls the corresponding prompt template to drive the large-scale model to generate the CNC machining code for that step, and finally integrates all the machining step codes into a complete list of CNC machining programs. This step corresponds to... Figure 4 A portion of the flowchart for generating preliminary CNC machining code in a single process step.

[0156] Finally, a memory function is introduced, using ConversationBufferWindowMemory to cache the CNC machining code generated in the last conversation. This allows users to actively correct and fine-tune the CNC machining code generated by the system through interactive dialogue until they are satisfied. This improves the interactivity and flexibility of the system.

[0157] This example employs techniques from the Prompt project to enhance the reasoning capabilities of large models and standardize input and output. It processes text-based part descriptions, decomposes machining steps, and extracts key machining information. RAG technology is used to reduce the "illusion" phenomenon of large models, enabling intelligent and accurate recommendation of machining parameters and reducing reliance on human intervention in parameter determination. Simultaneously, referencing the Agent framework, it leverages the perception capabilities of large models to construct routing chains and generate Prompts for CNC machining codes of different types, achieving intelligent generation of CNC machining codes for various machining types. Memory capabilities are also introduced to enhance the interactivity and flexibility of this example. This example allows for direct text-based input of part descriptions during CNC machining without human intervention, lowering the barrier to entry and complexity. It recommends machining parameters to engineers based on prior professional knowledge, reducing reliance on human experience and lowering the barrier to entry for CNC machining code writing. Furthermore, it automatically generates CNC machining code, significantly improving the quality and efficiency of machining parameter determination during CNC code writing.

[0158] The second embodiment of this application relates to an automatic CNC machining instruction generation system based on large model inference and routing chain template matching, the structure of which is as follows: Figure 5 As shown, this automatic CNC machining instruction generation system based on large model inference and routing chain template matching includes:

[0159] The process decomposition module is used to receive a part processing description in text format, decompose the part processing description into multiple single processes using large model inference, extract the key processing information of each process, and generate a process list.

[0160] The parameter generation module is used to take the key processing information in the process step list as the primary key, retrieve similar processing parameters from the local knowledge base using the search-enhanced generation RAG technology, and generate processing parameters for each process step through large model inference to form a process step parameter list.

[0161] The code generation module is used to construct a routing chain. The routing chain contains CNC code generation prompt templates for different machining types. A single machining step from the machining step parameter list is input into the routing chain. The large model identifies the machining type and matches the corresponding CNC code generation prompt template to generate CNC machining code for the single machining step. The CNC machining code is then integrated to form a CNC machining code list.

[0162] The code optimization module introduces a memory function to cache the generated CNC machining code list. Through an interactive dialogue, the CNC machining code list is fine-tuned and corrected. All the corrected single-step CNC machining codes are grouped and organized to generate the final CNC machining code.

[0163] The first embodiment is a method embodiment corresponding to this embodiment. The technical details in the first embodiment can be applied to this embodiment, and the technical details in this embodiment can also be applied to the first embodiment.

[0164] The above embodiments have the following technical effects:

[0165] Reduce reliance on human experience. Traditional CNC machining code writing heavily relies on the engineer's personal experience and skills, easily introducing errors and inconsistencies. The above embodiment, however, utilizes large model reasoning technology, through a structured prompt-based engineering framework (…). Figure 3 It guides the large model to understand the part machining description and automatically decomposes it into individual steps and extracts key information, greatly reducing the reliance on human judgment and experience, enabling non-professionals to quickly and accurately generate machining codes for complex parts.

[0166] Improve the accuracy of machining parameter selection. Previously, engineers needed to manually consult numerous manuals to determine suitable machining parameters. The above embodiment employs RAG (Retrieval Enhanced Generation) technology, intelligently retrieving similar machining cases from a local knowledge base for reference. Figure 2 Then, the large model performs reasoning optimization based on specific working conditions, which can quickly derive safe and reliable processing parameters and reduce the risk of repeated trial cuts and scrap.

[0167] Improve the efficiency of CNC code generation. Different machining operations require different CNC code structures, which places high demands on programmers. The above embodiment pre-designs CNC code generation prompt templates for different machining types. Figure 4 By constructing routing chains to achieve automatic matching, and leveraging the generalization capabilities of large models to flexibly generate specific code according to template rules, the workload of programmers is greatly reduced and programming efficiency is significantly improved.

[0168] Improve the standardization of CNC code. Manually written code often suffers from issues such as non-standard formatting and unclear comments, hindering subsequent maintenance and optimization. The code generated in the above embodiments strictly adheres to the industry standards preset in the prompt template. Figure 4 This includes aspects such as program structure, comment format, and variable naming, ultimately resulting in standardized code with a consistent style and high readability, which helps improve code maintainability.

[0169] Enhance the flexibility of human-computer interaction. Previous CNC programming software had a relatively rigid human-computer interaction, making it difficult to meet users' needs for secondary modifications. The above embodiment introduces a memory function. Figure 4By caching user feedback through ConversationBufferWindowMemory and linking it to previously generated code, users can submit modification suggestions in natural language. The system can understand the context and make targeted optimizations, greatly improving the system's usability and flexibility.

[0170] In summary, the above embodiments, based on advanced technologies such as large model inference and routing chain template matching, have achieved full automation of the CNC machining code writing process. Figure 2 This invention overcomes key technical challenges in process decomposition, parameter selection, and code generation, ensuring both programming quality and efficiency, and providing an innovative solution for the intelligent upgrading of the CNC machining industry. The above embodiments demonstrate significant technological advancement and practical value, and are expected to be widely applied in the industrial field.

[0171] It should be noted that those skilled in the art should understand that the implementation functions of each module shown in the above-described embodiments of the CNC machining instruction automatic generation system based on large model inference and routing chain template matching can be understood with reference to the relevant descriptions of the aforementioned CNC machining instruction automatic generation method based on large model inference and routing chain template matching. The functions of each module shown in the above-described embodiments of the CNC machining instruction automatic generation system based on large model inference and routing chain template matching can be implemented by a program (executable instructions) running on a processor, or by specific logic circuits. If the above-described CNC machining instruction automatic generation system based on large model inference and routing chain template matching is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage media include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Therefore, the embodiments of this application are not limited to any specific hardware and software combination.

[0172] Accordingly, this application also provides a computer storage medium storing computer-executable instructions, which, when executed by a processor, implement the various method implementations of this application.

[0173] Furthermore, this application also provides an automatic CNC machining instruction generation system based on large model inference and routing chain template matching, including a memory for storing computer-executable instructions and a processor; the processor is used to implement the steps in the above-described method embodiments when executing the computer-executable instructions in the memory. The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The aforementioned memory can be read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or solid-state drive, etc. The steps of the methods disclosed in the embodiments of this application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.

[0174] It should be noted that in this patent application, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element. In this patent application, if it refers to performing an action according to an element, it means performing the action at least according to that element, including two cases: performing the action only according to that element, and performing the action according to that element and other elements. Expressions such as "multiple," "repeatedly," and "various" include two, two times, two kinds, and more than two, more than two times, and more than two kinds.

[0175] All documents mentioned in this application are considered to be incorporated in their entirety into the disclosure of this application so that they can serve as a basis for modifications if necessary. Furthermore, it should be understood that after reading the foregoing disclosure of this application, those skilled in the art can make various alterations or modifications to this application, and these equivalent forms also fall within the scope of protection claimed in this application.

Claims

1. A method for automatically generating CNC machining instructions based on large model inference and routing chain template matching, characterized in that, Includes the following steps: Receive a part processing description in text format, use large model inference to decompose the part processing description into multiple single processing steps and extract the key processing information of each processing step to generate a processing step list; Using the key processing information in the process step list as the primary key, similar processing parameters are retrieved from the local knowledge base using retrieval enhancement generation RAG technology. Processing parameters are then generated for each process step through large model inference, forming a process step parameter list. Construct a routing chain, which includes CNC code generation prompt templates for different machining types. Input a single machining step from the machining step parameter list into the routing chain. The large model identifies the machining type and matches the corresponding CNC code generation prompt template to generate CNC machining code for the single machining step. Integrate the CNC machining code to form a CNC machining code list. A memory function is introduced to cache the generated CNC machining code list. The CNC machining code list is fine-tuned and corrected through interactive dialogue. All the corrected single-step CNC machining codes are grouped and organized to generate the final CNC machining code.

2. The method as described in claim 1, characterized in that, In the steps of receiving a text-formatted part processing description, decomposing the part processing description into multiple individual processing steps using large-scale model inference, extracting key processing information for each step, and generating a list of processing steps, a prompt word engineering framework is adopted to enhance the large-scale model's inference capabilities. This prompt word engineering framework includes: an input / output example module, providing typical part processing descriptions and corresponding processing step decomposition specification examples; a rule constraint module, embedding formatted output rules, processing step decomposition principles, and key information extraction principles; a Few-shot CoT module, guiding the large-scale model's thinking through step-by-step inference examples to improve the accuracy of processing step decomposition and key information extraction; and a ReAct module, guiding the large-scale model to reflect on the generated results, reflecting on and constraining inference errors, and achieving iterative optimization of dynamic inference and execution verification.

3. The method as described in claim 1 or 2, characterized in that, The process of decomposing the part processing description into multiple individual steps using large model reasoning includes: constructing a prompt word Prompt containing the prompt word engineering framework; and inputting the part processing description text into a large model with enhanced reasoning capabilities for step decomposition and extraction of key processing information.

4. The method as described in claim 1, characterized in that, The list of work steps is output as a list of dictionaries.

5. The method as described in claim 1, characterized in that, In the steps of using the key processing information in the process step list as the primary key, retrieving similar processing parameters from the local knowledge base using retrieval enhancement generation (RAG) technology, and generating processing parameters for each process step through large model inference to form a process step parameter list, a local knowledge base is constructed by collecting processing parameters under different materials and processing types. Similar processing parameters are retrieved according to the process step list and provided as context to the large model, which then infers and generates processing parameters.

6. The method as described in claim 1 or 5, characterized in that, The construction of the local knowledge base includes: using the key processing information as the primary key, collecting processing parameters under different processing states, and organizing them into a local knowledge base.

7. The method as described in claim 1, characterized in that, The CNC code generation prompt templates in the routing chain are selected from the following group: naming conventions for process parameters, processing feature description frameworks, process constraint sets, and typical parameter value ranges. Based on the prompt templates, names and descriptions are generated, and corresponding target chains are created to address the CNC code generation rules under different processing types.

8. The method as described in claim 1 or 7, characterized in that, The CNC code generation prompt template includes: CNC code writing rules and formatted output requirements corresponding to the machining type.

9. The method as described in claim 1, characterized in that, The process of constructing the routing chain includes: designing a description of a prompt template for each processing type, the description including the template name, the matching method between the processing type and the work step list corresponding to the template, and the prompt word name corresponding to the template; the large model dynamically selects the corresponding prompt word based on the description of the prompt template.

10. The method as described in claim 1, characterized in that, The Memory function uses ConversationBufferWindowMemory to buffer window memory, summarize the past k rounds of dialogue, and compress dialogue token consumption, allowing users to interactively fine-tune and correct the generated CNC machining code through dialogue.

11. The method as described in claim 1, characterized in that, Using a large-scale model AI Workflow, the complex process of writing CNC machining code based on the part to be processed is decomposed into three modules: step decomposition and key information extraction, machining parameter recommendation and CNC machining code generation. Each module is introduced into the large model through different methods and technologies to complete the intelligent and automatic realization of this complex task.

12. A CNC machining instruction automatic generation system based on large model reasoning and routing chain template matching, characterized in that, include: The process decomposition module is used to receive a part processing description in text format, decompose the part processing description into multiple single processes using large model inference, extract the key processing information of each process, and generate a process list. The parameter generation module is used to take the key processing information in the process step list as the primary key, retrieve similar processing parameters from the local knowledge base using the search-enhanced generation RAG technology, and generate processing parameters for each process step through large model inference to form a process step parameter list. The code generation module is used to construct a routing chain. The routing chain contains CNC code generation prompt templates for different machining types. A single machining step from the machining step parameter list is input into the routing chain. The large model identifies the machining type and matches the corresponding CNC code generation prompt template to generate CNC machining code for the single machining step. The CNC machining code is then integrated to form a CNC machining code list. The code optimization module introduces a memory function to cache the generated CNC machining code list. Through an interactive dialogue, the CNC machining code list is fine-tuned and corrected. All the corrected single-step CNC machining codes are grouped and organized to generate the final CNC machining code.