Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use system message for attachment content #162

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def get_completion_messages_for_attachments(
]

messages.append({
"role": "user",
"role": "system",
"content": content,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"content": AttachmentsConfigModel().context_description,
},
{
"role": "user",
"role": "system",
"content": "<ATTACHMENT><FILENAME>file1.txt</FILENAME><CONTENT>file 1</CONTENT></ATTACHMENT>",
},
{
"role": "user",
"role": "system",
"content": "<ATTACHMENT><FILENAME>file2.txt</FILENAME><CONTENT>file 2</CONTENT></ATTACHMENT>",
},
],
Expand All @@ -46,11 +46,11 @@
"content": AttachmentsConfigModel().context_description,
},
{
"role": "user",
"role": "system",
"content": "<ATTACHMENT><FILENAME>file1.txt</FILENAME><ERROR>error processing file: file 1 error</ERROR><CONTENT></CONTENT></ATTACHMENT>",
},
{
"role": "user",
"role": "system",
"content": "<ATTACHMENT><FILENAME>file2.txt</FILENAME><CONTENT>file 2</CONTENT></ATTACHMENT>",
},
],
Expand Down
4 changes: 2 additions & 2 deletions libraries/python/openai-client/openai_client/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def get_image_dims(image_uri: str) -> tuple[int, int]:
# From https://github.com/openai/openai-cookbook/pull/881/files
if re.match(r"data:image\/\w+;base64", image_uri):
image_uri = re.sub(r"data:image\/\w+;base64,", "", image_uri)
image = Image.open(BytesIO(base64.b64decode(image_uri)))
return image.size
with Image.open(BytesIO(base64.b64decode(image_uri))) as image:
return image.size
else:
raise ValueError("Image must be a base64 string.")

Expand Down