IDE Debugging
The following uses VS Code as an example to introduce how to debug ChatTrees created based on Python (Xmind ChatTrees cannot be debugged)
Debugging Preparation
- When logging in via VS Code, selelct then folder TeliChatSecRun
- Requires the installation of Python, Pylance, Python Debugger, Python Environments and other VS Code plug-ins
- Correctly choose the Python interpreter for VS Code, especially when there are various Python virtual environments
- Add the following content to the launch.json file of VS Code (in the TeliChatSecRun/.vscode directory, if not, you need to create the file first):
{
"version": "0.2.0",
"configurations": [
{
"name": "WEB",
"type": "debugpy",
"request": "launch",
"program": "./web.py",
"justMyCode": true,
"console": "integratedTerminal",
"envFile" : "${workspaceFolder}/env.txt",
"args" : [ "port=8080" ]
},
{
"name": "API",
"type": "debugpy",
"request": "launch",
"program": "./api.py",
"justMyCode": true,
"console": "integratedTerminal",
"envFile" : "${workspaceFolder}/env.txt",
"args" : [ "start_port=8000","gpu_index=0","LLMT=PUBLIC" ]
},
]
}
- At the same time, you also need to create an env.txt file in the TeliChatSecRun directory, with the following content (modify according to the actual situation):
GEMINI_APIKEY=...
GPT_APIKEY=...
OPENROUTER_APIKEY=...
- Before starting debugging, if there is a Python virtual environment, activate the virtual environment in the terminal, and then start debugging; when starting debugging, use the "Run and Debugg" on the left side of VS Code to activate the "WEB" and "API" options respectively
- Just set a breakpoint in the corresponding Python file (including Python ChatTree files and other imported Python files). When the breakpoint is interrupted, you can view the Python variables (especially the content of the InfoItems through the ctx parameter variable. For details, see "Python Script/Function")
Node Debugging Function
(only for Python ChatTrees)
- All nodes of the Python ChatTree have two special function attributes "before_execution" and "after_execution". These two attributes point to a certain function or directly define a lambda expression, so that a breakpoint can be set in the function or lambda expression to achieve debugging interception of a certain node (before or after execution), such as:
When debugging in the IDE, as shown above, you can set a breakpoint on the
def summarize_info_node_after_execution(ctx):
pass
summarize_info_node = chattree.create_node( "#inform_user#", {
"inform_content": "<Summary of relevant injuries or conditions, specific location and contact number based on previous communication>",
"before_execution" : lambda ctx : (
_:=0
),
"after_execution": summarize_info_node_after_execution,
})_:=0line of the lambda expression (note If it is a lambda expression, it must be in this multi-line form to set a valid debugging breakpoint), or you can set a breakpoint on thepassline of thesummarize_info_node_after_executionfunction