From 7b6c42f80576bca2d57ebbab945d9cd1c2c26dc4 Mon Sep 17 00:00:00 2001 From: Jon Klozik Date: Fri, 11 Jul 2025 13:20:26 -0400 Subject: [PATCH 1/6] Added optional OpenAI-Organization header to AzOAI --- Private/Invoke-OAIBeta.ps1 | 6 ++++++ Public/Set-AzOAISecrets.ps1 | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Private/Invoke-OAIBeta.ps1 b/Private/Invoke-OAIBeta.ps1 index 4ca2e76..04343e4 100644 --- a/Private/Invoke-OAIBeta.ps1 +++ b/Private/Invoke-OAIBeta.ps1 @@ -58,6 +58,12 @@ function Invoke-OAIBeta { 'AzureOpenAI' { $headers['api-key'] = "$($AzOAISecrets.apiKEY)" + if($AzOAISecrets.organizationId) { + $headers['OpenAI-Organization'] = "$($AzOAISecrets.organizationId)" + } + else { + $headers.Remove('OpenAI-Organization') + } if ($Body -isnot [System.IO.Stream]) { if ($null -ne $Body -and $Body.Contains("model") ) { diff --git a/Public/Set-AzOAISecrets.ps1 b/Public/Set-AzOAISecrets.ps1 index fd85ef9..64e678b 100644 --- a/Public/Set-AzOAISecrets.ps1 +++ b/Public/Set-AzOAISecrets.ps1 @@ -12,15 +12,20 @@ The URI of the Azure OAI. The API key for accessing the Azure OAI. .PARAMETER apiVersion -The version of the Azure OAI. +The version of the Azure OAI in YYYY-MM-DD format. .PARAMETER deploymentName -The name of the deployment. +The name of the AI model deployment. + +.PARAMETER organizationId +The organization ID associated with the Azure OAI. This parameter is optional. .EXAMPLE -Set-AzOAISecrets -apiURI "https://api.example.com" -apiKEY "myApiKey" -apiVersion "v1" -deploymentName "MyDeployment" +Set-AzOAISecrets -apiURI "https://api.example.com" -apiKEY "myApiKey" -apiVersion "2024-10-21" -deploymentName "MyDeployment" Sets the Azure OAI secrets with the specified values. +.NOTES +See https://learn.microsoft.com/en-us/azure/ai-foundry/openai/reference for more information on Azure OpenAI API version #> function Set-AzOAISecrets { @@ -33,11 +38,14 @@ function Set-AzOAISecrets { [Parameter(Mandatory)] $apiVersion, [Parameter(Mandatory)] - $deploymentName + $deploymentName, + [Parameter(Mandatory=$false)] + $organizationId = $null ) $script:AzOAISecrets['apiURI'] = $apiURI $script:AzOAISecrets['apiKEY'] = $apiKEY $script:AzOAISecrets['apiVersion'] = $apiVersion $script:AzOAISecrets['deploymentName'] = $deploymentName + $script:AzOAISecrets['organizationId'] = $organizationId } \ No newline at end of file From 02f5bbc56d413e91800e4b9d51f26d67a524d753 Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 11 Jul 2025 14:42:23 -0400 Subject: [PATCH 2/6] Format organizationId parameter attributes for consistency --- Public/Set-AzOAISecrets.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Public/Set-AzOAISecrets.ps1 b/Public/Set-AzOAISecrets.ps1 index 64e678b..7769105 100644 --- a/Public/Set-AzOAISecrets.ps1 +++ b/Public/Set-AzOAISecrets.ps1 @@ -39,7 +39,8 @@ function Set-AzOAISecrets { $apiVersion, [Parameter(Mandatory)] $deploymentName, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] + [ValidateNotNullOrEmpty()] $organizationId = $null ) From 976694e55deae107f6bbfcd2f6a63d1c0a5ae2de Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 11 Jul 2025 14:42:34 -0400 Subject: [PATCH 3/6] Improve organizationId check for OpenAI-Organization header in Invoke-OAIBeta function --- Private/Invoke-OAIBeta.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Private/Invoke-OAIBeta.ps1 b/Private/Invoke-OAIBeta.ps1 index 04343e4..d4ba4ec 100644 --- a/Private/Invoke-OAIBeta.ps1 +++ b/Private/Invoke-OAIBeta.ps1 @@ -58,7 +58,7 @@ function Invoke-OAIBeta { 'AzureOpenAI' { $headers['api-key'] = "$($AzOAISecrets.apiKEY)" - if($AzOAISecrets.organizationId) { + if (-not [string]::IsNullOrEmpty($AzOAISecrets.organizationId)) { $headers['OpenAI-Organization'] = "$($AzOAISecrets.organizationId)" } else { From 229bb50df046d0d4c90d5456b094927ae7436fd7 Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 11 Jul 2025 14:42:49 -0400 Subject: [PATCH 4/6] Bump module version to 0.5.0 and update copyright year to 2025 --- PSAI.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSAI.psd1 b/PSAI.psd1 index 6e6e355..0a3ace0 100644 --- a/PSAI.psd1 +++ b/PSAI.psd1 @@ -1,10 +1,10 @@ @{ RootModule = 'PSAI.psm1' - ModuleVersion = '0.4.11' + ModuleVersion = '0.5.0' GUID = '68662d19-a8f1-484f-b1b7-3bf0e8a436df' Author = 'Douglas Finke' CompanyName = 'Doug Finke' - Copyright = '© 2024 All rights reserved.' + Copyright = '© 2025 All rights reserved.' Description = @' PSAI brings OpenAI ChatGPT to PowerShell, leveraging advanced AI capabilities in your PowerShell scripts for dynamic, intelligent automation and data processing From 2f2ebbe510a2e3a75dbb4d697f0626723489ba46 Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 11 Jul 2025 14:42:55 -0400 Subject: [PATCH 5/6] Update README to include optional organizationId for Azure OpenAI resource --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab5d36d..1237a80 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,13 @@ Then set `$env:OpenAIKey` to your key. After creating an [Azure OpenAI resource](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal), you can use the `PSAI` module to interact with it. -You need to get the following secrets form the Azure Portal and Azure AI Studio - `apiURI`,`apiVersion`,`apiKey`,`deploymentName`. + +You need to get the following secrets from the Azure Portal and Azure AI Studio: +- `apiURI` +- `apiVersion` +- `apiKey` +- `deploymentName` +- *(Optional)* `organizationId` (if your Azure OpenAI resource requires the `OpenAI-Organization` header) ```powershell $secrets = @{ @@ -67,12 +73,15 @@ $secrets = @{ apiKey = "" apiVersion = "" deploymentName = "" + organizationId = "" # Optional } Set-OAIProvider AzureOpenAI Set-AzOAISecrets @secrets ``` +If your Azure OpenAI implementation requires the `OpenAI-Organization` header, provide the `organizationId` value. Otherwise, you can omit it. + ## Usage The full set of functions can be found here https://github.com/dfinke/PSAI/wiki/ From 3f513707df7822307776293b25b5a601ec456241 Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 11 Jul 2025 14:46:22 -0400 Subject: [PATCH 6/6] Add changelog entries for v0.4.12: include organizationId support in Set-AzOAISecrets --- changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index 4831fd0..4e786f0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +## v0.4.12 + +Thank you to https://github.com/jmkloz for the PR! + +- Added optional `organizationId` parameter to `Set-AzOAISecrets` for Azure OpenAI support +- `Invoke-OAIBeta` now sets the `OpenAI-Organization` header when `organizationId` is provided ## v0.4.11