Skip to content

Commit 97248bf

Browse files
updated base usage to account for async loader
1 parent e49a839 commit 97248bf

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

examples/base_usage.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from minds.client import Client
1+
import time
2+
23
from openai import OpenAI
34

5+
from minds.client import Client
6+
47

58
# Basic Setup and Workflow
69

@@ -43,8 +46,25 @@
4346
mind = client.minds.create(name='mind_name')
4447
mind.add_datasource(datasource.name, tables=['house_sales'])
4548

49+
# wait until Mind is ready
50+
def wait_for_mind(mind):
51+
status = mind.status
52+
while status != 'COMPLETED':
53+
print(f'Mind status: {status}')
54+
time.sleep(3)
55+
mind = client.minds.get(mind.name)
56+
status = mind.status
57+
58+
if status == 'FAILED':
59+
raise Exception('Mind creation failed')
60+
61+
print('Mind creation successful!')
62+
63+
wait_for_mind(mind)
64+
4665
# chat with the Mind using the OpenAI-compatible Completions API (without streaming)
4766
openai_client = OpenAI(api_key=API_KEY, base_url=BASE_URL)
67+
4868
completion = openai_client.chat.completions.create(
4969
model=mind.name,
5070
messages=[
@@ -63,7 +83,7 @@
6383
stream=True
6484
)
6585
for chunk in completion_stream:
66-
print(chunk.choices[0].delta)
86+
print(chunk.choices[0].delta.content)
6787

6888
# or chat with the Mind directly (without streaming)
6989
response = mind.completion('How many three-bedroom houses were sold in 2008?')
@@ -82,11 +102,12 @@
82102
datasources=[
83103
{
84104
'name': datasource.name,
85-
'tables': ['house_sales']
105+
'tables': ['home_rentals']
86106
}
87107
],
88108
replace=True
89109
)
110+
wait_for_mind(mind)
90111

91112
# update
92113
mind = client.minds.update(
@@ -99,6 +120,7 @@
99120
}
100121
],
101122
)
123+
wait_for_mind(mind)
102124

103125
# list
104126
minds = client.minds.list()

0 commit comments

Comments
 (0)