@@ -280,7 +280,7 @@ class Assistant:AssistantResource {
280280
281281 if ($files ) {
282282 # upload the files and create new vector store
283- $file_ids = $this.client.files.create (@ { " files" = $files }) | Select-Object - ExpandProperty id
283+ $file_ids = $this.client.files.create (@ { " files" = $files }) | Select-Object - ExpandProperty id
284284 $body.Add (" tools" , @ (
285285 @ {
286286 " type" = " file_search"
@@ -294,6 +294,7 @@ class Assistant:AssistantResource {
294294 })
295295 }
296296 })
297+
297298 }
298299
299300 if ($vector_store_ids -and $vector_store_ids.Count -gt 0 ) {
@@ -355,26 +356,39 @@ class AssistantObject:AssistantResourceObject {
355356
356357 AssistantObject([psobject ]$data ):base($data ) {}
357358
358- [void ]chat() {
359+ [void ]chat($clean = $false ) {
359360 if (-not $this.thread ) {
360361 # create a thread, and associate the assistant id
361362 $this.thread = $this.client.threads.create ($this.id )
362363 }
363364
364- while ($true ) {
365- # ask use to input, until the user type 'q' or 'bye'
366- $prompt = Read-Host " >"
367- if ($prompt -eq " q" -or $prompt -eq " bye" ) {
368- break
369- }
365+ try {
366+ while ($true ) {
367+ # ask use to input, until the user type 'q' or 'bye'
368+ $prompt = Read-Host " >"
369+ if ($prompt -eq " q" -or $prompt -eq " bye" ) {
370+ break
371+ }
370372
371- # send the message to the thread
372- $response = $this.thread.send ($prompt ).run().get_last_message()
373+ # send the message to the thread
374+ $response = $this.thread.send ($prompt ).run().get_last_message()
373375
374- if ($response ) {
375- Write-Host $response - ForegroundColor Green
376+ if ($response ) {
377+ Write-Host $response - ForegroundColor Green
378+ }
379+ }
380+ }
381+ finally {
382+ $this.client.threads.delete ($this.thread.id )
383+ if ($clean ) {
384+ Write-Host " clean up the thread, assistant, and vector_store..." - ForegroundColor Yellow
385+ # clean up the thread, assistant, and vector_store
386+ $vc_id = $this.tool_resources.file_search.vector_store_ids [0 ]
387+ $this.client.vector_stores.delete ($vc_id )
388+ $this.client.assistants.delete ($this.id )
376389 }
377390 }
391+
378392 }
379393}
380394
@@ -476,8 +490,16 @@ class Thread:AssistantResource {
476490 }
477491}
478492
493+ class Vector_storeObject :AssistantResourceObject {
494+ Vector_storeObject([psobject ]$data ):base($data ) {}
495+
496+ [string []]file_ids() {
497+ return $this.client.web (" vector_stores/$ ( $this.id ) /files" ).data | Select-Object - ExpandProperty id
498+ }
499+ }
500+
479501class Vector_store :AssistantResource {
480- Vector_store([OpenAIClient ]$client ): base($client , " vector_stores" , $null ) {}
502+ Vector_store([OpenAIClient ]$client ): base($client , " vector_stores" , " Vector_storeObject " ) {}
481503
482504 [psobject ]create([hashtable ]$body ) {
483505 <#
0 commit comments