diff --git a/minds/datasources/datasources.py b/minds/datasources/datasources.py index 2e548e1..56e8d52 100644 --- a/minds/datasources/datasources.py +++ b/minds/datasources/datasources.py @@ -38,7 +38,7 @@ def create(self, ds_config: DatabaseConfig, update=False): name = ds_config.name if update: - self.api.put('/datasources', data=ds_config.model_dump()) + self.api.put(f'/datasources/{name}', data=ds_config.model_dump()) else: self.api.post('/datasources', data=ds_config.model_dump()) return self.get(name) diff --git a/minds/minds.py b/minds/minds.py index de643a9..82508a3 100644 --- a/minds/minds.py +++ b/minds/minds.py @@ -1,5 +1,4 @@ from typing import List, Union, Iterable -import utils from openai import OpenAI import minds.utils as utils import minds.exceptions as exc @@ -278,11 +277,13 @@ def create( if update: method = self.api.put + url = f'/projects/{self.project}/minds/{name}' else: method = self.api.post + url = f'/projects/{self.project}/minds' method( - f'/projects/{self.project}/minds', + url, data={ 'name': name, 'model_name': model_name, diff --git a/tests/integration/test_base_flow.py b/tests/integration/test_base_flow.py index 7f37b6d..d5c3cfe 100644 --- a/tests/integration/test_base_flow.py +++ b/tests/integration/test_base_flow.py @@ -73,7 +73,7 @@ def test_minds(): # prepare datasources ds_cfg = copy.copy(example_ds) ds_cfg.name = ds_name - ds = client.datasources.create(example_ds, replace=True) + ds = client.datasources.create(example_ds, update=True) # second datasource ds2_cfg = copy.copy(example_ds) @@ -82,7 +82,7 @@ def test_minds(): # create with pytest.raises(MindNameInvalid): - mind = client.minds.create( + client.minds.create( invalid_mind_name, datasources=[ds], provider='openai' @@ -110,9 +110,6 @@ def test_minds(): mind = client.minds.get(mind_name) assert len(mind.datasources) == 2 assert mind.prompt_template == prompt1 - - with pytest.raises(MindNameInvalid): - client.minds.get(invalid_mind_name) # list mind_list = client.minds.list() @@ -179,6 +176,4 @@ def test_minds(): client.minds.drop(mind_name2) client.datasources.drop(ds.name) client.datasources.drop(ds2_cfg.name) - - with pytest.raises(MindNameInvalid): - client.minds.drop(invalid_mind_name) + diff --git a/tests/unit/test_unit.py b/tests/unit/test_unit.py index ee6819a..a3125d1 100644 --- a/tests/unit/test_unit.py +++ b/tests/unit/test_unit.py @@ -44,19 +44,19 @@ def test_create_datasources(self, mock_del, mock_post, mock_put, mock_get): response_mock(mock_get, example_ds.model_dump()) ds = client.datasources.create(example_ds) - def check_ds_created(ds, mock_post): + def check_ds_created(ds, mock_post, url): self._compare_ds(ds, example_ds) args, kwargs = mock_post.call_args assert kwargs['headers'] == {'Authorization': 'Bearer ' + API_KEY} assert kwargs['json'] == example_ds.model_dump() - assert args[0] == 'https://mdb.ai/api/datasources' + assert args[0] == url - check_ds_created(ds, mock_post) + check_ds_created(ds, mock_post, 'https://mdb.ai/api/datasources') # with update ds = client.datasources.create(example_ds, update=True) - check_ds_created(ds, mock_put) + check_ds_created(ds, mock_put, f'https://mdb.ai/api/datasources/{ds.name}') @patch('requests.get') def test_get_datasource(self, mock_get): @@ -132,9 +132,9 @@ def test_create(self, mock_del, mock_post, mock_put, mock_get): } mind = client.minds.create(**create_params) - def check_mind_created(mind, mock_post, create_params): + def check_mind_created(mind, mock_post, create_params, url): args, kwargs = mock_post.call_args - assert args[0].endswith('/api/projects/mindsdb/minds') + assert args[0].endswith(url) request = kwargs['json'] for key in ('name', 'datasources', 'provider', 'model_name'),: assert request.get(key) == create_params.get(key) @@ -142,7 +142,7 @@ def check_mind_created(mind, mock_post, create_params): self.compare_mind(mind, self.mind_json) - check_mind_created(mind, mock_post, create_params) + check_mind_created(mind, mock_post, create_params, '/api/projects/mindsdb/minds') # -- with replace -- create_params = { @@ -156,7 +156,7 @@ def check_mind_created(mind, mock_post, create_params): args, _ = mock_del.call_args assert args[0].endswith(f'/api/projects/mindsdb/minds/{mind_name}') - check_mind_created(mind, mock_post, create_params) + check_mind_created(mind, mock_post, create_params, '/api/projects/mindsdb/minds') # -- with update -- mock_del.reset_mock() @@ -164,7 +164,7 @@ def check_mind_created(mind, mock_post, create_params): # is not deleted assert not mock_del.called - check_mind_created(mind, mock_put, create_params) + check_mind_created(mind, mock_put, create_params, f'/api/projects/mindsdb/minds/{mind_name}') @patch('requests.get') @patch('requests.patch')