mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
e30c6662df
- **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>
41 lines
1.1 KiB
Python
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
|