Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/features/llm.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SessionLocal = sessionmaker(bind=engine)

client = ChatOpenAI(model="gpt-4o-mini")

mem = Memori(conn=SessionLocal).llm.register(client)
mem = Memori(conn=SessionLocal).llm.register(chatopenai=client)
mem.attribution(entity_id="user_123", process_id="langchain_agent")

response = client.invoke("Hello")
Expand Down
2 changes: 1 addition & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def get_sqlite_connection():
return sqlite3.connect("memori.db")

chat = ChatOpenAI()
mem = Memori(conn=get_sqlite_connection).llm.register(chat)
mem = Memori(conn=get_sqlite_connection).llm.register(chatopenai=chat)
mem.attribution(entity_id="user-123", process_id="my-app")
```

Expand Down
9 changes: 9 additions & 0 deletions memori/llm/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def client(self, client_obj: Any, config) -> BaseClient:
if matcher(client_obj):
return client_class(config)

module = type(client_obj).__module__
if module.startswith("langchain"):
class_name = type(client_obj).__name__
param_hint = class_name.lower()
raise RuntimeError(
f"LangChain models require named parameters. "
f"Use: llm.register({param_hint}=client) instead of llm.register(client)"
)

raise RuntimeError(
f"Unsupported LLM client type: {type(client_obj).__module__}.{type(client_obj).__name__}"
)
Expand Down
19 changes: 19 additions & 0 deletions tests/llm/test_llm_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,22 @@ def test_llm_adapter_raises_for_unsupported_provider():

with pytest.raises(RuntimeError, match="Unsupported LLM provider"):
Registry().adapter("mistral", "mistral")


def test_llm_client_raises_helpful_error_for_langchain():
"""Test that LangChain clients produce a helpful error message."""

class MockLangChainClient:
pass

MockLangChainClient.__module__ = "langchain_openai.chat_models.base"
MockLangChainClient.__name__ = "ChatOpenAI"

mock_client = MockLangChainClient()
mock_config = None

with pytest.raises(
RuntimeError,
match=r"LangChain models require named parameters.*llm\.register\(chatopenai=client\)",
):
Registry().client(mock_client, mock_config)
Loading