File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 1- from minds .client import Client
1+ import time
2+
23from openai import OpenAI
34
5+ from minds .client import Client
6+
47
58# Basic Setup and Workflow
69
4346mind = client .minds .create (name = 'mind_name' )
4447mind .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)
4766openai_client = OpenAI (api_key = API_KEY , base_url = BASE_URL )
67+
4868completion = openai_client .chat .completions .create (
4969 model = mind .name ,
5070 messages = [
6383 stream = True
6484)
6585for 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)
6989response = mind .completion ('How many three-bedroom houses were sold in 2008?' )
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
92113mind = client .minds .update (
99120 }
100121 ],
101122)
123+ wait_for_mind (mind )
102124
103125# list
104126minds = client .minds .list ()
You can’t perform that action at this time.
0 commit comments