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

OpenAI v1 embeddings errors #1005

Merged
merged 42 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
939de1c
Add embeddings OpenAI v1 support.
umaannamalai Dec 4, 2023
5405d94
Fix errors tests.
umaannamalai Dec 5, 2023
3460237
Add embeddings OpenAI v1 support.
umaannamalai Dec 4, 2023
816236c
Fix errors tests.
umaannamalai Dec 5, 2023
227bd28
Add updated tests for compatiblity with new mock server.
umaannamalai Dec 11, 2023
55c6265
Merge branch 'feature-openai-v1' of github.com:newrelic/newrelic-pyth…
umaannamalai Dec 11, 2023
b866a3f
Update tox.
umaannamalai Dec 11, 2023
7bca59f
Restore chat completion error tests.
umaannamalai Dec 11, 2023
505705b
Address review comments.
umaannamalai Dec 12, 2023
28e9695
Store converted response object in new var for v1.
umaannamalai Dec 13, 2023
0b7b33e
Add errors testing.
umaannamalai Dec 12, 2023
8c97a19
Async tests.
umaannamalai Dec 13, 2023
457e1d1
Merge branch 'develop-ai-limited-preview' into openai-v1-embeddings-e…
umaannamalai Dec 13, 2023
5254701
Fix exc parsing.
umaannamalai Dec 14, 2023
6c09cc6
Merge conflicts.
umaannamalai Dec 14, 2023
fd0d931
Fix auth test.
umaannamalai Dec 14, 2023
1ca28ca
Fix error message for Python 3.10 +.
umaannamalai Dec 14, 2023
9acc03d
Add embeddings OpenAI v1 support.
umaannamalai Dec 4, 2023
18eeee0
Fix errors tests.
umaannamalai Dec 5, 2023
107d867
Add updated tests for compatiblity with new mock server.
umaannamalai Dec 11, 2023
de80033
Add embeddings OpenAI v1 support.
umaannamalai Dec 4, 2023
0c82343
Fix errors tests.
umaannamalai Dec 5, 2023
890ddd4
Update tox.
umaannamalai Dec 11, 2023
541d770
Restore chat completion error tests.
umaannamalai Dec 11, 2023
2bd5687
Address review comments.
umaannamalai Dec 12, 2023
23a0d50
Store converted response object in new var for v1.
umaannamalai Dec 13, 2023
09923df
Add errors testing.
umaannamalai Dec 12, 2023
319e62c
Async tests.
umaannamalai Dec 13, 2023
f2f5785
Fix exc parsing.
umaannamalai Dec 14, 2023
1b5572b
Fix auth test.
umaannamalai Dec 14, 2023
202eb08
Fix error message for Python 3.10 +.
umaannamalai Dec 14, 2023
251752f
Merge conflicts.
umaannamalai Dec 15, 2023
2e22b1a
Merge branch 'openai-v1-embeddings-errors' of github.com:newrelic/new…
umaannamalai Dec 15, 2023
6066de4
Merge conflicts.
umaannamalai Dec 15, 2023
daf13b6
status code.
umaannamalai Dec 15, 2023
d11c394
Update mock server.
umaannamalai Dec 15, 2023
6a587d4
[Mega-Linter] Apply linters fixes
umaannamalai Dec 15, 2023
ef440b3
Trigger tests
hmstepanek Dec 15, 2023
b40cf32
Remove embedding error v1 tests from ignore list
hmstepanek Dec 15, 2023
9d38dca
Fix invalid request tests.
umaannamalai Dec 15, 2023
cd5f76a
[Mega-Linter] Apply linters fixes
umaannamalai Dec 15, 2023
539240a
Trigger tests
hmstepanek Dec 15, 2023
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
76 changes: 56 additions & 20 deletions newrelic/hooks/mlmodel_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,37 @@ def wrap_embedding_sync(wrapped, instance, args, kwargs):
try:
response = wrapped(*args, **kwargs)
except Exception as exc:
notice_error_attributes = {
"http.statusCode": getattr(exc, "http_status", ""),
"error.message": getattr(exc, "_message", ""),
"error.code": getattr(getattr(exc, "error", ""), "code", ""),
"error.param": getattr(exc, "param", ""),
"embedding_id": embedding_id,
}
exc._nr_message = notice_error_attributes.pop("error.message")
if OPENAI_V1:
response = getattr(exc, "response", "")
response_headers = getattr(response, "headers", "")
exc_organization = response_headers.get("openai-organization", "") if response_headers else ""
# There appears to be a bug here in openai v1 where despite having code,
# param, etc in the error response, they are not populated on the exception
# object so grab them from the response body object instead.
body = getattr(exc, "body", {}) or {}
notice_error_attributes = {
"http.statusCode": getattr(exc, "status_code", "") or "",
"error.message": body.get("message", "") or "",
"error.code": body.get("code", "") or "",
"error.param": body.get("param", "") or "",
"embedding_id": embedding_id,
}
else:
exc_organization = getattr(exc, "organization", "")
notice_error_attributes = {
"http.statusCode": getattr(exc, "http_status", ""),
"error.message": getattr(exc, "_message", ""),
"error.code": getattr(getattr(exc, "error", ""), "code", ""),
"error.param": getattr(exc, "param", ""),
"embedding_id": embedding_id,
}
message = notice_error_attributes.pop("error.message")
if message:
exc._nr_message = message
ft.notice_error(
attributes=notice_error_attributes,
)
# Gather attributes to add to embedding summary event in error context
exc_organization = getattr(exc, "organization", "")

error_embedding_dict = {
"id": embedding_id,
"appName": settings.app_name,
Expand Down Expand Up @@ -498,19 +516,37 @@ async def wrap_embedding_async(wrapped, instance, args, kwargs):
try:
response = await wrapped(*args, **kwargs)
except Exception as exc:
notice_error_attributes = {
"http.statusCode": getattr(exc, "http_status", ""),
"error.message": getattr(exc, "_message", ""),
"error.code": getattr(getattr(exc, "error", ""), "code", ""),
"error.param": getattr(exc, "param", ""),
"embedding_id": embedding_id,
}
exc._nr_message = notice_error_attributes.pop("error.message")
if OPENAI_V1:
response = getattr(exc, "response", "")
response_headers = getattr(response, "headers", "")
exc_organization = response_headers.get("openai-organization", "") if response_headers else ""
# There appears to be a bug here in openai v1 where despite having code,
# param, etc in the error response, they are not populated on the exception
# object so grab them from the response body object instead.
body = getattr(exc, "body", {}) or {}
notice_error_attributes = {
"http.statusCode": getattr(exc, "status_code", "") or "",
"error.message": body.get("message", "") or "",
"error.code": body.get("code", "") or "",
"error.param": body.get("param", "") or "",
"embedding_id": embedding_id,
}
else:
exc_organization = getattr(exc, "organization", "")
notice_error_attributes = {
"http.statusCode": getattr(exc, "http_status", ""),
"error.message": getattr(exc, "_message", ""),
"error.code": getattr(getattr(exc, "error", ""), "code", ""),
"error.param": getattr(exc, "param", ""),
"embedding_id": embedding_id,
}
message = notice_error_attributes.pop("error.message")
if message:
exc._nr_message = message
ft.notice_error(
attributes=notice_error_attributes,
)
# Gather attributes to add to embedding summary event in error context
exc_organization = getattr(exc, "organization", "")

error_embedding_dict = {
"id": embedding_id,
"appName": settings.app_name,
Expand Down
1 change: 0 additions & 1 deletion tests/mlmodel_openai/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"test_chat_completion.py",
"test_get_llm_message_ids.py",
"test_chat_completion_error.py",
umaannamalai marked this conversation as resolved.
Show resolved Hide resolved
"test_embeddings_error_v1.py",
]


Expand Down
Loading
Loading