Skip to content

Commit

Permalink
Fix for bug where attachments ignored prompt, refs #20
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 4, 2024
1 parent 59289b9 commit 7c5067e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions llm_claude_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def build_messages(self, prompt, conversation) -> List[dict]:
}
for attachment in response.attachments
]
content.append({"type": "text", "text": response.prompt.prompt})
else:
content = response.prompt.prompt
messages.extend(
Expand All @@ -151,24 +152,26 @@ def build_messages(self, prompt, conversation) -> List[dict]:
]
)
if prompt.attachments:
content = [
{
"type": (
"document"
if attachment.resolve_type() == "application/pdf"
else "image"
),
"source": {
"data": attachment.base64_content(),
"media_type": attachment.resolve_type(),
"type": "base64",
},
}
for attachment in prompt.attachments
]
content.append({"type": "text", "text": prompt.prompt})
messages.append(
{
"role": "user",
"content": [
{
"type": (
"document"
if attachment.resolve_type() == "application/pdf"
else "image"
),
"source": {
"data": attachment.base64_content(),
"media_type": attachment.resolve_type(),
"type": "base64",
},
}
for attachment in prompt.attachments
],
"content": content,
}
)
else:
Expand Down

0 comments on commit 7c5067e

Please sign in to comment.