From 76684e4e535166ea73b1d699698b861e87eb9383 Mon Sep 17 00:00:00 2001 From: "Jonathan C. McKinney" Date: Mon, 9 Sep 2024 20:19:28 -0700 Subject: [PATCH] Clarify display of images and avoid for all python scripts --- openai_server/agent_prompting.py | 5 +++++ openai_server/autogen_utils.py | 13 +++++++++++++ src/version.py | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/openai_server/agent_prompting.py b/openai_server/agent_prompting.py index 6485a1df1..0672c61a8 100644 --- a/openai_server/agent_prompting.py +++ b/openai_server/agent_prompting.py @@ -461,7 +461,12 @@ def get_image_query_helper(base_url, api_key, model): * image_query accepts most image files allowed by PIL (Pillow) except svg. * Only use image_query on key images or plots (e.g. plots meant to share back to the user or those that may be key in answering the user question). * If the user asks for a perfect image, use the image_query tool only up to 6 times. If the user asks for a very rough image, then do not use the image_query tool at all. If the user does not specify the quality of the image, then use the image_query tool only up to 3 times. If user asks for more uses of image_query, then do as they ask. +* Do not use plt.show() or plt.imshow() as the user cannot see that displayed, instead you must use this image_query tool to critique or analyze images as a file. """ + else: + image_query_helper = """* Do not use plt.show() or plt.imshow() as the user cannot see that displayed. Use other ways to analyze the image if required. +""" + # FIXME: What if chat history, counting will be off return image_query_helper diff --git a/openai_server/autogen_utils.py b/openai_server/autogen_utils.py index b74a8f25a..3514fba39 100644 --- a/openai_server/autogen_utils.py +++ b/openai_server/autogen_utils.py @@ -148,6 +148,19 @@ def _execute_code_dont_check_setup(self, code_blocks: List[CodeBlock]) -> Comman code_blocks = [x for x in code_blocks if '# execution: false' not in x.code] # give chance for LLM to give generic code blocks without any execution false code_blocks = [x for x in code_blocks if '# execution:' in x.code] + + # ensure no plots pop-up if in pycharm mode or outside docker + for code_block in code_blocks: + lang, code = code_block.language, code_block.code + if lang == 'python': + code_block.code = """import matplotlib +matplotlib.use('Agg') # Set the backend to non-interactive +import matplotlib.pyplot as plt +plt.ioff() +import os +os.environ['TERM'] = 'dumb' +""" + code_block.code + ret = super()._execute_code_dont_check_setup(code_blocks) except Exception as e: if 'exitcode' in str(e) and 'local variable' in str(e): diff --git a/src/version.py b/src/version.py index a1220a4c1..b8586a128 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1 @@ -__version__ = "016148d6571225d0df7d7a2221dabf931ab66f65" +__version__ = "29c6262b2de6cc41f6f704d98f816140082a09a1"