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: openai errors are correctly proxied #28

Merged
merged 5 commits into from
Nov 19, 2024

Conversation

adubovik
Copy link
Collaborator

@adubovik adubovik commented Nov 18, 2024

OpenAI errors received from the upstream are wrapped into a dictionary with detail field instead of being proxied as
is.

It happens because the OpenAI error are wrapped into fastapi.HTTPException, which has necessary this detail field.

The solution was to migrate the error to a more permitting fastapi.JSONResponse.

Along the way, the adapter was migrated to HTTPException from the DIAL SDK.

Error before

{
  "detail": "{\"error\":{\"message\":\"Invalid value: 'users'. Supported values are: 'system', 'assistant', 'user', 'function', and 'tool'.\",\"type\":\"invalid_request_error\",\"param\":\"messages[0].role\",\"code\":\"invalid_value\"}}"
}

Error after

{
  "error": {
    "message": "Invalid value: 'users'. Supported values are: 'system', 'assistant', 'user', 'function', and 'tool'.",
    "type": "invalid_request_error",
    "param": "messages[0].role",
    "code": "invalid_value"
  }
}

@adubovik adubovik self-assigned this Nov 18, 2024
@adubovik
Copy link
Collaborator Author

adubovik commented Nov 19, 2024

Review discussions

Re aidial_adapter_dial.utils.sse_stream.to_openai_sse_stream:

Q: Before this PR you returned END_CHUNK only in case there is no error. Now it's returned even after exception handling. Is this intentional?
A: we always return CHUNK_CHUNK in DIAL SDK, so I reasoned that we should follow the same logic everywhere

Q: If it's intentional, why you didn't use else/finally there?
A: I don't think we need to use finally here. Imagine SystemExit, CancelError or KeyboarInterrupt exception is thrown (none of which is Exception), the error handler won't catch it, but we will send END_CHUNK. This is strange. I would rather interrupt the response abruptly than make a false impression that everything is ok.

@adubovik adubovik merged commit 2fed242 into development Nov 19, 2024
7 checks passed
@adubovik adubovik deleted the fix/openai-errors-are-correctly-proxied branch November 19, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants