Add TogetherAI support (#1485)
This commit is contained in:
@@ -3,14 +3,14 @@ from unittest.mock import Mock, patch
|
||||
from mem0.llms.openai import OpenAILLM
|
||||
|
||||
@pytest.fixture
|
||||
def mock_groq_client():
|
||||
with patch('mem0.llms.openai.OpenAI') as mock_groq:
|
||||
def mock_openai_client():
|
||||
with patch('mem0.llms.openai.OpenAI') as mock_openai:
|
||||
mock_client = Mock()
|
||||
mock_groq.return_value = mock_client
|
||||
mock_openai.return_value = mock_client
|
||||
yield mock_client
|
||||
|
||||
|
||||
def test_generate_response_without_tools(mock_groq_client):
|
||||
def test_generate_response_without_tools(mock_openai_client):
|
||||
llm = OpenAILLM()
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
@@ -19,18 +19,18 @@ def test_generate_response_without_tools(mock_groq_client):
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.choices = [Mock(message=Mock(content="I'm doing well, thank you for asking!"))]
|
||||
mock_groq_client.chat.completions.create.return_value = mock_response
|
||||
mock_openai_client.chat.completions.create.return_value = mock_response
|
||||
|
||||
response = llm.generate_response(messages)
|
||||
|
||||
mock_groq_client.chat.completions.create.assert_called_once_with(
|
||||
mock_openai_client.chat.completions.create.assert_called_once_with(
|
||||
model="gpt-4o",
|
||||
messages=messages
|
||||
)
|
||||
assert response.choices[0].message.content == "I'm doing well, thank you for asking!"
|
||||
|
||||
|
||||
def test_generate_response_with_tools(mock_groq_client):
|
||||
def test_generate_response_with_tools(mock_openai_client):
|
||||
llm = OpenAILLM()
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
@@ -55,11 +55,11 @@ def test_generate_response_with_tools(mock_groq_client):
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.choices = [Mock(message=Mock(content="Memory added successfully."))]
|
||||
mock_groq_client.chat.completions.create.return_value = mock_response
|
||||
mock_openai_client.chat.completions.create.return_value = mock_response
|
||||
|
||||
response = llm.generate_response(messages, tools=tools)
|
||||
|
||||
mock_groq_client.chat.completions.create.assert_called_once_with(
|
||||
mock_openai_client.chat.completions.create.assert_called_once_with(
|
||||
model="gpt-4o",
|
||||
messages=messages,
|
||||
tools=tools,
|
||||
|
||||
Reference in New Issue
Block a user