555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
from unittest.mock import Mock, patch
|
|
|
|
import pytest
|
|
|
|
from mem0.configs.llms.lmstudio import LMStudioConfig
|
|
from mem0.llms.lmstudio import LMStudioLLM
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_lm_studio_client():
|
|
with patch("mem0.llms.lmstudio.OpenAI") as mock_openai: # Corrected path
|
|
mock_client = Mock()
|
|
mock_client.chat.completions.create.return_value = Mock(
|
|
choices=[Mock(message=Mock(content="I'm doing well, thank you for asking!"))]
|
|
)
|
|
mock_openai.return_value = mock_client
|
|
yield mock_client
|
|
|
|
|
|
def test_generate_response_without_tools(mock_lm_studio_client):
|
|
config = LMStudioConfig(
|
|
model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
|
|
temperature=0.7,
|
|
max_tokens=100,
|
|
top_p=1.0,
|
|
)
|
|
llm = LMStudioLLM(config)
|
|
messages = [
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
{"role": "user", "content": "Hello, how are you?"},
|
|
]
|
|
|
|
response = llm.generate_response(messages)
|
|
|
|
mock_lm_studio_client.chat.completions.create.assert_called_once_with(
|
|
model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
|
|
messages=messages,
|
|
temperature=0.7,
|
|
max_tokens=100,
|
|
top_p=1.0,
|
|
response_format={"type": "json_object"},
|
|
)
|
|
|
|
assert response == "I'm doing well, thank you for asking!"
|
|
|
|
|
|
def test_generate_response_specifying_response_format(mock_lm_studio_client):
|
|
config = LMStudioConfig(
|
|
model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
|
|
temperature=0.7,
|
|
max_tokens=100,
|
|
top_p=1.0,
|
|
lmstudio_response_format={"type": "json_schema"}, # Specifying the response format in config
|
|
)
|
|
llm = LMStudioLLM(config)
|
|
messages = [
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
{"role": "user", "content": "Hello, how are you?"},
|
|
]
|
|
|
|
response = llm.generate_response(messages)
|
|
|
|
mock_lm_studio_client.chat.completions.create.assert_called_once_with(
|
|
model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
|
|
messages=messages,
|
|
temperature=0.7,
|
|
max_tokens=100,
|
|
top_p=1.0,
|
|
response_format={"type": "json_schema"},
|
|
)
|
|
|
|
assert response == "I'm doing well, thank you for asking!"
|