Skip to content

Commit 1e513e6

Browse files
committed
addressed review comments
1 parent 0e1ea94 commit 1e513e6

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

minds/minds.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from typing import List, Union, Iterable
22
from urllib.parse import urlparse, urlunparse
3-
from datetime import datetime
43

54
from openai import OpenAI
65
import minds.utils as utils
76
import minds.exceptions as exc
8-
97
from minds.datasources import Datasource, DatabaseConfig
108

119
DEFAULT_PROMPT_TEMPLATE = 'Use your database tools to answer the user\'s question: {{question}}'
@@ -25,9 +23,6 @@ def __init__(
2523
self.api = client.api
2624
self.client = client
2725
self.project = 'mindsdb'
28-
29-
if not utils.validate_mind_name(name):
30-
raise exc.MindNameInvalid("Mind name should start with a letter and contain only letters, numbers or underscore, with a maximum of 32 characters. Spaces are not allowed.")
3126

3227
self.name = name
3328
self.model_name = model_name
@@ -78,8 +73,8 @@ def update(
7873
"""
7974
data = {}
8075

81-
if not utils.validate_mind_name(name):
82-
raise exc.MindNameInvalid("Mind name should start with a letter and contain only letters, numbers or underscore, with a maximum of 32 characters. Spaces are not allowed.")
76+
if name is not None:
77+
utils.validate_mind_name(name)
8378

8479
if datasources is not None:
8580
ds_names = []
@@ -222,8 +217,6 @@ def get(self, name: str) -> Mind:
222217
:param name: name of the mind
223218
:return: a mind object
224219
"""
225-
if not utils.validate_mind_name(name):
226-
raise exc.MindNameInvalid("Mind name should start with a letter and contain only letters, numbers or underscore, with a maximum of 32 characters. Spaces are not allowed.")
227220

228221
item = self.api.get(f'/projects/{self.project}/minds/{name}').json()
229222
return Mind(self.client, **item)
@@ -270,8 +263,8 @@ def create(
270263
:return: created mind
271264
"""
272265

273-
if not utils.validate_mind_name(name):
274-
raise exc.MindNameInvalid("Mind name should start with a letter and contain only letters, numbers or underscore, with a maximum of 32 characters. Spaces are not allowed.")
266+
if name is not None:
267+
utils.validate_mind_name(name)
275268

276269
if replace:
277270
try:
@@ -316,9 +309,4 @@ def drop(self, name: str):
316309
:param name: name of the mind
317310
"""
318311

319-
if not utils.validate_mind_name(name):
320-
raise exc.MindNameInvalid("""
321-
Mind name should start with a letter and contain only letters, numbers or underscore, with a maximum of 32 characters.
322-
Spaces are not allowed.""")
323-
324312
self.api.delete(f'/projects/{self.project}/minds/{name}')

minds/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import minds.exceptions as exc
23

34
def validate_mind_name(mind_name):
45
"""
@@ -20,4 +21,6 @@ def validate_mind_name(mind_name):
2021
pattern = r'^[A-Za-z][A-Za-z0-9_]{0,31}$'
2122

2223
# Check if the Mind name matches the pattern
23-
return re.match(pattern, mind_name)
24+
if not re.match(pattern, mind_name):
25+
raise exc.MindNameInvalid("Mind name should start with a letter and contain only letters, numbers or underscore, with a maximum of 32 characters. Spaces are not allowed.")
26+

0 commit comments

Comments
 (0)