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
64 changes: 62 additions & 2 deletions memori/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .database.connectors import MySQLConnector, PostgreSQLConnector, SQLiteConnector
from .database.queries import BaseQueries, ChatQueries, EntityQueries, MemoryQueries

# Wrapper integrations
# Wrapper integrations (legacy - will show deprecation warnings)
from .integrations import MemoriAnthropic, MemoriOpenAI

# Tools and integrations
Expand Down Expand Up @@ -84,6 +84,31 @@
# Agents are not available, use placeholder None values
pass

# Integration factory functions (recommended way to use integrations)
create_openai_client: Any | None = None
create_genai_model: Any | None = None
setup_openai_interceptor: Any | None = None
setup_genai_interceptor: Any | None = None
_INTEGRATIONS_AVAILABLE = {"openai": False, "genai": False, "anthropic": False}

try:
from .integrations.openai_integration import (
create_openai_client,
setup_openai_interceptor,
)
_INTEGRATIONS_AVAILABLE["openai"] = True
except ImportError:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.
pass

try:
from .integrations.google_genai_integration import (
create_genai_model,
setup_genai_interceptor,
)
_INTEGRATIONS_AVAILABLE["genai"] = True
except ImportError:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.
pass

# Build __all__ list dynamically based on available components
_all_components = [
# Core
Expand All @@ -107,7 +132,7 @@
"MemoryTool",
"create_memory_tool",
"create_memory_search_tool",
# Integrations
# Integrations (legacy wrappers)
"MemoriOpenAI",
"MemoriAnthropic",
# Pydantic Models
Expand Down Expand Up @@ -153,4 +178,39 @@
if _AGENTS_AVAILABLE:
_all_components.extend(["MemoryAgent", "MemorySearchEngine"])

# Add integration factory functions if available
if _INTEGRATIONS_AVAILABLE["openai"]:
_all_components.extend(["create_openai_client", "setup_openai_interceptor"])

if _INTEGRATIONS_AVAILABLE["genai"]:
_all_components.extend(["create_genai_model", "setup_genai_interceptor"])

__all__ = _all_components


# Convenience function to show available integrations
def get_available_integrations():
"""
Get a dictionary of available LLM integrations.
Returns:
dict: Dictionary with provider names as keys and availability as values
"""
return _INTEGRATIONS_AVAILABLE.copy()


def get_integration_status():
"""
Print a formatted status of all available integrations.
"""
logger = get_logger(__name__)
logger.info("🔌 Memori Integration Status:")
logger.info(f" OpenAI: {'✅ Available' if _INTEGRATIONS_AVAILABLE['openai'] else '❌ Not installed'}")
logger.info(f" Google GenAI: {'✅ Available' if _INTEGRATIONS_AVAILABLE['genai'] else '❌ Not installed'}")
logger.info(f" Anthropic: {'✅ Available' if _INTEGRATIONS_AVAILABLE['anthropic'] else '❌ Not installed'}")
logger.info(f" Agents: {'✅ Available' if _AGENTS_AVAILABLE else '❌ Not available'}")


# Add these to __all__ as well
_all_components.extend(["get_available_integrations", "get_integration_status"])
__all__ = _all_components
26 changes: 23 additions & 3 deletions memori/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import anthropic
client = anthropic.Anthropic(api_key="...")
client.messages.create(...) # ✅ Auto-recorded
# Direct Google GenAI (auto-wrapping)
import google.generativeai as genai
genai.configure(api_key="...")
model = genai.GenerativeModel("gemini-pro")
model.generate_content(...) # ✅ Auto-recorded
```
The universal system automatically detects and records ALL LLM providers
Expand All @@ -36,23 +42,30 @@
from loguru import logger

# Legacy imports (all deprecated)
from . import anthropic_integration, litellm_integration, openai_integration
from . import anthropic_integration, google_genai_integration, litellm_integration, openai_integration

__all__ = [
# New interceptor classes (recommended)
"MemoriOpenAIInterceptor",
# Wrapper classes for direct SDK usage (legacy)

"MemoriOpenAI",
"MemoriAnthropic",
# Factory functions
"create_openai_client",
"setup_openai_interceptor",
"create_genai_model",
"setup_genai_interceptor",
]


# For backward compatibility, provide simple passthrough
try:
from .anthropic_integration import MemoriAnthropic
from .google_genai_integration import (
create_genai_model,
setup_genai_interceptor,
)
from .openai_integration import (
MemoriOpenAI,
MemoriOpenAIInterceptor,
Expand All @@ -78,6 +91,8 @@
"MemoriOpenAIInterceptor",
"create_openai_client",
"setup_openai_interceptor",
"create_genai_model",
"setup_genai_interceptor",
]:
# These are the new recommended classes/functions
if name == "MemoriOpenAIInterceptor":
Expand All @@ -86,8 +101,13 @@
return create_openai_client
elif name == "setup_openai_interceptor":
return setup_openai_interceptor
elif name == "create_genai_model":
return create_genai_model
elif name == "setup_genai_interceptor":
return setup_genai_interceptor
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

except ImportError:
except ImportError as e:
# Wrapper classes not available, that's fine
pass
logger.debug(f"Some integrations not available: {e}")
pass

Check warning

Code scanning / CodeQL

Unnecessary pass Warning

Unnecessary 'pass' statement.
Loading
Loading