Skip to content

Commit 83939ff

Browse files
authored
files路径支持通配符 (#255)
Fixes #254
2 parents 617a074 + 03fea3b commit 83939ff

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

code365scripts.openai/Types/OpenAIClient.ps1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ class File:AssistantResource {
155155

156156
[System.Management.Automation.HiddenAttribute()]
157157
[psobject]upload([string[]]$fullname) {
158+
159+
# process the input, if it is a wildcard or a folder, then get all the files based on this pattern
160+
$fullname = $fullname | Get-ChildItem | Select-Object -ExpandProperty FullName
161+
162+
# confirm if user want to upload those files to openai
163+
$confirm = Read-Host "Are you sure you want to upload the $($fullname.Count) files? (yes/no)"
164+
if ($confirm -ne "yes" -and $confirm -ne "y") {
165+
throw "The user canceled the operation."
166+
}
167+
168+
158169
$url = "{0}{1}" -f $this.client.baseUri, $this.urifragment
159170
if ($this.client.baseUri -match "azure") {
160171
$url = "{0}?api-version=2024-05-01-preview" -f $url
@@ -302,7 +313,7 @@ class Assistant:AssistantResource {
302313
$body.Remove("functions")
303314
$body.Remove("config")
304315

305-
$result = [AssistantObject]::new($this.client.web("$($this.urifragment)", "POST", $body))
316+
$result = [AssistantObject]::new($this.client.web("$($this.urifragment)", "POST", $body))
306317
$result | Add-Member -MemberType NoteProperty -Name client -Value $this.client
307318
return $result
308319
}
@@ -332,7 +343,7 @@ class AssistantObject:AssistantResourceObject {
332343
$this.thread = $this.client.threads.create($this.id)
333344
}
334345

335-
while($true){
346+
while ($true) {
336347
# ask use to input, until the user type 'q' or 'bye'
337348
$prompt = Read-Host ">"
338349
if ($prompt -eq "q" -or $prompt -eq "bye") {
@@ -364,10 +375,10 @@ class ThreadObject:AssistantResourceObject {
364375

365376
[ThreadObject]run([string]$assistantId) {
366377
$obj = [AssistantResource]::new($this.client, ("threads/{0}/runs" -f $this.id), $null ).create(@{assistant_id = $assistantId })
367-
if($null -eq $this.last_run_id){
378+
if ($null -eq $this.last_run_id) {
368379
$this | Add-Member -MemberType NoteProperty -Name last_run_id -Value $obj.id
369380
}
370-
else{
381+
else {
371382
$this.last_run_id = $obj.id
372383
}
373384
return $this

0 commit comments

Comments
 (0)