aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run-tool.py
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-10-18 18:28:03 +0800
committerGitHub <noreply@github.com>2024-10-18 18:28:03 +0800
commit6eb391bdc76ed070299f1b70e96f021a03a6d97a (patch)
treec28eba4cac9b9da1773ad35524fa02c2dd3bca25 /scripts/run-tool.py
parentb5377bf28bb4d7ec114b7ab9ef1ecec3995cfe66 (diff)
downloadllm-functions-docker-6eb391bdc76ed070299f1b70e96f021a03a6d97a.tar.gz
feat: controls displaying the results from function call (#111)
Diffstat (limited to 'scripts/run-tool.py')
-rwxr-xr-xscripts/run-tool.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/run-tool.py b/scripts/run-tool.py
index b5cdc79..4b6af78 100755
--- a/scripts/run-tool.py
+++ b/scripts/run-tool.py
@@ -82,6 +82,7 @@ def run(tool_path, tool_func, tool_data):
value = getattr(mod, tool_func)(**tool_data)
return_to_llm(value)
+ dump_result()
def return_to_llm(value):
@@ -102,6 +103,37 @@ def return_to_llm(value):
writer.write(value_str)
+def dump_result():
+ if not os.isatty(1):
+ return
+
+ if not os.getenv("LLM_OUTPUT"):
+ return
+
+ show_result = False
+ tool_name = os.environ["LLM_TOOL_NAME"].upper().replace("-", "_")
+ env_name = f"LLM_TOOL_DUMP_RESULT_{tool_name}"
+ env_value = os.getenv(env_name)
+
+ if os.getenv("LLM_TOOL_DUMP_RESULT") in ("1", "true"):
+ if env_value not in ("0", "false"):
+ show_result = True
+ else:
+ if env_value in ("1", "true"):
+ show_result = True
+
+ if not show_result:
+ return
+
+ try:
+ with open(os.environ["LLM_OUTPUT"], "r", encoding="utf-8") as f:
+ data = f.read()
+ except:
+ return
+
+ print(f"\x1b[2m----------------------\n{data}\n----------------------\x1b[0m")
+
+
if __name__ == "__main__":
try:
main()