11import os
22import copy
33
4- api_key = os .getenv ('API_KEY' )
5- base_url = 'https://dev.mindsdb.com'
6-
74from minds .client import Client
85
9- client = Client (api_key , base_url = base_url )
10-
116import logging
127logging .basicConfig (level = logging .DEBUG )
138
1611from minds .exceptions import ObjectNotFound
1712
1813
14+ def get_client ():
15+ api_key = os .getenv ('API_KEY' )
16+ base_url = os .getenv ('BASE_URL' , 'https://dev.mindsdb.com' )
17+
18+ return Client (api_key , base_url = base_url )
19+
20+
1921def test_datasources ():
22+ client = get_client ()
2023
2124 # remove previous object
2225 try :
@@ -41,6 +44,8 @@ def test_datasources():
4144
4245
4346def test_minds ():
47+ client = get_client ()
48+
4449 ds_name = 'test_datasource_'
4550 ds_name2 = 'test_datasource2_'
4651 mind_name = 'int_test_mind_'
@@ -63,6 +68,7 @@ def test_minds():
6368 # second datasource
6469 ds2_cfg = copy .copy (example_ds )
6570 ds2_cfg .name = ds_name2
71+ ds2_cfg .tables = ['home_rentals' ]
6672
6773 # create
6874 mind = client .minds .create (
@@ -118,6 +124,23 @@ def test_minds():
118124 # completion
119125 answer = mind .completion ('say hello' )
120126 assert 'hola' in answer .lower ()
127+
128+ # ask about data
129+ answer = mind .completion ('what is max rental price in home rental?' )
130+ assert '5602' in answer .replace (' ' , '' ).replace (',' , '' )
131+
132+ # limit tables
133+ mind .del_datasource (ds .name )
134+ mind .add_datasource (ds_name2 )
135+ assert len (mind .datasources ) == 1
136+
137+ answer = mind .completion ('what is max rental price in home rental?' )
138+ assert '5602' in answer .replace (' ' , '' ).replace (',' , '' )
139+
140+ # not accessible table
141+ answer = mind .completion ('what is max price in car sales?' )
142+ assert '145000' not in answer .replace (' ' , '' ).replace (',' , '' )
143+
121144 # stream completion
122145 success = False
123146 for chunk in mind .completion ('say hello' , stream = True ):
0 commit comments