Skip to content

Commit

Permalink
Support body with no model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor Lahutin committed Sep 30, 2024
1 parent b5dc07e commit 527e4e3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aidial_interceptors_sdk/chat_completion/adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import re
from typing import Any, AsyncIterator, Type, cast

from aidial_sdk.chat_completion import ChatCompletion as DialChatCompletion
Expand Down Expand Up @@ -27,6 +28,7 @@
_log = logging.getLogger(__name__)
_debug = _log.isEnabledFor(logging.DEBUG)

DEPLOYMENT_ID_PATTERN = r'/openai/deployments/([^/]+)/'

def interceptor_to_chat_completion(
cls: Type[ChatCompletionInterceptor],
Expand All @@ -49,6 +51,15 @@ async def chat_completion(
)

request_body = await request.original_request.json()

if not request_body.get("model"):
original_url = request.original_request.url
deployment_id_match = re.search(
DEPLOYMENT_ID_PATTERN, str(original_url)
)
if deployment_id_match:
request_body["model"] = deployment_id_match.group(1)

request_body = await debug_logging("request")(
interceptor.traverse_request
)(request_body)
Expand Down

0 comments on commit 527e4e3

Please sign in to comment.