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

fix: gpt-4o: fixed failing tool/function calling #175

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
17 changes: 9 additions & 8 deletions aidial_adapter_openai/gpt4_multi_modal/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,28 @@ async def download_content_images(
ret: List[ImageMetadata] = []

for content_part in content:
if image_url := content_part.get("image_url", {}).get("url"):
image_detail = content_part.get("image_url", {}).get("detail")
if image_detail not in [None, "auto", "low", "high"]:
image_url = content_part.get("image_url")
if image_url and (url := image_url.get("url")):
detail = image_url.get("detail")
if detail not in [None, "auto", "low", "high"]:
raise ValidationError("Unexpected image detail")

dial_resource = URLResource(
url=image_url,
url=url,
entity_name="image",
supported_types=SUPPORTED_IMAGE_TYPES,
)
result = await self.try_download_resource(dial_resource)
self.collect_resource(ret, result, image_detail)
self.collect_resource(ret, result, detail)

return ret

async def transform_message(self, message: dict) -> MultiModalMessage:
message = message.copy()

content = message.get("content", "")
custom_content = message.pop("custom_content", {})
attachments = custom_content.get("attachments", [])
content = message.get("content") or ""
custom_content = message.pop("custom_content", None) or {}
attachments = custom_content.get("attachments") or []

attachment_meta = await self.download_attachment_images(attachments)
content_meta = await self.download_content_images(content)
Expand Down
Loading