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

[CM-8195] now logs error if trying to log to a non llm project (#67) #76

Merged
merged 1 commit into from
Oct 2, 2023
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
15 changes: 15 additions & 0 deletions src/comet_llm/backend_error_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# *******************************************************
# ____ _ _
# / ___|___ _ __ ___ ___| |_ _ __ ___ | |
# | | / _ \| '_ ` _ \ / _ \ __| | '_ ` _ \| |
# | |__| (_) | | | | | | __/ |_ _| | | | | | |
# \____\___/|_| |_| |_|\___|\__(_)_| |_| |_|_|
#
# Sign up for free at https://www.comet.com
# Copyright (C) 2015-2023 Comet ML INC
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this package.
# *******************************************************

UNABLE_TO_LOG_TO_NON_LLM_PROJECT = 34323
3 changes: 3 additions & 0 deletions src/comet_llm/experiment_api/request_exception_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import requests # type: ignore

from .. import config, exceptions
from ..handlers import failed_response

LOGGER = logging.getLogger(__name__)

Expand All @@ -42,6 +43,8 @@ def wrapper(*args, **kwargs) -> Any: # type: ignore
f"{comet_url}. Check that your Comet "
f"installation is up-to-date and check the traceback for more details."
)
if exception.response is not None:
exception_args.append(failed_response.handle(exception.response))

_debug_log(exception)

Expand Down
28 changes: 28 additions & 0 deletions src/comet_llm/handlers/failed_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# *******************************************************
# ____ _ _
# / ___|___ _ __ ___ ___| |_ _ __ ___ | |
# | | / _ \| '_ ` _ \ / _ \ __| | '_ ` _ \| |
# | |__| (_) | | | | | | __/ |_ _| | | | | | |
# \____\___/|_| |_| |_|\___|\__(_)_| |_| |_|_|
#
# Sign up for free at https://www.comet.com
# Copyright (C) 2015-2023 Comet ML INC
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this package.
# *******************************************************
import json
from typing import Optional

import requests # type: ignore

from .. import backend_error_codes, logging_messages

SDK_ERROR_CODES_LOGGING_MESSAGE = {
backend_error_codes.UNABLE_TO_LOG_TO_NON_LLM_PROJECT: logging_messages.UNABLE_TO_LOG_TO_NON_LLM_PROJECT
}


def handle(response: requests.Response) -> Optional[str]:
sdk_error_code = json.loads(response.text)["sdk_error_code"]
return SDK_ERROR_CODES_LOGGING_MESSAGE.get(sdk_error_code)
16 changes: 16 additions & 0 deletions src/comet_llm/logging_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# *******************************************************
# ____ _ _
# / ___|___ _ __ ___ ___| |_ _ __ ___ | |
# | | / _ \| '_ ` _ \ / _ \ __| | '_ ` _ \| |
# | |__| (_) | | | | | | __/ |_ _| | | | | | |
# \____\___/|_| |_| |_|\___|\__(_)_| |_| |_|_|
#
# Sign up for free at https://www.comet.com
# Copyright (C) 2015-2023 Comet ML INC
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this package.
# *******************************************************


UNABLE_TO_LOG_TO_NON_LLM_PROJECT = "Failed to send prompt to the specified project as it is not an LLM project, please specify a different project name."
24 changes: 23 additions & 1 deletion tests/unit/experiment_api/test_request_exception_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest
import requests
from testix import *
Expand All @@ -9,6 +11,7 @@
@pytest.fixture(autouse=True)
def mock_imports(patch_module):
patch_module(request_exception_wrapper, "config")
patch_module(request_exception_wrapper, "failed_response")


def test_wrap_no_exceptions():
Expand Down Expand Up @@ -49,4 +52,23 @@ def f():
with Scenario() as s:
s.config.comet_url() >> COMET_CLOUD_URL
with pytest.raises(exceptions.CometLLMException):
f()
f()


def test_wrap__request_exception_non_llm_project_sdk_code__log_specifc_message_in_exception():
@request_exception_wrapper.wrap()
def f():
exception = requests.RequestException()
response = requests.Response
response.text = json.dumps({"sdk_error_code": 34323})
exception.response = response
raise exception

expected_log_message = "Failed to send prompt to the specified project as it is not an LLM project, please specify a different project name."

with Scenario() as s:
s.failed_response.handle(requests.Response) >> expected_log_message
with pytest.raises(exceptions.CometLLMException) as excinfo:
f()

assert excinfo.value.args == (expected_log_message, )