Public/VectorStores/Batches/Get-VectorStoreFileBatch.ps1
function Get-VectorStoreFileBatch { [CmdletBinding()] [OutputType([pscustomobject])] param ( [Parameter(ParameterSetName = 'VectorStore', Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [Alias('InputObject')] # for backword compatibility [PSTypeName('PSOpenAI.VectorStore')]$VectorStore, [Parameter(ParameterSetName = 'VectorStoreId', Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('vector_store_id')] [string][UrlEncodeTransformation()]$VectorStoreId, [Parameter(ParameterSetName = 'VectorStore', Mandatory, Position = 1, ValueFromPipelineByPropertyName)] [Parameter(ParameterSetName = 'VectorStoreId', Mandatory, Position = 1, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('batch_id')] [string][UrlEncodeTransformation()]$BatchId, [Parameter(ParameterSetName = 'VectorStoreFileBatch', Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [PSTypeName('PSOpenAI.VectorStore.FileBatch')]$Batch, [Parameter()] [int]$TimeoutSec = 0, [Parameter()] [ValidateRange(0, 100)] [int]$MaxRetryCount = 0, [Parameter()] [OpenAIApiType]$ApiType = [OpenAIApiType]::OpenAI, [Parameter()] [System.Uri]$ApiBase, [Parameter(DontShow)] [string]$ApiVersion, [Parameter()] [ValidateSet('openai', 'azure', 'azure_ad')] [string]$AuthType = 'openai', [Parameter()] [securestring][SecureStringTransformation()]$ApiKey, [Parameter()] [Alias('OrgId')] [string]$Organization, [Parameter()] [System.Collections.IDictionary]$AdditionalQuery, [Parameter()] [System.Collections.IDictionary]$AdditionalHeaders, [Parameter()] [object]$AdditionalBody ) begin { # Get API context $OpenAIParameter = Get-OpenAIAPIParameter -EndpointName 'VectorStore.FileBatches' -Parameters $PSBoundParameters -ErrorAction Stop } process { # Get ids if ($PSCmdlet.ParameterSetName -ceq 'VectorStore') { $VectorStoreId = $VectorStore.id } elseif ($PSCmdlet.ParameterSetName -ceq 'VectorStoreFileBatch') { $VectorStoreId = $Batch.vector_store_id $BatchId = $Batch.id } if (-not $VectorStoreId) { Write-Error -Exception ([System.ArgumentException]::new('Could not retrieve vector store id.')) return } if (-not $BatchId) { Write-Error -Exception ([System.ArgumentException]::new('Could not retrieve batch id.')) return } #region Construct Query URI $QueryUri = $OpenAIParameter.Uri.ToString() -f $VectorStoreId $UriBuilder = [System.UriBuilder]::new($QueryUri) $UriBuilder.Path += "/$BatchId" $QueryUri = $UriBuilder.Uri #endregion #region Send API Request $params = @{ Method = 'Get' Uri = $QueryUri ContentType = $OpenAIParameter.ContentType TimeoutSec = $OpenAIParameter.TimeoutSec MaxRetryCount = $OpenAIParameter.MaxRetryCount ApiKey = $OpenAIParameter.ApiKey AuthType = $OpenAIParameter.AuthType Headers = @{'OpenAI-Beta' = 'assistants=v2' } Organization = $OpenAIParameter.Organization AdditionalQuery = $AdditionalQuery AdditionalHeaders = $AdditionalHeaders AdditionalBody = $AdditionalBody } $Response = Invoke-OpenAIAPIRequest @params # error check if ($null -eq $Response) { return } #endregion #region Parse response object try { $Response = $Response | ConvertFrom-Json -ErrorAction Stop } catch { Write-Error -Exception $_.Exception } #endregion #region Output # parse objects ParseVectorStoreFileBatchObject $Response #endregion } end {} } |