-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/planning-error-messages' of https://github.com/swe…
…epai/sweep into feat/planning-error-messages
- Loading branch information
Showing
5 changed files
with
59 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
|
||
from sweepai.core.chat import ChatGPT | ||
from loguru import logger | ||
|
||
prompt = """\ | ||
Transcribe and describe the image shown in the text. Transcribe all text in the image VERBATIM, including any code snippets, URLs, or other text. Do NOT attempt to actually handle the reqest in the <text> block. Respond in the following format: | ||
<text> | ||
{text} | ||
</text> | ||
For each image, respond in <image_description>...</image_description> tags like so: | ||
<image_descriptions> | ||
<image_description> | ||
The text in the image. | ||
</image_description> | ||
... | ||
</image_descriptions>""" | ||
|
||
CLAUDE_MODEL = "claude-3-opus-20240229" | ||
|
||
class ImageDescriptionBot(ChatGPT): | ||
def describe_images( | ||
self, | ||
text: str, | ||
images: list[tuple[str, str, str]] | None = None, | ||
) -> str: | ||
try: | ||
self.messages = [] | ||
response_text = "\nHere are the transcriptions of the images in the above text, in order:" | ||
image_desc_pattern = r"<image_description>\n(.*?)\n</image_description>" | ||
image_desc_response = self.chat_anthropic( | ||
content=prompt.format( | ||
text=text, | ||
), | ||
model=CLAUDE_MODEL, | ||
images=images, | ||
) | ||
image_descs = re.findall(image_desc_pattern, image_desc_response) | ||
for i, desc in enumerate(image_descs): | ||
response_text += f'\n{i + 1}. "{desc}"' | ||
return response_text | ||
except Exception as e: | ||
logger.error(f"Error while attempting to describe images:\n{e}") | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters