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: patch-release 0.17.1 #176

Merged
merged 4 commits into from
Nov 19, 2024
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
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
Loading