Skip to content

Commit

Permalink
fix: gpt-4o: fixed failing tool/function calling (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik authored Nov 19, 2024
1 parent fe3faea commit 79b7d11
Showing 1 changed file with 9 additions and 8 deletions.
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

0 comments on commit 79b7d11

Please sign in to comment.