Skip to content

Commit

Permalink
Clarify display of images and avoid for all python scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudotensor committed Sep 10, 2024
1 parent 29c6262 commit 76684e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions openai_server/agent_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions openai_server/autogen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "016148d6571225d0df7d7a2221dabf931ab66f65"
__version__ = "29c6262b2de6cc41f6f704d98f816140082a09a1"

0 comments on commit 76684e4

Please sign in to comment.