[Update] Default LLM (#3587)
This commit is contained in:
@@ -5,7 +5,7 @@ import pytest
|
||||
from mem0.configs.llms.azure import AzureOpenAIConfig
|
||||
from mem0.llms.azure_openai import AzureOpenAILLM
|
||||
|
||||
MODEL = "gpt-4o" # or your custom deployment name
|
||||
MODEL = "gpt-4.1-nano-2025-04-14" # or your custom deployment name
|
||||
TEMPERATURE = 0.7
|
||||
MAX_TOKENS = 100
|
||||
TOP_P = 1.0
|
||||
@@ -191,8 +191,8 @@ def test_init_with_env_vars(monkeypatch):
|
||||
http_client=None,
|
||||
default_headers=None,
|
||||
)
|
||||
# Should default to "gpt-4o" if model is None
|
||||
assert llm.config.model == "gpt-4o"
|
||||
# Should default to "gpt-4.1-nano-2025-04-14" if model is None
|
||||
assert llm.config.model == "gpt-4.1-nano-2025-04-14"
|
||||
|
||||
|
||||
def test_init_with_default_azure_credential(monkeypatch):
|
||||
|
||||
@@ -56,7 +56,7 @@ def test_init_with_default_credential(mock_credential, mock_token_provider, mock
|
||||
mock_token_provider.return_value = "token-provider"
|
||||
llm = AzureOpenAIStructuredLLM(config)
|
||||
# Should set default model if not provided
|
||||
assert llm.config.model == "gpt-4o-2024-08-06"
|
||||
assert llm.config.model == "gpt-4.1-nano-2025-04-14"
|
||||
mock_credential.assert_called_once()
|
||||
mock_token_provider.assert_called_once_with(mock_credential.return_value, SCOPE)
|
||||
mock_azure_openai.assert_called_once()
|
||||
@@ -91,7 +91,7 @@ def test_init_with_placeholder_api_key_uses_default_credential(
|
||||
config = DummyConfig(model=None, azure_kwargs=DummyAzureKwargs(api_key="your-api-key"))
|
||||
mock_token_provider.return_value = "token-provider"
|
||||
llm = AzureOpenAIStructuredLLM(config)
|
||||
assert llm.config.model == "gpt-4o-2024-08-06"
|
||||
assert llm.config.model == "gpt-4.1-nano-2025-04-14"
|
||||
mock_credential.assert_called_once()
|
||||
mock_token_provider.assert_called_once_with(mock_credential.return_value, SCOPE)
|
||||
mock_azure_openai.assert_called_once()
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_generate_response_with_unsupported_model(mock_litellm):
|
||||
|
||||
|
||||
def test_generate_response_without_tools(mock_litellm):
|
||||
config = BaseLlmConfig(model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1)
|
||||
config = BaseLlmConfig(model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1)
|
||||
llm = litellm.LiteLLM(config)
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
@@ -39,13 +39,13 @@ def test_generate_response_without_tools(mock_litellm):
|
||||
response = llm.generate_response(messages)
|
||||
|
||||
mock_litellm.completion.assert_called_once_with(
|
||||
model="gpt-4o", messages=messages, temperature=0.7, max_tokens=100, top_p=1.0
|
||||
model="gpt-4.1-nano-2025-04-14", messages=messages, temperature=0.7, max_tokens=100, top_p=1.0
|
||||
)
|
||||
assert response == "I'm doing well, thank you for asking!"
|
||||
|
||||
|
||||
def test_generate_response_with_tools(mock_litellm):
|
||||
config = BaseLlmConfig(model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1)
|
||||
config = BaseLlmConfig(model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1)
|
||||
llm = litellm.LiteLLM(config)
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
@@ -82,7 +82,7 @@ def test_generate_response_with_tools(mock_litellm):
|
||||
response = llm.generate_response(messages, tools=tools)
|
||||
|
||||
mock_litellm.completion.assert_called_once_with(
|
||||
model="gpt-4o", messages=messages, temperature=0.7, max_tokens=100, top_p=1, tools=tools, tool_choice="auto"
|
||||
model="gpt-4.1-nano-2025-04-14", messages=messages, temperature=0.7, max_tokens=100, top_p=1, tools=tools, tool_choice="auto"
|
||||
)
|
||||
|
||||
assert response["content"] == "I've added the memory for you."
|
||||
|
||||
+11
-11
@@ -17,7 +17,7 @@ def mock_openai_client():
|
||||
|
||||
def test_openai_llm_base_url():
|
||||
# case1: default config: with openai official base url
|
||||
config = OpenAIConfig(model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1.0, api_key="api_key")
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1.0, api_key="api_key")
|
||||
llm = OpenAILLM(config)
|
||||
# Note: openai client will parse the raw base_url into a URL object, which will have a trailing slash
|
||||
assert str(llm.client.base_url) == "https://api.openai.com/v1/"
|
||||
@@ -25,7 +25,7 @@ def test_openai_llm_base_url():
|
||||
# case2: with env variable OPENAI_API_BASE
|
||||
provider_base_url = "https://api.provider.com/v1"
|
||||
os.environ["OPENAI_BASE_URL"] = provider_base_url
|
||||
config = OpenAIConfig(model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1.0, api_key="api_key")
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1.0, api_key="api_key")
|
||||
llm = OpenAILLM(config)
|
||||
# Note: openai client will parse the raw base_url into a URL object, which will have a trailing slash
|
||||
assert str(llm.client.base_url) == provider_base_url + "/"
|
||||
@@ -33,7 +33,7 @@ def test_openai_llm_base_url():
|
||||
# case3: with config.openai_base_url
|
||||
config_base_url = "https://api.config.com/v1"
|
||||
config = OpenAIConfig(
|
||||
model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1.0, api_key="api_key", openai_base_url=config_base_url
|
||||
model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1.0, api_key="api_key", openai_base_url=config_base_url
|
||||
)
|
||||
llm = OpenAILLM(config)
|
||||
# Note: openai client will parse the raw base_url into a URL object, which will have a trailing slash
|
||||
@@ -41,7 +41,7 @@ def test_openai_llm_base_url():
|
||||
|
||||
|
||||
def test_generate_response_without_tools(mock_openai_client):
|
||||
config = OpenAIConfig(model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1.0)
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1.0)
|
||||
llm = OpenAILLM(config)
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
@@ -55,13 +55,13 @@ def test_generate_response_without_tools(mock_openai_client):
|
||||
response = llm.generate_response(messages)
|
||||
|
||||
mock_openai_client.chat.completions.create.assert_called_once_with(
|
||||
model="gpt-4o", messages=messages, temperature=0.7, max_tokens=100, top_p=1.0, store=False
|
||||
model="gpt-4.1-nano-2025-04-14", messages=messages, temperature=0.7, max_tokens=100, top_p=1.0, store=False
|
||||
)
|
||||
assert response == "I'm doing well, thank you for asking!"
|
||||
|
||||
|
||||
def test_generate_response_with_tools(mock_openai_client):
|
||||
config = OpenAIConfig(model="gpt-4o", temperature=0.7, max_tokens=100, top_p=1.0)
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", temperature=0.7, max_tokens=100, top_p=1.0)
|
||||
llm = OpenAILLM(config)
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
@@ -97,7 +97,7 @@ def test_generate_response_with_tools(mock_openai_client):
|
||||
response = llm.generate_response(messages, tools=tools)
|
||||
|
||||
mock_openai_client.chat.completions.create.assert_called_once_with(
|
||||
model="gpt-4o", messages=messages, temperature=0.7, max_tokens=100, top_p=1.0, tools=tools, tool_choice="auto", store=False
|
||||
model="gpt-4.1-nano-2025-04-14", messages=messages, temperature=0.7, max_tokens=100, top_p=1.0, tools=tools, tool_choice="auto", store=False
|
||||
)
|
||||
|
||||
assert response["content"] == "I've added the memory for you."
|
||||
@@ -110,7 +110,7 @@ def test_response_callback_invocation(mock_openai_client):
|
||||
# Setup mock callback
|
||||
mock_callback = Mock()
|
||||
|
||||
config = OpenAIConfig(model="gpt-4o", response_callback=mock_callback)
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", response_callback=mock_callback)
|
||||
llm = OpenAILLM(config)
|
||||
messages = [{"role": "user", "content": "Test callback"}]
|
||||
|
||||
@@ -131,7 +131,7 @@ def test_response_callback_invocation(mock_openai_client):
|
||||
|
||||
|
||||
def test_no_response_callback(mock_openai_client):
|
||||
config = OpenAIConfig(model="gpt-4o")
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14")
|
||||
llm = OpenAILLM(config)
|
||||
messages = [{"role": "user", "content": "Test no callback"}]
|
||||
|
||||
@@ -153,7 +153,7 @@ def test_callback_exception_handling(mock_openai_client):
|
||||
def faulty_callback(*args):
|
||||
raise ValueError("Callback error")
|
||||
|
||||
config = OpenAIConfig(model="gpt-4o", response_callback=faulty_callback)
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", response_callback=faulty_callback)
|
||||
llm = OpenAILLM(config)
|
||||
messages = [{"role": "user", "content": "Test exception"}]
|
||||
|
||||
@@ -172,7 +172,7 @@ def test_callback_exception_handling(mock_openai_client):
|
||||
|
||||
def test_callback_with_tools(mock_openai_client):
|
||||
mock_callback = Mock()
|
||||
config = OpenAIConfig(model="gpt-4o", response_callback=mock_callback)
|
||||
config = OpenAIConfig(model="gpt-4.1-nano-2025-04-14", response_callback=mock_callback)
|
||||
llm = OpenAILLM(config)
|
||||
messages = [{"role": "user", "content": "Test tools"}]
|
||||
tools = [
|
||||
|
||||
+3
-3
@@ -68,14 +68,14 @@ def test_completions_create(mock_memory_client, mock_litellm):
|
||||
mock_litellm.completion.return_value = {"choices": [{"message": {"content": "I'm doing well, thank you!"}}]}
|
||||
mock_litellm.supports_function_calling.return_value = True
|
||||
|
||||
response = completions.create(model="gpt-4o-mini", messages=messages, user_id="test_user", temperature=0.7)
|
||||
response = completions.create(model="gpt-4.1-nano-2025-04-14", messages=messages, user_id="test_user", temperature=0.7)
|
||||
|
||||
mock_memory_client.add.assert_called_once()
|
||||
mock_memory_client.search.assert_called_once()
|
||||
|
||||
mock_litellm.completion.assert_called_once()
|
||||
call_args = mock_litellm.completion.call_args[1]
|
||||
assert call_args["model"] == "gpt-4o-mini"
|
||||
assert call_args["model"] == "gpt-4.1-nano-2025-04-14"
|
||||
assert len(call_args["messages"]) == 2
|
||||
assert call_args["temperature"] == 0.7
|
||||
|
||||
@@ -93,7 +93,7 @@ def test_completions_create_with_system_message(mock_memory_client, mock_litellm
|
||||
mock_litellm.completion.return_value = {"choices": [{"message": {"content": "I'm doing well, thank you!"}}]}
|
||||
mock_litellm.supports_function_calling.return_value = True
|
||||
|
||||
completions.create(model="gpt-4o-mini", messages=messages, user_id="test_user")
|
||||
completions.create(model="gpt-4.1-nano-2025-04-14", messages=messages, user_id="test_user")
|
||||
|
||||
call_args = mock_litellm.completion.call_args[1]
|
||||
assert call_args["messages"][0]["role"] == "system"
|
||||
|
||||
Reference in New Issue
Block a user