From 8edc84ede080c79149687ebc232b4f0d2b3ccaab Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Wed, 11 Dec 2024 11:32:55 -0800 Subject: [PATCH] Add env var to disable image parsing Added a `PROMPTY_CHAT_PARSER_DISABLE_IMAGE_PARSING=true` environment variable to disable image parsing in the chat parser. In my use case, I am using Prompty to send a prompt to the LLM that contains Markdown that should be converted to a different format. I do not need Prompty to parse the images and try to send them to the LLM. In fact, this is inconvenient because I don't want to have to copy the images just so Prompty can read them. An environment variable seems kind of janky perhaps, but it's the best solution I could come up with that doesn't require a lot of changes, because there's a fairly deep call stack so in order to pass a parameter, it would require modifying a lot of code. I'm open to other ideas though. --- runtime/prompty/prompty/parsers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/prompty/prompty/parsers.py b/runtime/prompty/prompty/parsers.py index 53f1d1c..f8ee876 100644 --- a/runtime/prompty/prompty/parsers.py +++ b/runtime/prompty/prompty/parsers.py @@ -1,3 +1,4 @@ +import os import re import base64 from .core import Prompty @@ -58,6 +59,9 @@ def parse_content(self, content: str): any The parsed content """ + if os.getenv("PROMPTY_CHAT_PARSER_DISABLE_IMAGE_PARSING", "false").lower() == "true": + return content + # regular expression to parse markdown images image = r"(?P!\[[^\]]*\])\((?P.*?)(?=\"|\))\)" matches = re.findall(image, content, flags=re.MULTILINE)