Skip to content

Commit 0d2ee9b

Browse files
committed
update
1 parent c5ce987 commit 0d2ee9b

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

code365scripts.openai/Public/Assistant/OpenAIClient.ps1

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class OpenAIClient {
1010
[System.Management.Automation.HiddenAttribute()]
1111
[string]$apiVersion
1212

13-
[Assistant]$assistant
13+
[Assistant]$assistants
14+
[Vector_store]$vector_stores
15+
[File]$files
16+
[Thread]$threads
1417

1518
OpenAIClient([string]$apiKey, [string]$baseUri, [string]$model, [string]$apiVersion = "2024-05-01-preview") {
1619
$this.apikey = $apiKey
@@ -47,7 +50,10 @@ class OpenAIClient {
4750
$this.apiVersion = ""
4851
}
4952

50-
$this.assistant = [Assistant]::new($this)
53+
$this.assistants = [Assistant]::new($this)
54+
$this.vector_stores = [Vector_store]::new($this)
55+
$this.files = [File]::new($this)
56+
$this.threads = [Thread]::new($this)
5157
}
5258

5359
[psobject]web(
@@ -77,51 +83,39 @@ class AssistantResource {
7783
[System.Management.Automation.HiddenAttribute()]
7884
[OpenAIClient]$Client
7985
[System.Management.Automation.HiddenAttribute()]
80-
[string]$urlfragment
86+
[string]$urifragment
8187

82-
AssistantResource([OpenAIClient]$client) {
88+
AssistantResource([OpenAIClient]$client, [string]$urifragment) {
8389
$this.Client = $client
90+
$this.urifragment = $urifragment
8491
}
85-
86-
AssistantResource() {
87-
$this.Client = [OpenAIClient]::new()
88-
}
89-
9092
[psobject[]]list() {
91-
return $this.Client.web($this.urlfragment).data
93+
return $this.Client.web($this.urifragment).data
9294
}
9395

9496
[psobject]get([string]$id) {
95-
return $this.Client.web("$($this.urlfragment)/$id")
97+
return $this.Client.web("$($this.urifragment)/$id")
9698
}
9799

98100
[psobject]delete([string]$id) {
99101
# remove all the assistants
100-
return $this.Client.web("$($this.urlfragment)/$id", "DELETE", @{})
102+
return $this.Client.web("$($this.urifragment)/$id", "DELETE", @{})
101103
}
102104

103-
[psobject]create([string]$name, [string]$model, [string]$instructions) {
104-
$body = @{
105-
"name" = $name
106-
"model" = $model
107-
"instructions" = $instructions
108-
}
109-
110-
return $this.Client.web("$($this.urlfragment)", "POST", $body)
105+
[psobject]create([hashtable]$body) {
106+
return $this.Client.web("$($this.urifragment)", "POST", $body)
111107
}
112108
}
113109

114-
class Assistant : AssistantResource {
115-
[System.Management.Automation.HiddenAttribute()]
116-
[string]$urlfragment = "assistants"
117-
118-
[psobject]create([string]$name, [string]$model, [string]$instructions) {
119-
$body = @{
120-
"name" = $name
121-
"model" = $model
122-
"instructions" = $instructions
123-
}
124-
125-
return $this.Client.web("$($this.urlfragment)", "POST", $body)
126-
}
110+
class Assistant:AssistantResource {
111+
Assistant([OpenAIClient]$client): base($client, "assistants") {}
112+
}
113+
class Vector_store:AssistantResource {
114+
Vector_store([OpenAIClient]$client): base($client, "vector_stores") {}
115+
}
116+
class File:AssistantResource {
117+
File([OpenAIClient]$client): base($client, "files") {}
127118
}
119+
class Thread:AssistantResource {
120+
Thread([OpenAIClient]$client): base($client, "threads") {}
121+
}

0 commit comments

Comments
 (0)