langchain/libs/community/tests/unit_tests/chat_models/test_kinetica.py
Erick Friis c2a3021bb0
multiple: pydantic 2 compatibility, v0.3 (#26443)
Signed-off-by: ChengZi <chen.zhang@zilliz.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com>
Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com>
Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no>
Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: ccurme <chester.curme@gmail.com>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com>
Co-authored-by: ZhangShenao <15201440436@163.com>
Co-authored-by: Friso H. Kingma <fhkingma@gmail.com>
Co-authored-by: ChengZi <chen.zhang@zilliz.com>
Co-authored-by: Nuno Campos <nuno@langchain.dev>
Co-authored-by: Morgante Pell <morgantep@google.com>
2024-09-13 14:38:45 -07:00

68 lines
2.0 KiB
Python

"""Test `Kinetica` chat models"""
import logging
from typing import Any
from langchain_core.messages import AIMessage
from langchain_community.chat_models.kinetica import ChatKinetica, KineticaUtil
LOG = logging.getLogger(__name__)
class TestChatKinetica:
test_ctx_json: str = """
{
"payload":{
"question": "foo",
"context":[
{
"table":"demo.test_profiles",
"columns":[
"username VARCHAR (32) NOT NULL",
"name VARCHAR (32) NOT NULL",
"sex VARCHAR (1) NOT NULL",
"address VARCHAR (64) NOT NULL",
"mail VARCHAR (32) NOT NULL",
"birthdate TIMESTAMP NOT NULL"
],
"description":"Contains user profiles.",
"rules":[
]
},
{
"samples":{
"How many male users are there?":
"select count(1) as num_users from demo.test_profiles where sex = ''M'';"
}
}
]
}
}
"""
def test_convert_messages(self, monkeypatch: Any) -> None:
"""Test convert messages from context."""
def patch_kdbc() -> None:
return None
monkeypatch.setattr(KineticaUtil, "create_kdbc", patch_kdbc)
def patch_execute_sql(*args: Any, **kwargs: Any) -> dict:
return dict(Prompt=self.test_ctx_json)
monkeypatch.setattr(ChatKinetica, "_execute_sql", patch_execute_sql)
kinetica_llm = ChatKinetica() # type: ignore[call-arg]
test_messages = kinetica_llm.load_messages_from_context("test")
LOG.info(f"test_messages: {test_messages}")
ai_message = test_messages[-1]
assert isinstance(ai_message, AIMessage)
assert (
ai_message.content
== "select count(1) as num_users from demo.test_profiles where sex = 'M';"
)