Search

CN-121996254-A - Policy code generation method, device and equipment

CN121996254ACN 121996254 ACN121996254 ACN 121996254ACN-121996254-A

Abstract

The application discloses a strategy code generation method, a strategy code generation device and strategy code generation equipment, which relate to the technical field of code conversion, wherein the strategy code generation method comprises the steps of obtaining a first script file and generating a corresponding abstract syntax tree according to the first script file; the method comprises the steps of determining a plurality of code segments and the dependency relationship among the code segments according to the dependency graph corresponding to an abstract grammar tree, splitting the first script file according to the dependency graph, inputting the code segments and first prompt words into a preset large language model, outputting policy codes corresponding to the code segments respectively through the large language model, wherein the first prompt words at least comprise the dependency relationship, and assembling the policy codes corresponding to the code segments respectively to obtain an object policy code file. The application can solve the technical problem that transcoding by using a large language model is limited by a context window.

Inventors

  • YE FENG

Assignees

  • 深圳前海微众银行股份有限公司

Dates

Publication Date
20260508
Application Date
20260205

Claims (10)

  1. 1. A policy code generation method, the policy code generation method comprising: Acquiring a first script file, and generating a corresponding abstract syntax tree according to the first script file; Splitting codes of the first script file according to a dependency graph corresponding to the abstract syntax tree and the dependency graph to obtain a plurality of code fragments and determining the dependency relationship among the code fragments; Inputting each code segment and a first prompt word into a preset large language model, and sequentially outputting strategy codes corresponding to each code segment by the large language model, wherein the first prompt word at least comprises the dependency relationship; And assembling the strategy codes corresponding to the code fragments respectively to obtain the target strategy code file.
  2. 2. The method of generating policy codes according to claim 1, wherein the dependency graph includes at least a data dependency graph and a control dependency graph, and the steps of splitting the code of the first script file according to the dependency graph and obtaining a plurality of code segments and determining a dependency relationship between the code segments include: Generating a data dependency graph corresponding to the abstract syntax tree according to the reference data corresponding to each variable in the abstract syntax tree, wherein the data dependency graph is used for representing the data dependency relationship among the variables; generating a control dependency graph corresponding to the abstract syntax tree according to control sentences corresponding to expressions in the abstract syntax tree, wherein the control dependency graph is used for representing control dependency relations among the control sentences; selecting at least one target split node from the nodes of the abstract syntax tree based on the data dependency graph and the control dependency graph; splitting the codes of the first script file according to the target splitting node to obtain a plurality of code fragments, and determining the dependency relationship between the code fragments according to the data dependency graph and the control dependency graph.
  3. 3. The policy code generation method according to claim 2, wherein the step of selecting at least one target split node among the nodes of the abstract syntax tree based on the data dependency graph and the control dependency graph comprises: taking a root node, a nested node and a conditional node in the abstract syntax tree as candidate split nodes; According to the data dependency graph and the control dependency graph, identifying the number of dependency edges of each candidate split node and other nodes respectively; calculating splitting gain values respectively corresponding to the candidate splitting nodes according to the number of the tokens respectively covered by the candidate splitting nodes, the number of the dependent edges of other nodes and a preset penalty coefficient; and selecting at least one target split node from the candidate split nodes based on the split gain value of each candidate split node and a preset constraint condition.
  4. 4. The policy code generation method according to claim 3, wherein the step of selecting at least one target split node from the candidate split nodes based on the split gain value of each of the candidate split nodes and a preset constraint condition comprises: judging whether a first candidate split node with the largest split profit value meets the constraint condition or not; If the constraint condition is met, determining the first candidate split node as a target split node, and judging whether the target split node contains other candidate split nodes or not; And if so, taking the candidate split node meeting the constraint condition from other candidate split nodes contained in the target split node as the target split node, and returning to the step of judging whether the target split node contains other candidate split nodes.
  5. 5. The method of generating a policy code according to claim 1, wherein before said step of inputting each of said code segments and said first hint word into a predetermined large language model, outputting policy codes corresponding to each of said code segments in turn by said large language model, said method further comprises: Based on a preset dynamic context budget allocation algorithm, respectively corresponding context budgets for the code segments; And generating the first prompt word according to the context budget corresponding to each code segment and the dependency relationship between each code segment.
  6. 6. The method of generating a policy code according to claim 1, wherein the step of generating a corresponding abstract syntax tree from the first script file comprises: sequentially formatting and standardizing the first script file to obtain a first standardized code; And analyzing the morphology and grammar of the first standardized code through a preset strategy language analyzer to obtain an abstract grammar tree.
  7. 7. The method of generating a policy code according to claim 6, wherein the policy syntax parser includes at least a syntax checking service, the policy code generating method further comprising: Obtaining a policy engine document, and performing format conversion on the policy engine document to obtain a lightweight markup language file; Inputting the lightweight markup language file and the second prompt word into a preset large language model, and outputting a plurality of corresponding grammar rules by the large language model; merging the grammar rules into grammar files, and generating a corresponding lexical analyzer and a grammar analyzer according to the grammar files; And packaging the lexical analyzer and the grammar analyzer into grammar checking service, wherein the grammar checking service at least comprises a code checking interface.
  8. 8. The method for generating a policy code according to claim 1, wherein said step of assembling the policy codes respectively corresponding to the code segments to obtain the target policy code file comprises: generating a strategy file header according to the first script file, wherein the strategy file header is used for representing file names, generation time and source files; Sequentially adding input parameter declarations on the basis of the head of the strategy file, and obtaining a first strategy code file by each strategy code, each output statement and the tail of the strategy file; And formatting the first strategy code file to obtain a target strategy code file.
  9. 9. A policy code generating device, characterized in that the policy code generating device comprises: The grammar tree generation module is used for acquiring a first script file and generating a corresponding abstract grammar tree according to the first script file; The code splitting module is used for splitting codes of the first script file according to a dependency graph corresponding to the abstract syntax tree and the dependency graph to obtain a plurality of code segments and determining the dependency relationship among the code segments; The code generation module is used for inputting each code segment and a first prompt word into a preset large language model, and sequentially outputting strategy codes corresponding to each code segment by the large language model, wherein the first prompt word at least comprises the dependency relationship; and the code assembly module is used for assembling the strategy codes respectively corresponding to the code fragments to obtain the target strategy code file.
  10. 10. A policy code generating device, characterized in that it comprises a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the policy code generating method according to any one of claims 1 to 8.

Description

Policy code generation method, device and equipment Technical Field The present application relates to the field of transcoding technologies, and in particular, to a method, an apparatus, and a device for generating a policy code. Background The existing mainstream code conversion technical scheme comprises rule-based template conversion, namely, fixed modes of source codes are mapped into target codes through predefined conversion rules and templates, and the scheme is poor in flexibility and cannot process complex nested logic because of processing the predefined modes. The other scheme is to use a large language model for conversion, and the method is limited by a model context window (usually 4K-32K tokens (word elements)) and cannot process a large file, is inaccurate in understanding of a specific language in the field, has conversion accuracy of only about 60% -70%, is easy to make mistakes in complex nested logic in the whole code file, and has the deep technical defect that the code conversion scheme generates technical problems is that the large language model processes too many tokens output by the large file, and exceeds the scope of the processing capacity of the large model. Disclosure of Invention The application mainly aims to provide a strategy code generation method, a strategy code generation device and strategy code generation equipment, and aims to solve the technical problem that transcoding by using a large language model is limited by a context window. In order to achieve the above object, the present application provides a policy code generation method, which includes: Acquiring a first script file, and generating a corresponding abstract syntax tree according to the first script file; Splitting codes of the first script file according to a dependency graph corresponding to the abstract syntax tree and the dependency graph to obtain a plurality of code fragments and determining the dependency relationship among the code fragments; Inputting each code segment and a first prompt word into a preset large language model, and sequentially outputting strategy codes corresponding to each code segment by the large language model, wherein the first prompt word at least comprises the dependency relationship; And assembling the strategy codes corresponding to the code fragments respectively to obtain the target strategy code file. In addition, to achieve the above object, the present application also proposes a policy code generating device, including: The grammar tree generation module is used for acquiring a first script file and generating a corresponding abstract grammar tree according to the first script file; The code splitting module is used for splitting codes of the first script file according to a dependency graph corresponding to the abstract syntax tree and the dependency graph to obtain a plurality of code segments and determining the dependency relationship among the code segments; The code generation module is used for inputting each code segment and a first prompt word into a preset large language model, and sequentially outputting strategy codes corresponding to each code segment by the large language model, wherein the first prompt word at least comprises the dependency relationship; and the code assembly module is used for assembling the strategy codes respectively corresponding to the code fragments to obtain the target strategy code file. In addition, in order to achieve the above object, the present application also proposes a policy code generating device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the policy code generating method as described above. One or more technical schemes provided by the application have at least the following technical effects: The method comprises the steps of firstly obtaining a first script file, generating a corresponding abstract syntax tree according to the first script file, splitting codes of the first script file according to a dependency graph corresponding to the abstract syntax tree, obtaining a plurality of code fragments and determining dependency relations among the code fragments according to the dependency graph, inputting the code fragments and a first prompt word into a preset large language model, sequentially outputting strategy codes corresponding to the code fragments by the large language model, wherein the first prompt word at least comprises the dependency relations, finally assembling the strategy codes corresponding to the code fragments to obtain a target strategy code file According to the technical scheme, the script file is abstracted into the abstract syntax tree, the dependency graph is determined to represent the dependency relationship in the abstract syntax tree, the splitting process of the script file is performed based on the dependency relationship and the syntax, the logic in