Public/Files/Remove-OpenAIFile.ps1
function Remove-OpenAIFile { [CmdletBinding()] [OutputType([pscustomobject])] param ( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias('file_id')] [ValidateNotNullOrEmpty()] [string][UrlEncodeTransformation()]$Id, [Parameter()] [int]$TimeoutSec = 0, [Parameter()] [ValidateRange(0, 100)] [int]$MaxRetryCount = 0, [Parameter()] [System.Uri]$ApiBase, [Parameter()] [securestring][SecureStringTransformation()]$ApiKey, [Parameter()] [Alias('OrgId')] [string]$Organization ) begin { # Initialize API Key [securestring]$SecureToken = Initialize-APIKey -ApiKey $ApiKey # Initialize API Base $ApiBase = Initialize-APIBase -ApiBase $ApiBase -ApiType ([OpenAIApiType]::OpenAI) # Initialize Organization ID $Organization = Initialize-OrganizationID -OrgId $Organization # Get API endpoint $OpenAIParameter = Get-OpenAIAPIEndpoint -EndpointName 'Files' -ApiBase $ApiBase } process { $QueryUri = $OpenAIParameter.Uri.ToString() + "/$Id" #region Send API Request $Response = Invoke-OpenAIAPIRequest ` -Method 'Delete' ` -Uri $QueryUri ` -ContentType $OpenAIParameter.ContentType ` -TimeoutSec $TimeoutSec ` -MaxRetryCount $MaxRetryCount ` -ApiKey $SecureToken ` -Organization $Organization # 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 Verbose Output if ($Response.deleted) { Write-Verbose ('The file with id "{0}" has been deleted.' -f $Response.id) } #endregion } end { } } |