#!/usr/bin/env python3 # -*- coding: utf-8 -*- """专题四 · 步骤 1:在 chat.py 注入临时调试日志(验证后请运行删日志脚本)。""" from __future__ import annotations import sys import _bootstrap # noqa: F401 import _config as C import _plugin_patch as P from dify_api import Dify def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: d.login() chat_path = P.find_plugin_file(d, "chat.py") print("chat.py:", chat_path) content = P.read_remote_file(d, chat_path) new_content = P.inject_debug_log(content) P.deploy_plugin_file(d, chat_path, new_content) d.sh( "docker exec %s sh -c 'rm -f /tmp/dify_openai_messages.log && " "touch /tmp/dify_openai_messages.log'" % C.PLUGIN_CONTAINER ) print("已重启 plugin_daemon 并清空 /tmp/dify_openai_messages.log") return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())