Skip to content

Commit 722911d

Browse files
authored
Merge branch 'main' into patch-1
2 parents c124e16 + dcbe1e5 commit 722911d

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,5 @@ client.datasources.drop('my_datasource')
149149
```
150150
>Note: The SDK currently does not support automatically removing a data source if it is no longer connected to any mind.
151151
152+
### Other SDKs
153+
#### [Command-Line](https://github.com/Better-Boy/minds-cli-sdk)

minds/minds.py

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from typing import List, Union, Iterable
2-
from urllib.parse import urlparse, urlunparse
3-
2+
import utils
43
from openai import OpenAI
54
import minds.utils as utils
65
import minds.exceptions as exc
76
from minds.datasources import Datasource, DatabaseConfig
87

98
DEFAULT_PROMPT_TEMPLATE = 'Use your database tools to answer the user\'s question: {{question}}'
109

11-
1210
class Mind:
1311
def __init__(
1412
self, client, name,
@@ -33,6 +31,11 @@ def __init__(
3331
self.parameters = parameters
3432
self.created_at = created_at
3533
self.updated_at = updated_at
34+
base_url = utils.get_openai_base_url(self.api.base_url)
35+
self.openai_client = OpenAI(
36+
api_key=self.api.api_key,
37+
base_url=base_url
38+
)
3639
self.datasources = datasources
3740

3841
def __repr__(self):
@@ -167,23 +170,7 @@ def completion(self, message: str, stream: bool = False) -> Union[str, Iterable[
167170
168171
:return: string if stream mode is off or iterator of ChoiceDelta objects (by openai)
169172
"""
170-
parsed = urlparse(self.api.base_url)
171-
172-
netloc = parsed.netloc
173-
if netloc == 'mdb.ai':
174-
llm_host = 'llm.mdb.ai'
175-
else:
176-
llm_host = 'ai.' + netloc
177-
178-
parsed = parsed._replace(path='', netloc=llm_host)
179-
180-
base_url = urlunparse(parsed)
181-
openai_client = OpenAI(
182-
api_key=self.api.api_key,
183-
base_url=base_url
184-
)
185-
186-
response = openai_client.chat.completions.create(
173+
response = self.openai_client.chat.completions.create(
187174
model=self.name,
188175
messages=[
189176
{'role': 'user', 'content': message}

minds/utils.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
import re
22
import minds.exceptions as exc
3+
from urllib.parse import urlparse, urlunparse
4+
5+
def get_openai_base_url(base_url: str) -> str:
6+
parsed = urlparse(base_url)
7+
8+
netloc = parsed.netloc
9+
if netloc == 'mdb.ai':
10+
llm_host = 'llm.mdb.ai'
11+
else:
12+
llm_host = 'ai.' + netloc
13+
14+
parsed = parsed._replace(path='', netloc=llm_host)
15+
16+
return urlunparse(parsed)
17+
318

419
def validate_mind_name(mind_name):
520
"""
@@ -23,4 +38,3 @@ def validate_mind_name(mind_name):
2338
# Check if the Mind name matches the pattern
2439
if not re.match(pattern, mind_name):
2540
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)