Skip to content

Commit

Permalink
fix: patch-release 0.17.1 (#176)
Browse files Browse the repository at this point in the history
* fix: truncated error messages in plain text tokenizer (#172)
* fix: removed content-encoding header to avoid decoding errors (#174)
* chore: bump aiohttp from 3.10.2 to 3.10.11 (#173)
* fix: gpt-4o: fixed failing tool/function calling (#175)
  • Loading branch information
adubovik authored Nov 19, 2024
1 parent 6ad5990 commit b90e996
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 169 deletions.
8 changes: 7 additions & 1 deletion aidial_adapter_openai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,16 @@ async def embedding(deployment_id: str, request: Request):
def openai_exception_handler(request: Request, e: DialException):
if isinstance(e, APIStatusError):
r = e.response
headers = r.headers

# Avoid encoding the error message when the original response was encoded.
if "Content-Encoding" in headers:
del headers["Content-Encoding"]

return Response(
content=r.content,
status_code=r.status_code,
headers=r.headers,
headers=headers,
)

if isinstance(e, APITimeoutError):
Expand Down
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
7 changes: 4 additions & 3 deletions aidial_adapter_openai/utils/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def _process_raw_message(
pass
else:
raise InternalServerError(
f"Unexpected type of content in message: {value!r}"
f"Unexpected type of content in message: {type(value)}"
)

elif key == "role":
if isinstance(value, str):
tokens += calculate_text_tokens(value)
else:
raise InternalServerError(
f"Unexpected type of 'role' field in message: {value!r}"
f"Unexpected type of 'role' field in message: {type(value)}"
)
return tokens

Expand All @@ -116,8 +116,9 @@ class PlainTextTokenizer(BaseTokenizer[dict]):
"""

def _handle_custom_content_part(self, content_part: Any):
short_content_part = str(content_part)[:100]
raise InternalServerError(
f"Unexpected type of content in message: {content_part!r}"
f"Unexpected type of content in message: {short_content_part!r}"
f"Use MultiModalTokenizer for messages with images"
)

Expand Down
Loading

0 comments on commit b90e996

Please sign in to comment.