mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
743f888580
**Description:** This PR adds [Dappier](https://dappier.com/) for the chat model. It supports generate, async generate, and batch functionalities. We added unit and integration tests as well as a notebook with more details about our chat model. **Dependencies:** No extra dependencies are needed.
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
from typing import List
|
|
|
|
import pytest
|
|
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
|
|
from langchain_core.outputs import ChatGeneration, LLMResult
|
|
|
|
from langchain_community.chat_models.dappier import (
|
|
ChatDappierAI,
|
|
)
|
|
|
|
|
|
@pytest.mark.scheduled
|
|
def test_dappier_chat() -> None:
|
|
"""Test ChatDappierAI wrapper."""
|
|
chat = ChatDappierAI(
|
|
dappier_endpoint="https://api.dappier.com/app/datamodelconversation",
|
|
dappier_model="dm_01hpsxyfm2fwdt2zet9cg6fdxt",
|
|
)
|
|
message = HumanMessage(content="Who are you ?")
|
|
response = chat([message])
|
|
assert isinstance(response, AIMessage)
|
|
assert isinstance(response.content, str)
|
|
|
|
|
|
@pytest.mark.scheduled
|
|
def test_dappier_generate() -> None:
|
|
"""Test generate method of Dappier AI."""
|
|
chat = ChatDappierAI(
|
|
dappier_endpoint="https://api.dappier.com/app/datamodelconversation",
|
|
dappier_model="dm_01hpsxyfm2fwdt2zet9cg6fdxt",
|
|
)
|
|
chat_messages: List[List[BaseMessage]] = [
|
|
[HumanMessage(content="Who won the last super bowl?")],
|
|
]
|
|
messages_copy = [messages.copy() for messages in chat_messages]
|
|
result: LLMResult = chat.generate(chat_messages)
|
|
assert isinstance(result, LLMResult)
|
|
for response in result.generations[0]:
|
|
assert isinstance(response, ChatGeneration)
|
|
assert isinstance(response.text, str)
|
|
assert response.text == response.message.content
|
|
assert chat_messages == messages_copy
|
|
|
|
|
|
@pytest.mark.scheduled
|
|
async def test_dappier_agenerate() -> None:
|
|
"""Test async generation."""
|
|
chat = ChatDappierAI(
|
|
dappier_endpoint="https://api.dappier.com/app/datamodelconversation",
|
|
dappier_model="dm_01hpsxyfm2fwdt2zet9cg6fdxt",
|
|
)
|
|
message = HumanMessage(content="Who won the last super bowl?")
|
|
result: LLMResult = await chat.agenerate([[message], [message]])
|
|
assert isinstance(result, LLMResult)
|
|
for response in result.generations[0]:
|
|
assert isinstance(response, ChatGeneration)
|
|
assert isinstance(response.text, str)
|
|
assert response.text == response.message.content
|