mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
50ba3c68bb
**Description:** Initial pull request for Kinetica LLM wrapper **Issue:** N/A **Dependencies:** No new dependencies for unit tests. Integration tests require gpudb, typeguard, and faker **Twitter handle:** @chad_juliano Note: There is another pull request for Kinetica vectorstore. Ultimately we would like to make a partner package but we are starting with a community contribution.
68 lines
2.0 KiB
Python
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 = """
|
|
{
|
|
"payload":{
|
|
"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()
|
|
|
|
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';"
|
|
)
|