-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into CM-8549_add_error_handling_for_current_chain
- Loading branch information
Showing
12 changed files
with
171 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- 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 functools | ||
from typing import Optional | ||
|
||
|
||
@functools.lru_cache(maxsize=1) | ||
def openai_version() -> Optional[str]: | ||
try: | ||
import openai | ||
|
||
version: str = openai.__version__ | ||
return version | ||
except Exception: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/unit/autologgers/openai/test_chat_completion_parsers_openai_v0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import box | ||
import pytest | ||
from testix import * | ||
|
||
from comet_llm.autologgers.openai import chat_completion_parsers | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_imports(patch_module): | ||
patch_module(chat_completion_parsers, "metadata") | ||
|
||
def test_parse_create_result__input_is_openai_object__input_parsed_successfully(): | ||
create_result = Fake("create_result") | ||
with Scenario() as s: | ||
s.metadata.openai_version() >> "0.99.99" | ||
s.create_result.to_dict() >> { | ||
"choices": "the-choices", | ||
"some-key": "some-value", | ||
} | ||
|
||
outputs, metadata = chat_completion_parsers.parse_create_result(create_result) | ||
|
||
assert outputs == {"choices": "the-choices"} | ||
assert metadata == {"some-key": "some-value"} | ||
|
||
|
||
def test_parse_create_result__input_is_openai_object__input_parsed_successfully__model_key_renamed_to_output_model(): | ||
create_result = Fake("create_result") | ||
with Scenario() as s: | ||
s.metadata.openai_version() >> "0.99.99" | ||
s.create_result.to_dict() >> { | ||
"choices": "the-choices", | ||
"some-key": "some-value", | ||
"model": "the-model", | ||
} | ||
|
||
outputs, metadata = chat_completion_parsers.parse_create_result(create_result) | ||
|
||
assert outputs == {"choices": "the-choices"} | ||
assert metadata == {"some-key": "some-value", "output_model": "the-model"} | ||
|
||
|
||
def test_parse_create_result__input_is_generator_object__input_parsed_with_hardcoded_values_used(): | ||
create_result = (x for x in []) | ||
|
||
with Scenario() as s: | ||
s.metadata.openai_version() >> "0.99.99" | ||
outputs, metadata = chat_completion_parsers.parse_create_result(create_result) | ||
|
||
assert outputs == {"choices": "Generation is not logged when using stream mode"} | ||
assert metadata == {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters