Data processing method, electronic device, medium and product

By integrating Python interpreter and large language model, analyzing abstract syntax trees and monitoring nodes, and dynamically adjusting the execution process, the problem that Python interpreter cannot utilize external knowledge is solved, and more intelligent and flexible Python code execution is achieved, which expands its application in knowledge-intensive tasks.

CN120315724BActive Publication Date: 2025-09-02SHANG HAI JIE YUE XING CHEN ZHI NENG KE JI YOU XIAN GONG SI
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510779512.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-12
Publication Date
2025-09-02
Estimated Expiration
2045-06-12

AI Technical Summary

Technical Problem

The Python interpreter can only process Python code and cannot use the knowledge of the outside world to enhance the functionality of the program.

Method used

Integrates Python interpreter and large language model, analyzes abstract syntax trees, monitors nodes and calls large language models to obtain modification information, dynamically adjusts execution processes, and solves exceptions and undefined functions.

Benefits of technology

It realizes the smarter and more flexible interpretation and execution of Python code, can handle code involving a wide range of knowledge, and expands the application of Python language in knowledge-intensive tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120315724B_ABST
    Figure CN120315724B_ABST
Patent Text Reader

Abstract

The embodiments of the present application relate to the field of computer technology, and disclose a data processing method, electronic device, medium, and product. The target system is integrated with a Python interpreter and a large language model, and the method includes: determining an abstract syntax tree based on the Python interpreter and Python code; determining modification information based on the large language model and the abstract syntax tree; the modification information is used to change the execution environment of the Python interpreter; and determining the current execution environment of the program based on the Python interpreter and the modification information. It can at least be used to solve the technical problem in the related art that the Python interpreter can only process Python code and can only perform tasks based on the given Python code, and cannot use knowledge from the outside world to further enhance the function of the program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data processing method, electronic equipment, medium, and product. Background Art

[0002] Currently, the Python interpreter is mainly implemented based on the compilation principle, and its workflow usually includes the following steps:

[0003] 1. Lexical analysis: Break the source code into lexical units, such as keywords, identifiers, operators, etc.

[0004] 2. Syntax analysis: According to the grammatical rules, the lexical units are organized into an abstract syntax tree (AST).

[0005] 3. Semantic analysis: Perform semantic level checks on AST, such as type checking and scope analysis.

[0006] 4. Intermediate code generation: Convert AST into intermediate code, such as bytecode.

[0007] 5. Intermediate code optimization: Optimize the intermediate code to improve subsequent execution efficiency.

[0008] 6. Target code generation: The intermediate code is further converted into target code, such as machine code.

[0009] 7. Execution: Execute the target code to get the output of the program.

[0010] The above-mentioned interpreter based on the compilation principle can accurately execute the given Python code. However, the inventors have found that there are at least the following technical problems in the related art:

[0011] The Python interpreter can only process Python code and can only perform tasks based on the given Python code. It cannot use knowledge of the outside world to further enhance the functionality of the program. Summary of the Invention

[0012] One purpose of the present application is to provide a data processing method, electronic device, medium and product, at least to solve the technical problem in the related art that the Python interpreter can only process Python code and can only perform tasks based on the given Python code, and cannot use knowledge of the outside world to further enhance the functionality of the program.

[0013] To achieve the above objectives, some embodiments of the present application provide the following aspects:

[0014] In a first aspect, some embodiments of the present application further provide a data processing method, which is applied to a target system, wherein the target system integrates a Python interpreter and a large language model, the method comprising: determining an abstract syntax tree based on the Python interpreter and Python code; determining modification information based on the large language model and the abstract syntax tree; the modification information is used to change the execution environment of the Python interpreter; and determining the current execution environment of a program based on the Python interpreter and the modification information; wherein, after determining the abstract syntax tree based on the Python interpreter and the Python code, the method further comprises: taking over the execution process of the abstract syntax tree by the Python interpreter and monitoring the nodes of the abstract syntax tree; determining the modification information based on the large language model and the abstract syntax tree comprises: determining whether the execution status meets a preset condition during the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree; if the execution status meets the preset condition, calling the large language model to interpret the execution status to determine the modification information; the preset condition comprises at least one of the following: the Python interpreter encounters an exception during execution, encounters an undefined function, or encounters a function that requires external knowledge to execute.

[0015] Optionally, the modification information includes: first modification information based on local variables and second modification information based on global variables.

[0016] Optionally, in the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining whether the execution status meets the preset conditions includes: in the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining the basic element type corresponding to the node of the abstract syntax tree; and determining whether the execution status meets the preset conditions based on the basic element type.

[0017] Optionally, the basic element type includes: a first type for representing the evaluation of an expression and a second type for representing the execution of a code block.

[0018] In a second aspect, some embodiments of the present application further provide an electronic device comprising: one or more processors; and a memory storing computer program instructions, wherein the computer program instructions, when executed, cause the processor to perform the steps of the method described above.

[0019] In a third aspect, some embodiments of the present application further provide a computer-readable medium having computer program instructions stored thereon, wherein the computer program instructions can be executed by a processor to implement the method described above.

[0020] In a fourth aspect, some embodiments of the present application further provide a computer program product, comprising a computer program or instructions, which implement the steps of the above-described method when executed by a processor.

[0021] Compared with the related art, the solution provided in the embodiment of the present application provides a data processing method applied to a target system. The target system integrates the Python interpreter and the large language model in a pioneering way, cleverly utilizing the knowledge and reasoning ability of the large language model, which can effectively solve the technical problem that the existing Python interpreter can only process Python code and can only perform tasks based on the given Python code, and cannot use the knowledge of the outside world to further enhance the function of the program, thereby achieving a more intelligent and flexible interpretation and execution of the Python code. Specifically, when processing the Python code input by the user, the abstract syntax tree can be determined based on the Python interpreter and the Python code, and then the modification information for changing the execution environment of the Python interpreter can be determined based on the large language model and the abstract syntax tree. Finally, the current execution environment of the program is determined by combining the Python interpreter and the modification information. Through this series of operations, the target system can process code involving a wide range of domain knowledge, greatly expanding the application of the Python language in knowledge-intensive tasks. For example, in fields such as geographic information analysis and global economic research, professional knowledge can be obtained with the help of a large language model, and developers do not need to manually collect and organize large amounts of external data. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0023] Figure 1 This is an exemplary flow chart of a data processing method provided according to some embodiments of the present application;

[0024] Figure 2 This is an exemplary structural diagram of an electronic device provided according to some embodiments of the present application. DETAILED DESCRIPTION

[0025] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0026] The following terms are used in this article.

[0027] An Abstract Syntax Tree (AST) is an intermediate representation of the source code generated after lexical and syntactic analysis. It represents the grammatical structure of a program as a tree, with each node representing a syntactic element in the source code, such as an expression, statement, or function. Nodes are connected through parent-child and sibling relationships, forming a hierarchical tree. The primary function of the AST is to describe the grammatical structure of the code, helping developers understand and analyze it.

[0028] Large Language Model (LLM) is a large language model. Through large-scale pre-training and fine-tuning, LLM possesses powerful natural language understanding and generation capabilities. It not only processes and generates natural language text but also possesses a certain level of knowledge representation and reasoning capabilities.

[0029] First embodiment

[0030] The first embodiment of the present application relates to a data processing method. The method is applied to a target system, which is integrated with a Python interpreter and a large language model, such as Figure 1 As shown, the method may include the following steps:

[0031] Step S101, determining an abstract syntax tree according to the Python interpreter and Python code;

[0032] Step S102: determining modification information based on the large language model and the abstract syntax tree; the modification information is used to change the execution environment of the Python interpreter;

[0033] Step S103: Determine the current execution environment of the program according to the Python interpreter and the modification information.

[0034] That is, when executing Python code, the target system can perform data processing according to the above steps, achieving more intelligent and flexible interpretation and execution of the code. The following is a detailed description of each of the above steps.

[0035] Regarding step S101, specifically, the Python code can be parsed by a Python interpreter. In some examples, the Python code can be parsed into an abstract syntax tree using an ast module.

[0036] With respect to step S102, specifically, considering that the natural language input belongs to the category of statements that cannot be compiled (code that does not conform to the grammatical rules of the programming language), the Python interpreter can only perform tasks based on the given code and cannot use the knowledge of the outside world to further enhance the functionality of the program. Through this step, during the process of the Python interpreter monitoring and controlling each node of the abstract syntax tree, if an abnormality is found, the large language model can output modification information that changes the current execution environment of the Python interpreter based on its own knowledge and reasoning ability. Exemplarily, the large language model can be but not limited to: GPT-4, PaLM, LLaMA, etc. Exemplarily, the modification information can be implemented in a predetermined format, such as JSON format.

[0037] Specifically, in step S103, after the Python interpreter receives the modified information output by the large language model, it can integrate the modified information into the execution environment, thereby determining the current execution environment of the program and then continuing the program execution. This seamless integration ensures that the program does not interrupt or change the original execution flow when utilizing the knowledge of the large language model.

[0038] In other words, in this application, the large language model can handle Python syntax errors, compilation errors, and other issues. Specifically, when the Python interpreter catches an execution exception, it pauses the original execution logic and passes the error context (including the code snippet, error type, variable status, etc.) to the large language model that has been fine-tuned for this purpose. This model is trained based on a large amount of Python code execution data, which is obtained by executing real code and recording intermediate states, which is relatively inexpensive.

[0039] For example, take the code that iterates over all subtropical countries:

[0040] for country in get_subtropical_countries():

[0041] # Do something

[0042] Among them, get_subtropical_countries() is a function that requires external knowledge reasoning before returning a list of countries.

[0043] The above code cannot be directly executed using the existing Python interpreter. The reason is: on the one hand, the existing Python interpreter can only perform calculations and operations based on the internal predefined instruction set and the code's own logic. It does not have built-in information about external knowledge such as "subtropical countries" and does not have the reasoning ability to obtain and process this knowledge. On the other hand, the execution process of the existing Python interpreter is based on deterministic rules and relies on variables, functions, and existing libraries defined in the code itself. If the function called in the code is not defined in the current environment, the Python interpreter will directly report an error and will not try to obtain relevant information from other channels to complete the function's function. In this example, get_subtropical_countries() is not defined in the code, so the Python interpreter cannot execute this code block.

[0044] The target system provided in this embodiment integrates a Python interpreter and a large language model, and can display different execution modes when processing the above code: When the Python interpreter encounters a call to the get_subtropical_countries() function, it invokes the large language model. Based on its knowledge and reasoning capabilities, the large language model analyzes and generates a list of subtropical countries, such as ["Brazil", "India", "Subtropical countries where parts of China are located"].

[0045] Furthermore, the country list output by the large language model can be used as the return value of the get_subtropical_countries() function, and then the Python interpreter's execution environment can be updated. This allows the Python interpreter to continue executing subsequent code, iterating over the country list and performing corresponding operations, such as printing the name of each country in the loop or performing other processing based on the country data.

[0046] As can be seen, the target system provided by this embodiment leverages the reasoning capabilities of a large language model to interpret and execute Python code more intelligently and flexibly. In the above example, not only can a list of subtropical countries be obtained, but the code context can also be used to provide more reasonable support for subsequent processing. For example, different operations can be performed within a loop based on the characteristics of different countries, which is difficult to achieve using existing Python interpreters.

[0047] It is understandable that there is no technical solution in the related art to integrate large language models with existing Python interpreters. In the related art, integrating large language models with Python interpreters will face the following difficulties:

[0048] 1. The problem of knowledge embedding: How to efficiently embed the knowledge mastered by the large language model into the execution process of the Python interpreter so that the Python interpreter can use the knowledge of the large language model to enhance the program functionality. - In this embodiment, by converting the Python code into an abstract syntax tree, it is helpful to accurately locate the parts of the code that require external knowledge. By obtaining knowledge from the large language model and generating modification information based on the needs determined by the abstract syntax tree, the knowledge of the large language model can be prepared in a suitable form. Finally, these modification information are applied to the execution environment of the Python interpreter, so that the Python interpreter can smoothly use the knowledge provided by the large language model in the process of executing the code, thereby efficiently realizing knowledge embedding and enhancing program functionality.

[0049] 2. Execution control problem: During the execution of the Python interpreter, how to flexibly and dynamically adjust the execution process based on the output of the large language model. - In this embodiment, the generated abstract syntax tree provides a clear framework and logical structure for code execution, allowing the Python interpreter to clearly understand the execution process. Modification information is determined based on the output of the large language model, and the modification information may include instructions for adjusting the execution process. The modification information is then integrated into the execution environment, and the Python interpreter continues to execute based on the updated environment, achieving flexible and dynamic adjustment of the execution process based on the output of the large language model, thus solving the execution control problem.

[0050] 3. Security and reliability issues: How to ensure that the content output by the large language model will not have a negative impact on the execution of the interpreter, and ensure the security and reliability of the program operation. - In this embodiment, when parsing the abstract syntax tree, the code can be statically analyzed to discover potential risks such as undefined variables in advance, laying the foundation for ensuring safe and reliable execution. When determining the modification information, the output of the large language model can be strictly filtered and verified, and only information that meets the security and reliability requirements is selected. When the modification information is applied to the execution environment, it can be strictly managed and monitored, and the type and range checks of the modified variables and functions can be performed, and a rollback mechanism can be set. When the modification information causes an exception, it can be restored to the previous execution environment in a timely manner to ensure the security and reliability of the program operation.

[0051] It is not difficult to find that, compared with the related art, the technical solution provided in this embodiment provides a data processing method applied to the target system. The target system pioneered the integration of the Python interpreter and the large language model, cleverly utilizing the knowledge and reasoning ability of the large language model, which can effectively solve the technical problem that the existing Python interpreter can only process Python code and can only perform tasks based on the given Python code, and cannot use the knowledge of the outside world to further enhance the function of the program, thereby achieving a more intelligent and flexible interpretation and execution of Python code. Specifically, when processing the Python code input by the user, the abstract syntax tree can be determined based on the Python interpreter and the Python code, and then the modification information for changing the execution environment of the Python interpreter can be determined based on the large language model and the abstract syntax tree. Finally, the current execution environment of the program is determined by combining the Python interpreter and the modification information. Through this series of operations, the target system can process code involving a wide range of domain knowledge, greatly expanding the application of the Python language in knowledge-intensive tasks. For example, in fields such as geographic information analysis and global economic research, professional knowledge can be obtained with the help of the large language model, and developers do not need to manually collect and organize large amounts of external data.

[0052] After determining the abstract syntax tree based on the Python interpreter and the Python code, the method may further include: taking over the execution process of the abstract syntax tree through the Python interpreter and monitoring the nodes of the abstract syntax tree to facilitate control of the abstract syntax tree.

[0053] Specifically, after obtaining the abstract syntax tree, the Python interpreter can take over the entire execution process based on the abstract syntax tree, and then monitor each node of the abstract syntax tree, so as to realize the control of the abstract syntax tree.

[0054] For example, let's take the code for traversing all subtropical countries: "for country in get_subtropical_countries (): # Do something" as an example. In the second embodiment scenario of the present application, the above Python code can be parsed into an abstract syntax tree through the Python interpreter. After obtaining the abstract syntax tree, the Python interpreter can take over the execution process of the tree, so that it can pay attention to each node in the tree. For example, in this example, the Python interpreter can pay attention to the "for" loop node to understand how the loop works, including the scope and life cycle of the loop variable "country"; it will also pay attention to the function call node "get_subtropical_countries()" to make it clear that this is an operation that requires obtaining external knowledge. In the process of monitoring nodes, the Python interpreter can achieve control over the abstract syntax tree.

[0055] It is not difficult to find that, compared with the related art, in the technical solution provided by this embodiment, since the Python interpreter can fully take over all nodes of the abstract syntax tree, including the fine-grained operation nodes at the end. Therefore, any subtle errors or demands for external knowledge during code execution can be discovered in a timely manner. This fine-grained control method enables the Python interpreter to capture the most fine-grained errors and knowledge execution requirements, and thus to perform more accurate and comprehensive management and control of Python code. In this way, it is conducive to timely and dynamic adjustment of the execution environment.

[0056] Further, specifically, the determining of the modification information according to the large language model and the abstract syntax tree, i.e., step S102, may include the following steps:

[0057] Step S1021, in the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining whether the execution status meets the preset conditions;

[0058] Step S1022: If the execution status meets the preset conditions, the large language model is called to interpret the execution status to determine the modification information.

[0059] Exemplarily, the preset conditions refer to pre-set rules or situations used to determine whether special handling is required during code execution. The preset conditions are related to problems that may arise during code execution or scenarios that require additional knowledge support.

[0060] For example, if the execution status meets the preset conditions, when interpreting Python using the large language model, each interpretation process actually updates the internal state of the Python interpreter. The internal state of the Python interpreter can be represented using a common data structure (JSON). This state information can be converted into a string or text form and provided as input to the large language model. After receiving it, the large language model can further output text information in JSON format.

[0061] As you can understand, during the processing process, the system can use guided decoding technology to constrain the model output, ensuring that the repair solutions generated by the guided decoding technology conform to Python syntax rules and correctly simulate internal state changes such as variable assignments and function calls. In this way, the large language model can accurately infer the original execution path of the program and generate effective repair solutions or alternative execution logic to restore normal program operation.

[0062] Optionally, in some embodiments, the preset condition may include, but is not limited to, at least one of the following: the Python interpreter encountering an exception (e.g., a syntax error, a runtime error), encountering an undefined function, or encountering a function that requires external knowledge to execute. Thus, while monitoring the abstract syntax tree nodes, the Python interpreter may determine whether the current execution status meets any of the preset conditions based on the preset conditions.

[0063] The following code "for country in get_subtropical_countries(): # Do something" is used as an example to explain steps S1021 and S1022 in detail:

[0064] When the Python interpreter takes over the execution of the abstract syntax tree corresponding to "for country in get_subtropical_countries(): # Dosomething" and monitors the nodes, it can judge the following preset conditions:

[0065] For example, during code execution, exceptions may occur for various reasons. For example, if the get_subtropical_countries function is incorrectly defined before code execution, such as with a syntax error, a syntax error exception will be triggered when the Python interpreter executes the function call. Alternatively, if the function involves operations such as file reading or network requests, and the file does not exist or the network connection fails, corresponding exceptions such as FileNotFoundError or ConnectionError will be thrown. In this case, it can be determined that the execution meets the pre-set condition of "encountering an exception."

[0066] For example, assuming the get_subtropical_countries function is undefined in the above code, when the Python interpreter reaches the get_subtropical_countries() function call node, it finds that the function has no corresponding definition in the current execution environment. Therefore, it can be determined that the execution meets the pre-defined condition of "encountering an undefined function."

[0067] For example, the get_subtropical_countries function returns a list of all subtropical countries, which requires external knowledge of geography. The Python interpreter itself doesn't have this knowledge, so when it encounters this function call, it determines that the execution meets the precondition of "encountering a function requiring external knowledge."

[0068] Furthermore, suppose that during the monitoring process, the Python interpreter discovers that the get_subtropical_countries function is undefined and requires external knowledge, satisfying a pre-defined condition. In this case, based on monitoring the abstract syntax tree nodes, the Python interpreter can pass the current contextual information, such as the location of the function call, the surrounding code logic, and the problem description (e.g., "need to get a list of all subtropical countries"), to the large language model. Upon receiving this information, the large language model can leverage its knowledge and reasoning capabilities to analyze and identify a request for geographical knowledge. It then extracts information about all subtropical countries from its training data and compiles it into a list, such as ["Brazil","China (partial regions)","Australia (partial regions)"], which it then feeds back to the Python interpreter as an explanation of the execution. The Python interpreter can then use this list as the return value of the get_subtropical_countries function, allowing the code to continue the subsequent traversal and execute the corresponding processing logic for each country in the list (i.e., the #Do something portion of the code).

[0069] Optionally, in some embodiments, the modification information may include: first modification information based on local variables (__locals__) and second modification information based on global variables (__globals__).

[0070] Specifically, __locals__ represents a dictionary of local variables within the current function or code block. Variables defined within a function are typically scoped to that function, and these variables are stored in __locals__. When the function ends, the variables in __locals__ are typically destroyed (unless there are special closures, etc.). For example, if a local variable is defined within a loop, for example:

[0071] for country in get_subtropical_countries():

[0072] temp_var = country + " is a subtropical country"

[0073] # Do something

[0074] Here, temp_var is a local variable, stored in the __locals__ dictionary corresponding to the current loop code block. The result returned by the large language model, as the return value of the get_subtropical_countries function, affects the execution of the loop, and indirectly affects the creation and use of variables in __locals__. Assuming the list of countries returned by the large language model is ["Brazil", "China (partial regions)", "Australia (partial regions)"], then in each loop, temp_var will be assigned a different country value, and these assignments occur in the local variable context of __locals__.

[0075] Specifically, __globals__ is a dictionary containing global variables that are accessible throughout the scope of a Python module (usually a .py file). The lifetime of a global variable typically begins when the module is loaded and ends when the module ends (unless explicitly deleted). For example, if a global variable is defined at the top of a module containing the code "for country in get_subtropical_countries (): # Do something", such as:

[0076] subtropical_countries_list = []

[0077] for country in get_subtropical_countries():

[0078] subtropical_countries_list.append(country)

[0079] # Do something

[0080] Here, subtropical_countries_list is a global variable stored in the __globals__ dictionary. The country list returned by the large language model, as the return value of the get_subtropical_countries function, is repeatedly added to the subtropical_countries_list global variable within the loop, effectively modifying the variables in __globals__. This example shows that variables in __globals__ can be accessed and modified from different code blocks within the module (including loops). The results of the large language model can affect the state of global variables by influencing function execution.

[0081] It should be noted that this embodiment may also be an improvement based on the first embodiment.

[0082] It is not difficult to find that the embodiments of the present application provide a specific implementation method for determining modification information based on the large language model and the abstract syntax tree. Because the Python interpreter takes over the execution of the abstract syntax tree and monitors the nodes, it can determine whether the execution status meets the preset conditions. If so, it calls the large language model for interpretation. This enhances the robustness of code execution and can handle exceptions and undefined elements. It not only expands the code knowledge processing capabilities, but also obtains external knowledge, realizes intelligent assistance in code execution, and can make decisions based on context and continuously optimize execution. In this way, when encountering undefined functions or functions that require external knowledge, it no longer directly reports an error and interrupts the program. Instead, it attempts to solve the problem through the intervention of the large language model, ensuring smooth execution of the program. This allows developers to focus on the implementation of business logic without worrying too much about the completeness of function definitions when writing code, improving development efficiency. For example, when developing a data collection program, the target system of this application can better handle some functions that rely on specific domain knowledge to obtain data, reducing the complexity of code writing and debugging. It can be seen that the technical solution of this embodiment can ensure that the program obtains the required knowledge and support in a timely manner during execution, thereby resolving operations that would otherwise be impossible to execute and avoiding interruptions due to code failure.

[0083] Second embodiment

[0084] The second embodiment of the present application relates to a data processing method. The second embodiment is an improvement based on the first embodiment. The specific improvement is that: in the fourth embodiment of the present application, a specific implementation method is provided for determining whether the execution status meets the preset conditions during the process in which the Python interpreter takes over the execution process of the abstract syntax tree and monitors the nodes of the abstract syntax tree.

[0085] Specifically, in the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining whether the execution status meets the preset conditions, that is, step S1021 includes:

[0086] Step S10211, in the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining the basic element type corresponding to the node of the abstract syntax tree;

[0087] Step S10212: Determine whether the execution status meets the preset conditions according to the basic element type.

[0088] Optionally, in some embodiments, the basic element type may include: a first type for representing the evaluation of an expression and a second type for representing the execution of a code block.

[0089] Specifically, all abstract syntax tree nodes are different from a code logic perspective. This embodiment aims to customize the processing of nodes for different types of abstract syntax trees. The inventors discovered that the nodes of abstract syntax trees share commonalities: the basic operations of a node involve either evaluating an expression or executing a block of code. Because these two operations are at the core of code execution and many underlying errors arise from them, understanding and handling them is crucial.

[0090] That is to say, in this embodiment, expression evaluation and code block execution are the core links that the Python interpreter takes over. Based on this, after the entire execution process is completed, once an error occurs, the cause of the error can usually be traced back to these two basic levels. Specifically, the error situations are mainly divided into two categories: first, an error occurs when evaluating an expression (similar to the eval operation). For example, an undefined variable is referenced in the code. When the Python interpreter tries to calculate the expression containing the variable, it will report an error because it cannot find the corresponding variable. Second, an error is reported during the execution of a code block (similar to the exec operation). For example, a runtime error occurs when a function is running. Common examples include memory out of bounds - the program accesses an area beyond its allocated memory range, which causes an error.

[0091] It is not difficult to find that in the embodiment of the present application, when the Python interpreter takes over the abstract syntax tree execution and monitors the nodes, it first determines the basic element type corresponding to the node, and then judges whether the execution status meets the preset conditions based on this. This method can accurately locate code problems, quickly identify the root cause of the error and handle exceptions in a targeted manner; by optimizing the execution process and reducing unnecessary judgments, it effectively improves execution efficiency; it can also enhance code maintainability and extensibility, facilitate understanding of code logic, and support function expansion; at the same time, it accurately transmits information to the large language model, optimizes knowledge embedding, and improves the collaboration effect between the two, providing comprehensive protection for Python code execution.

[0092] The step division of the above various methods is only for the purpose of clear description. During implementation, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this application; adding insignificant modifications or introducing insignificant designs to the algorithm or process without changing the core design of the algorithm and process are all within the scope of protection of this application.

[0093] In addition, some embodiments of the present application further provide an electronic device. The electronic device may be various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, etc. The electronic device may also be various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices.

[0094] The electronic device includes: one or more processors; and a memory storing computer program instructions, wherein the computer program instructions, when executed, enable the processor to perform the steps of the method provided in any one or more of the above embodiments. Figure 2 An exemplary structural diagram of the electronic device is disclosed. Figure 2 As shown, the electronic device includes: one or more processors 1101, memory 1102, and interfaces for connecting various components, including high-speed and low-speed interfaces. The various components are interconnected using different buses and can be mounted on a common motherboard or in other ways as needed. The processor can process instructions executed within the electronic device, including instructions stored in or on the memory for displaying graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In some other embodiments, if desired, multiple processors and / or multiple buses can be used with multiple memories and multiple storage devices. Similarly, multiple electronic devices can be connected, with each device providing some of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.

[0095] The electronic device may further include: an input device 1103 and an output device 1104. The processor 1101, the memory 1102, the input device 1103 and the output device 1104 may be connected via a bus or other means. Figure 2 The bus connection is taken as an example.

[0096] Input device 1103 can receive input digital or character information and generate key signal input related to user settings and function control of the electronic device. Examples include a touch screen, keypad, mouse, trackpad, touchpad, pointer, one or more mouse buttons, trackball, joystick, and other input devices. Output device 1104 may include a display device, auxiliary lighting devices (e.g., LEDs), and tactile feedback devices (e.g., vibration motors). Display devices may include, but are not limited to, liquid crystal displays (LCDs), light-emitting diode (LED) displays, and plasma displays. In some embodiments, the display device may be a touch screen.

[0097] To provide user interaction, the electronic device may be a computer. The computer includes a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user, as well as a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices may also be used to provide user interaction; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback), and input from the user may be received in any form, including acoustic input, voice input, or tactile input.

[0098] In the embodiments of the present application, a computer-readable medium stores a computer program or instructions that, when executed by a processor, implement the steps of the method provided in any one or more of the above embodiments. The computer-readable medium may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the device. The computer-readable medium carries one or more computer-readable instructions.

[0099] The memory 1102 can be used as a non-transitory computer-readable storage medium to store non-transitory software programs, non-transitory computer executable programs, and modules. The processor 1101 executes the non-transitory software programs, instructions, and modules stored in the memory 1102 to execute various functional applications and data processing of the server, thereby implementing the program instructions / modules corresponding to the method provided in any one or more of the above embodiments of the present application.

[0100] The memory 1102 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device, etc. In addition, the memory 1102 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 1102 may optionally include a memory remotely located relative to the processor 1101, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0101] It should be noted that the computer-readable medium described in this application may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. Computer-readable media may include, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or components, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this application, a computer-readable medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or component.

[0102] Computer-readable media include both permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology for information storage. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change RAM (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc-read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device.

[0103] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0104] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. For example, implementation may be achieved using an application-specific integrated circuit (ASIC), a general-purpose computer, or any other similar hardware device. In some embodiments, the software program of the present application may be executed by a processor to implement the above steps or functions. Similarly, the software program of the present application (including related data structures) may be stored in a computer-readable recording medium, such as a RAM memory, a magnetic or optical drive, a floppy disk, or the like. In addition, some steps or functions of the present application may be implemented using hardware, for example, as a circuit that cooperates with a processor to perform the various steps or functions.

[0105] The computer program product provided in the embodiments of the present application includes one or more computer programs or instructions, which, when executed by a processor, fully or partially produce the processes or functions described in accordance with the embodiments of the present application. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).

[0106] The flowcharts or block diagrams in the accompanying drawings illustrate the possible architectures, functions and operations of the devices, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment or part of code, and the module, program segment or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, as well as the combination of boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-specific system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0107] The scope of this application is defined by the appended claims rather than the foregoing description and is therefore intended to encompass within this application all changes that come within the meaning and range of equivalents of the claims. Any reference signs in the claims should not be construed as limiting the claims to which they relate. In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in a device claim may also be implemented by one unit or device through software or hardware. Words such as "first" and "second" are only used to distinguish the description and do not indicate any particular order, nor should they be understood as indicating or implying relative importance.

[0108] The above descriptions are merely specific embodiments of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included within the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims, and the above descriptions should be regarded as exemplary and non-limiting.

Claims

1. A data processing method, characterized in that: The method is applied to a target system, wherein the target system is integrated with a Python interpreter and a large language model, and the method includes: Determine an abstract syntax tree based on the Python interpreter and the Python code; Determining modification information based on the large language model and the abstract syntax tree; the modification information is used to change the execution environment of the Python interpreter; Determining a current execution environment of a program based on the Python interpreter and the modification information; After determining the abstract syntax tree according to the Python interpreter and the Python code, the method further comprises: taking over the execution process of the abstract syntax tree through the Python interpreter and monitoring the nodes of the abstract syntax tree; Determining the modification information based on the large language model and the abstract syntax tree includes: determining whether an execution status satisfies a preset condition during a process in which the Python interpreter takes over the execution process of the abstract syntax tree and monitors the nodes of the abstract syntax tree; if the execution status satisfies the preset condition, calling the large language model to interpret the execution status to determine the modification information; The preset condition includes at least one of the following: the Python interpreter encounters an exception during execution, encounters an undefined function, or encounters a function that requires external knowledge to execute.

2. The method according to claim 1, characterized in that The modification information includes: first modification information based on local variables and second modification information based on global variables.

3. The method according to claim 1, characterized in that In the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining whether the execution status meets the preset conditions includes: In the process of the Python interpreter taking over the execution process of the abstract syntax tree and monitoring the nodes of the abstract syntax tree, determining the basic element type corresponding to the node of the abstract syntax tree; According to the basic element type, it is determined whether the execution status meets the preset conditions.

4. The method according to claim 3, characterized in that The basic element types include: a first type for representing the evaluation of an expression and a second type for representing the execution of a code block.

5. An electronic device, characterized in that: The electronic device comprises: one or more processors; and A memory storing computer program instructions, which, when executed, cause the processor to perform the steps of the method according to any one of claims 1 to 4.

6. A computer-readable medium having a computer program or instruction stored thereon, characterized in that: When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.

7. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Test interface determination and function call chain generation method and device, equipment and medium

    CN115344282A

  • Text processing model training method, text processing method and question and answer processing method and device

    CN118627543A