repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from unittest.mock import Mock, patch |
| #2 | |
| #3 | import pytest |
| #4 | |
| #5 | from mem0 import Memory, MemoryClient |
| #6 | from mem0.proxy.main import Chat, Completions, Mem0 |
| #7 | |
| #8 | |
| #9 | @pytest.fixture |
| #10 | def mock_memory_client(): |
| #11 | mock_client = Mock(spec=MemoryClient) |
| #12 | mock_client.user_email = None |
| #13 | return mock_client |
| #14 | |
| #15 | |
| #16 | @pytest.fixture |
| #17 | def mock_openai_embedding_client(): |
| #18 | with patch("mem0.embeddings.openai.OpenAI") as mock_openai: |
| #19 | mock_client = Mock() |
| #20 | mock_openai.return_value = mock_client |
| #21 | yield mock_client |
| #22 | |
| #23 | |
| #24 | @pytest.fixture |
| #25 | def mock_openai_llm_client(): |
| #26 | with patch("mem0.llms.openai.OpenAI") as mock_openai: |
| #27 | mock_client = Mock() |
| #28 | mock_openai.return_value = mock_client |
| #29 | yield mock_client |
| #30 | |
| #31 | |
| #32 | @pytest.fixture |
| #33 | def mock_litellm(): |
| #34 | with patch("mem0.proxy.main.litellm") as mock: |
| #35 | yield mock |
| #36 | |
| #37 | |
| #38 | def test_mem0_initialization_with_api_key(mock_openai_embedding_client, mock_openai_llm_client): |
| #39 | mem0 = Mem0() |
| #40 | assert isinstance(mem0.mem0_client, Memory) |
| #41 | assert isinstance(mem0.chat, Chat) |
| #42 | |
| #43 | |
| #44 | def test_mem0_initialization_with_config(): |
| #45 | config = {"some_config": "value"} |
| #46 | with patch("mem0.Memory.from_config") as mock_from_config: |
| #47 | mem0 = Mem0(config=config) |
| #48 | mock_from_config.assert_called_once_with(config) |
| #49 | assert isinstance(mem0.chat, Chat) |
| #50 | |
| #51 | |
| #52 | def test_mem0_initialization_without_params(mock_openai_embedding_client, mock_openai_llm_client): |
| #53 | mem0 = Mem0() |
| #54 | assert isinstance(mem0.mem0_client, Memory) |
| #55 | assert isinstance(mem0.chat, Chat) |
| #56 | |
| #57 | |
| #58 | def test_chat_initialization(mock_memory_client): |
| #59 | chat = Chat(mock_memory_client) |
| #60 | assert isinstance(chat.completions, Completions) |
| #61 | |
| #62 | |
| #63 | def test_completions_create(mock_memory_client, mock_litellm): |
| #64 | completions = Completions(mock_memory_client) |
| #65 | |
| #66 | messages = [{"role": "user", "content": "Hello, how are you?"}] |
| #67 | mock_memory_client.search.return_value = [{"memory": "Some relevant memory"}] |
| #68 | mock_litellm.completion.return_value = {"choices": [{"message": {"content": "I'm doing well, thank you!"}}]} |
| #69 | mock_litellm.supports_function_calling.return_value = True |
| #70 | |
| #71 | response = completions.create(model="gpt-4.1-nano-2025-04-14", messages=messages, user_id="test_user", temperature=0.7) |
| #72 | |
| #73 | mock_memory_client.add.assert_called_once() |
| #74 | mock_memory_client.search.assert_called_once() |
| #75 | |
| #76 | mock_litellm.completion.assert_called_once() |
| #77 | call_args = mock_litellm.completion.call_args[1] |
| #78 | assert call_args["model"] == "gpt-4.1-nano-2025-04-14" |
| #79 | assert len(call_args["messages"]) == 2 |
| #80 | assert call_args["temperature"] == 0.7 |
| #81 | |
| #82 | assert response == {"choices": [{"message": {"content": "I'm doing well, thank you!"}}]} |
| #83 | |
| #84 | |
| #85 | def test_completions_create_with_system_message(mock_memory_client, mock_litellm): |
| #86 | completions = Completions(mock_memory_client) |
| #87 | |
| #88 | messages = [ |
| #89 | {"role": "system", "content": "You are a helpful assistant."}, |
| #90 | {"role": "user", "content": "Hello, how are you?"}, |
| #91 | ] |
| #92 | mock_memory_client.search.return_value = [{"memory": "Some relevant memory"}] |
| #93 | mock_litellm.completion.return_value = {"choices": [{"message": {"content": "I'm doing well, thank you!"}}]} |
| #94 | mock_litellm.supports_function_calling.return_value = True |
| #95 | |
| #96 | completions.create(model="gpt-4.1-nano-2025-04-14", messages=messages, user_id="test_user") |
| #97 | |
| #98 | call_args = mock_litellm.completion.call_args[1] |
| #99 | assert call_args["messages"][0]["role"] == "system" |
| #100 | assert call_args["messages"][0]["content"] == "You are a helpful assistant." |
| #101 |