Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing release issues #54

Merged
merged 10 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion minds/datasources/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions minds/minds.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions tests/integration/test_base_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

18 changes: 9 additions & 9 deletions tests/unit/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -132,17 +132,17 @@ 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)
assert create_params.get('prompt_template') == request.get('parameters', {}).get('prompt_template')

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 = {
Expand All @@ -156,15 +156,15 @@ 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()
mind = client.minds.create(update=True, **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')
Expand Down
Loading