Skip to content

Instantly share code, notes, and snippets.

@Agazoth
Last active April 13, 2025 12:48
Show Gist options
  • Save Agazoth/07c3cdaff86aeb563af701a4d82414d5 to your computer and use it in GitHub Desktop.
Save Agazoth/07c3cdaff86aeb563af701a4d82414d5 to your computer and use it in GitHub Desktop.
Tab completion
Register-ArgumentCompleter -CommandName 'Get-Models' -ParameterName 'Model' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParams)
if ($wordToComplete -notmatch ':') {
$completionResults = 'openai', 'google', 'github', 'azureopenai', 'azure', 'azureopenai'
$completionResults | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new("$($_):", $_, 'ParameterValue', "Provider: $_")
}
}
else {
$provider, $partial = $wordToComplete -split ':', 2
switch ($provider.ToLower()) {
'openai' {
$models = "gpt-3.5-turbo", "gpt-4", "gpt-4-32k" # Mock
}
'google' {
$models = @('gemini-1', 'gemini-pro') # Mock
}
'github' {
$models = (Invoke-RestMethod -Uri "https://models.inference.ai.azure.com/models").name
}
'azureopenai' {
# This catches all accounts on the subscription - there might be more then one!
$Accounts = Get-AzCognitiveServicesAccount | Where-Object { $_.AccountType -eq 'OpenAI' }
$models = $Accounts.ForEach{ Get-AzCognitiveServicesAccountDeployment -ResourceId $_.Id }.Name
}
default {
$models = @()
}
}
$models | Where-Object { $_ -like "$partial*" } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new("$($provider):$($_)", "$($provider):$($_)", 'ParameterValue', "Model: $($_)")
}
}
}
function Get-Models {
param(
[string]$Model
)
$Model
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment