Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Jan 6, 2024
1 parent bf0b3cc commit c2da719
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions libs/core/tests/unit_tests/runnables/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,43 @@ def get_session_history(user_id: str, conversation_id: str) -> ChatMessageHistor
]
),
}


def test_thingy():
from langchain.schema import HumanMessage
from langchain_community.chat_message_histories import SQLChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory

Check failure on line 373 in libs/core/tests/unit_tests/runnables/test_history.py

View workflow job for this annotation

GitHub Actions / ci (libs/core) / lint / build (3.8)

Ruff (I001)

tests/unit_tests/runnables/test_history.py:370:1: I001 Import block is un-sorted or un-formatted

Check failure on line 373 in libs/core/tests/unit_tests/runnables/test_history.py

View workflow job for this annotation

GitHub Actions / ci (libs/core) / lint / build (3.11)

Ruff (I001)

tests/unit_tests/runnables/test_history.py:370:1: I001 Import block is un-sorted or un-formatted
def _fake_llm(input: Dict[str, Any]) -> List[BaseMessage]:
messages = input
return [
AIMessage(
content="you said: "
+ "\n".join(
str(m.content) for m in messages if isinstance(m, HumanMessage)
)
)
]

chat = RunnableLambda(_fake_llm)

def factory(session_id):
return SQLChatMessageHistory(
session_id=session_id, connection_string="sqlite:///sqlite.db"
)

session = factory("abc")

chat_with_history = RunnableWithMessageHistory(
chat,
factory,
)

# This is where we configure the session id, which is needed for fetching messages
config = {"configurable": {"session_id": "abc"}}

chat_with_history.invoke(HumanMessage(content="Hi! I'm Bob"), config=config)
assert session.messages[:2] == [
HumanMessage(content="Hi! I'm Bob"),
AIMessage(content="you said: Hi! I'm Bob"),
]

0 comments on commit c2da719

Please sign in to comment.