Skip to content

Commit

Permalink
TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Jun 29, 2024
1 parent e539739 commit ef61137
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
14 changes: 0 additions & 14 deletions finetuna.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,4 @@ if ((-not (Get-OpenAIContext).ApiKey) -and (Test-Path -Path $configFile)) {
if ($persisted.AuthType) { $splat.AuthType = $persisted.AuthType }
if ($persisted.Organization) { $splat.Organization = $persisted.Organization }
$null = Set-TuneProvider @splat
}

# get context values to pass to Get-OpenAIAPIParameter
$context = Get-OpenAIContext
if ($context.ApiKey) {
$PSDefaultParameterValues["Get-OpenAIAPIParameter:Parameters"] = @{
ApiKey = $context.ApiKey
AuthType = $context.AuthType
Organization = $context.Organization
ApiBase = $context.ApiBase
ApiVersion = $context.ApiVersion
TimeoutSec = $context.TimeoutSec
MaxRetryCount = $context.MaxRetryCount
}
}
62 changes: 62 additions & 0 deletions private/Get-OpenAIAPIParameter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Get-OpenAIAPIParameter {
param(
[Parameter(Mandatory)]
[string]$EndpointName,

[Parameter()]
[AllowEmptyString()]
[string]$Engine = '',

[Parameter()]
[hashtable]
$Parameters
)
if (-not $Parameters) {
Write-Warning "NO PARAM"
# get context values to pass to Get-OpenAIAPIParameter
$context = Get-OpenAIContext
if ($context.ApiKey) {
$Parameters = @{
ApiKey = $context.ApiKey
AuthType = $context.AuthType
Organization = $context.Organization
ApiBase = $context.ApiBase
ApiVersion = $context.ApiVersion
TimeoutSec = $context.TimeoutSec
MaxRetryCount = $context.MaxRetryCount
}
} else {
throw "No API key found in the context. Please set the API key using Set-TuneProvider."
}
}
# Get common params from session context
$OpenAIParameter = ParseCommonParams $Parameters

# Get params from environment variables
$OpenAIParameter.ApiKey = Initialize-APIKey -ApiKey $OpenAIParameter.ApiKey -ErrorAction Stop
$OpenAIParameter.ApiBase = Initialize-APIBase -ApiBase $OpenAIParameter.ApiBase -ApiType $OpenAIParameter.ApiType -ErrorAction Stop
$OpenAIParameter.Organization = Initialize-OrganizationID -OrgId $OpenAIParameter.Organization

# Get API endpoint and etc.
if ($OpenAIParameter.ApiType -eq [OpenAIApiType]::Azure) {
# When the user wants to use Azure, the AuthType is also set to Azure.
if ($OpenAIParameter.AuthType -notlike 'azure*') {
$OpenAIParameter.AuthType = 'azure'
}
$ApiParam = Get-AzureOpenAIAPIEndpoint -EndpointName $EndpointName -ApiBase $OpenAIParameter.ApiBase -ApiVersion $OpenAIParameter.ApiVersion -Engine $Engine
}
else {
# It looks like the API base URL is Azure even though the API type is OpenAI. In this case, ignore the base URL.
if (([string]([uri]$OpenAIParameter.ApiBase).IdnHost).EndsWith('.azure.com', [System.StringComparison]::OrdinalIgnoreCase)) {
$OpenAIParameter.ApiBase = $null
}
$OpenAIParameter.AuthType = 'openai'
$ApiParam = Get-OpenAIAPIEndpoint -EndpointName $EndpointName -ApiBase $OpenAIParameter.ApiBase
}

foreach ($key in $ApiParam.Keys) {
$OpenAIParameter.$key = $ApiParam.$key
}

$OpenAIParameter
}
2 changes: 0 additions & 2 deletions tests/finetuna.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Describe "finetuna Module Tests" {
$provider = Set-TuneProvider @splat
$provider.ApiKey | Should -Not -BeNullOrEmpty
$provider.ApiType | Should -Be 'openai'
$PSDefaultParameterValues["Get-OpenAIAPIParameter:Parameters"] | Out-String | Write-Warning
$PSDefaultParameterValues["Get-OpenAIAPIParameter:Parameters"] | Should -Not -BeNullOrEmpty
}
}

Expand Down

0 comments on commit ef61137

Please sign in to comment.