Skip to content

Commit f580095

Browse files
committed
upsert minds
1 parent 475c5c1 commit f580095

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

minds/minds.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def create(
243243
datasources=None,
244244
parameters=None,
245245
replace=False,
246+
update=False,
246247
) -> Mind:
247248
"""
248249
Create a new mind and return it
@@ -259,6 +260,7 @@ def create(
259260
:param datasources: list of datasources used by mind, optional
260261
:param parameters, dict: other parameters of the mind, optional
261262
:param replace: if true - to remove existing mind, default is false
263+
:param update: if true - to update mind if exists, default is false
262264
:return: created mind
263265
"""
264266

@@ -284,7 +286,12 @@ def create(
284286
if 'prompt_template' not in parameters:
285287
parameters['prompt_template'] = DEFAULT_PROMPT_TEMPLATE
286288

287-
self.api.post(
289+
if update:
290+
method = self.api.put
291+
else:
292+
method = self.api.post
293+
294+
method(
288295
f'/projects/{self.project}/minds',
289296
data={
290297
'name': name,

tests/integration/test_base_flow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ def test_minds():
9393
datasources=[ds.name, ds2_cfg],
9494
prompt_template=prompt1
9595
)
96+
mind = client.minds.create(
97+
mind_name,
98+
update=True,
99+
datasources=[ds.name, ds2_cfg],
100+
prompt_template=prompt1
101+
)
96102

97103
# get
98104
mind = client.minds.get(mind_name)

tests/unit/test_unit.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ def compare_mind(self, mind, mind_json):
120120
assert mind.parameters == mind_json['parameters']
121121

122122
@patch('requests.get')
123+
@patch('requests.put')
123124
@patch('requests.post')
124125
@patch('requests.delete')
125-
def test_create(self, mock_del, mock_post, mock_get):
126+
def test_create(self, mock_del, mock_post, mock_put, mock_get):
126127
client = get_client()
127128

128129
mind_name = 'test_mind'
@@ -150,7 +151,7 @@ def check_mind_created(mind, mock_post, create_params):
150151

151152
check_mind_created(mind, mock_post, create_params)
152153

153-
# with replace
154+
# -- with replace --
154155
create_params = {
155156
'name': mind_name,
156157
'prompt_template': prompt_template,
@@ -164,6 +165,14 @@ def check_mind_created(mind, mock_post, create_params):
164165

165166
check_mind_created(mind, mock_post, create_params)
166167

168+
# -- with update --
169+
mock_del.reset_mock()
170+
mind = client.minds.create(update=True, **create_params)
171+
# is not deleted
172+
assert not mock_del.called
173+
174+
check_mind_created(mind, mock_put, create_params)
175+
167176
@patch('requests.get')
168177
@patch('requests.patch')
169178
def test_update(self, mock_patch, mock_get):

0 commit comments

Comments
 (0)