Skip to content

Commit b8dd225

Browse files
authored
🧪 modify test_conversation_management_service.py & test_exa_search_tool.py
2 parents 1bdaa7a + 2deca72 commit b8dd225

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

‎sdk/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
dependencies = [
2929
"aiofiles>=24.1.0",
3030
"elasticsearch==8.17.2",
31-
"exa_py>=1.9.1",
31+
"exa_py==1.14.0",
3232
"httpx[socks]>=0.28.1",
3333
"numpy>=1.26.4",
3434
"openai>=1.69.0",

‎test/backend/services/test_conversation_management_service.py‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import json
33
from datetime import datetime
4-
from unittest.mock import patch, MagicMock, mock_open
4+
from unittest.mock import patch, MagicMock
55

66
# Mock boto3 and minio client before importing the module under test
77
import sys
@@ -213,14 +213,9 @@ def test_extract_user_messages(self):
213213
self.assertIn("AI stands for Artificial Intelligence.", result)
214214

215215
@patch('backend.services.conversation_management_service.OpenAIServerModel')
216-
@patch('backend.services.conversation_management_service.open', new_callable=mock_open, read_data="""
217-
SYSTEM_PROMPT: "Generate a short title"
218-
USER_PROMPT: "Generate a title for: {{content}}"
219-
""")
220-
@patch('backend.services.conversation_management_service.yaml.safe_load')
221-
@patch('os.getenv')
216+
@patch('backend.services.conversation_management_service.get_generate_title_prompt_template')
222217
@patch('backend.services.conversation_management_service.tenant_config_manager.get_model_config')
223-
def test_call_llm_for_title(self, mock_get_model_config, mock_getenv, mock_yaml_load, mock_open_file, mock_openai):
218+
def test_call_llm_for_title(self, mock_get_model_config, mock_get_prompt_template, mock_openai):
224219
# Setup
225220
mock_get_model_config.return_value = {
226221
"model_name": "gpt-4",
@@ -229,17 +224,11 @@ def test_call_llm_for_title(self, mock_get_model_config, mock_getenv, mock_yaml_
229224
"api_key": "fake-key"
230225
}
231226

232-
mock_getenv.side_effect = lambda key: {
233-
'LLM_MODEL_NAME': 'gpt-4',
234-
'LLM_MODEL_URL': 'http://example.com',
235-
'LLM_API_KEY': 'fake-key'
236-
}.get(key)
237-
238-
mock_yaml_data = {
227+
mock_prompt_template = {
239228
"SYSTEM_PROMPT": "Generate a short title",
240229
"USER_PROMPT": "Generate a title for: {{content}}"
241230
}
242-
mock_yaml_load.return_value = mock_yaml_data
231+
mock_get_prompt_template.return_value = mock_prompt_template
243232

244233
mock_llm_instance = mock_openai.return_value
245234
mock_response = MagicMock()
@@ -253,6 +242,7 @@ def test_call_llm_for_title(self, mock_get_model_config, mock_getenv, mock_yaml_
253242
self.assertEqual(result, "AI Discussion")
254243
mock_openai.assert_called_once()
255244
mock_llm_instance.assert_called_once()
245+
mock_get_prompt_template.assert_called_once_with(language='zh')
256246

257247
@patch('backend.services.conversation_management_service.rename_conversation')
258248
def test_update_conversation_title(self, mock_rename_conversation):

0 commit comments

Comments
 (0)