langchain/libs/community/tests/unit_tests/chat_models/test_edenai.py
Ghani e30c6662df
Langchain-community : EdenAI chat integration. (#16377)
- **Description:** This PR adds [EdenAI](https://edenai.co/) for the
chat model (already available in LLM & Embeddings). It supports all
[ChatModel] functionality: generate, async generate, stream, astream and
batch. A detailed notebook was added.

  - **Dependencies**: No dependencies are added as we call a rest API.

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
2024-01-26 09:56:43 -05:00

41 lines
1.1 KiB
Python

"""Test EdenAI Chat API wrapper."""
from typing import List
import pytest
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
from langchain_community.chat_models.edenai import (
_format_edenai_messages,
_message_role,
)
@pytest.mark.parametrize(
("messages", "expected"),
[
(
[
SystemMessage(content="Translate the text from English to French"),
HumanMessage(content="Hello how are you today?"),
],
{
"text": "Hello how are you today?",
"previous_history": [],
"chatbot_global_action": "Translate the text from English to French",
},
)
],
)
def test_edenai_messages_formatting(messages: List[BaseMessage], expected: str) -> None:
result = _format_edenai_messages(messages)
assert result == expected
@pytest.mark.parametrize(
("role", "role_response"),
[("ai", "assistant"), ("human", "user"), ("chat", "user")],
)
def test_edenai_message_role(role: str, role_response) -> None:
role = _message_role(role)
assert role == role_response