forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added octoai test (langchain-ai#21793)
- [ ] **PR title**: community: add tests for ChatOctoAI - [ ] **PR message**: Description: Added unit tests for the ChatOctoAI class in the community package to ensure proper validation and default values. These tests verify the correct initialization of fields, the handling of missing required parameters, and the proper setting of aliases. Issue: N/A Dependencies: None --------- Co-authored-by: ccurme <[email protected]> Co-authored-by: Eugene Yurtsev <[email protected]>
- Loading branch information
1 parent
69f9acb
commit a8af396
Showing
2 changed files
with
53 additions
and
2 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
51 changes: 51 additions & 0 deletions
51
libs/community/tests/unit_tests/chat_models/test_octoai.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 pytest | ||
from langchain_core.pydantic_v1 import SecretStr, ValidationError | ||
|
||
from langchain_community.chat_models.octoai import ChatOctoAI | ||
|
||
DEFAULT_API_BASE = "https://text.octoai.run/v1/" | ||
DEFAULT_MODEL = "llama-2-13b-chat" | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test__default_octoai_api_base() -> None: | ||
chat = ChatOctoAI(octoai_api_token=SecretStr("test_token")) # type: ignore[call-arg] | ||
assert chat.octoai_api_base == DEFAULT_API_BASE | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test__default_octoai_api_token() -> None: | ||
chat = ChatOctoAI(octoai_api_token=SecretStr("test_token")) # type: ignore[call-arg] | ||
assert chat.octoai_api_token.get_secret_value() == "test_token" | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test__default_model_name() -> None: | ||
chat = ChatOctoAI(octoai_api_token=SecretStr("test_token")) # type: ignore[call-arg] | ||
assert chat.model_name == DEFAULT_MODEL | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test__field_aliases() -> None: | ||
chat = ChatOctoAI(octoai_api_token=SecretStr("test_token"), model="custom-model") # type: ignore[call-arg] | ||
assert chat.model_name == "custom-model" | ||
assert chat.octoai_api_token.get_secret_value() == "test_token" | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test__missing_octoai_api_token() -> None: | ||
with pytest.raises(ValidationError) as e: | ||
ChatOctoAI() | ||
assert "Did not find octoai_api_token" in str(e) | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test__all_fields_provided() -> None: | ||
chat = ChatOctoAI( # type: ignore[call-arg] | ||
octoai_api_token=SecretStr("test_token"), | ||
model="custom-model", | ||
octoai_api_base="https://custom.api/base/", | ||
) | ||
assert chat.octoai_api_base == "https://custom.api/base/" | ||
assert chat.octoai_api_token.get_secret_value() == "test_token" | ||
assert chat.model_name == "custom-model" |