Guest User

ChatGpt Hide Models

a guest
Nov 18th, 2026
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. @echo off
  2. setlocal DisableDelayedExpansion
  3. set "pickerShell=%ProgramFiles%\PowerShell\7\pwsh.exe"
  4. if not exist "%pickerShell%" set "pickerShell=%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\native\powershell\pwsh.exe"
  5. if not exist "%pickerShell%" (
  6. where /q pwsh.exe
  7. if errorlevel 1 (
  8. echo PowerShell 7.2 or later is required to open Model Picker Settings.
  9. pause
  10. exit /b 1
  11. )
  12. set "pickerShell=pwsh.exe"
  13. )
  14.  
  15. set "pickerBatch=%~f0"
  16. "%pickerShell%" -NoProfile -STA -Command "$ErrorActionPreference = 'Stop'; $parts = [regex]::Split([IO.File]::ReadAllText($env:pickerBatch), '(?m)^::POWERSHELL_SCRIPT\r?\n'); if ($parts.Count -ne 2) { throw 'The batch file is incomplete. Copy the full code and try again.' }; $script = Join-Path ([IO.Path]::GetTempPath()) ('model-picker-' + [guid]::NewGuid() + '.ps1'); try { [IO.File]::WriteAllText($script, $parts[1]); & $script } finally { [IO.File]::Delete($script) }"
  17. if errorlevel 1 (
  18. pause
  19. exit /b 1
  20. )
  21. exit /b 0
  22.  
  23. ::POWERSHELL_SCRIPT
  24. #requires -Version 7.2
  25. $ErrorActionPreference = 'Stop'
  26. $settingsDir = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $env:USERPROFILE '.codex' }
  27. $cacheFile = Join-Path $settingsDir 'models_cache.codex_work_desktop.json'
  28. $configFile = Join-Path $settingsDir 'config.toml'
  29. $catalogFile = Join-Path $settingsDir 'model-picker-settings.catalog.json'
  30. $catalogLine = 'model_catalog_json = "' + $catalogFile.Replace('\', '/') + '"'
  31.  
  32. function Write-AtomicText($path, $value) {
  33. $temp = "$path.$([guid]::NewGuid()).tmp"
  34. try {
  35. [IO.File]::WriteAllText($temp, $value)
  36. [IO.File]::Move($temp, $path, $true)
  37. } finally {
  38. if ([IO.File]::Exists($temp)) { [IO.File]::Delete($temp) }
  39. }
  40. }
  41.  
  42. function Save-ModelSelection([string[]]$hiddenModels) {
  43. $config = if ([IO.File]::Exists($configFile)) { [IO.File]::ReadAllText($configFile) } else { '' }
  44. $root = ($config -split '(?m)^\s*\[', 2)[0]
  45. $entry = [regex]::Match($root, '(?m)^[ \t]*model_catalog_json[ \t]*=[^\r\n]*')
  46. if ($entry.Success -and $entry.Value -cne $catalogLine) {
  47. throw 'A different custom model catalog is configured. Your configuration has been preserved.'
  48. }
  49. if (-not $hiddenModels.Count) {
  50. if ($entry.Success) {
  51. $tail = $config.Substring($entry.Index + $entry.Length) -replace '^\r?\n', ''
  52. Write-AtomicText $configFile ($config.Substring(0, $entry.Index) + $tail)
  53. }
  54. return
  55. }
  56. $models = (Get-Content -LiteralPath $cacheFile -Raw | ConvertFrom-Json -Depth 100 -AsHashtable).models
  57. if (-not @($models | Where-Object { $_.visibility -eq 'list' -and $_.slug -notin $hiddenModels }).Count) {
  58. throw 'Keep at least one model visible.'
  59. }
  60. foreach ($model in $models) {
  61. if ($model.slug -in $hiddenModels) { $model.visibility = 'hide' }
  62. }
  63. Write-AtomicText $catalogFile (ConvertTo-Json -InputObject @{models=$models} -Depth 100 -Compress)
  64. if (-not $entry.Success) { Write-AtomicText $configFile ($catalogLine + "`r`n" + $config) }
  65. }
  66.  
  67. if ($MyInvocation.InvocationName -eq '.') { return }
  68. Add-Type -AssemblyName System.Windows.Forms
  69. Add-Type -AssemblyName System.Drawing
  70. [Windows.Forms.Application]::EnableVisualStyles()
  71. try {
  72. $choices = @((Get-Content -LiteralPath $cacheFile -Raw | ConvertFrom-Json -AsHashtable).models | Where-Object visibility -eq 'list')
  73. if (-not $choices.Count) { throw 'The desktop model cache has no visible models.' }
  74. $hidden = @()
  75. if ((Test-Path -LiteralPath $configFile) -and ((Get-Content -LiteralPath $configFile) -ccontains $catalogLine)) {
  76. $hidden = @((Get-Content -LiteralPath $catalogFile -Raw | ConvertFrom-Json -AsHashtable).models | Where-Object visibility -eq 'hide' | ForEach-Object slug)
  77. }
  78. $form = [Windows.Forms.Form]::new()
  79. $form.Text = 'Model Picker Settings'
  80. $form.Font = [Drawing.Font]::new('Segoe UI', 10)
  81. $form.AutoScaleMode = 'Dpi'
  82. $form.ClientSize = [Drawing.Size]::new(410, 365)
  83. $form.FormBorderStyle = 'FixedDialog'
  84. $form.MaximizeBox = $false
  85. $form.StartPosition = 'CenterScreen'
  86. $label = [Windows.Forms.Label]::new()
  87. $label.Text = 'Show these models in the picker'
  88. $label.SetBounds(16, 16, 378, 24)
  89. $list = [Windows.Forms.CheckedListBox]::new()
  90. $list.SetBounds(16, 46, 378, 240)
  91. $list.CheckOnClick = $true
  92. foreach ($model in $choices) { [void]$list.Items.Add($model.display_name, ($model.slug -notin $hidden)) }
  93. $hint = [Windows.Forms.Label]::new()
  94. $hint.Text = 'Restart the desktop app after saving.'
  95. $hint.SetBounds(16, 285, 378, 24)
  96. $defaults = [Windows.Forms.Button]::new()
  97. $defaults.Text = 'Show all'
  98. $defaults.SetBounds(16, 320, 100, 30)
  99. $defaults.Add_Click({ for ($i = 0; $i -lt $list.Items.Count; $i++) { $list.SetItemChecked($i, $true) } })
  100. $save = [Windows.Forms.Button]::new()
  101. $save.Text = 'Save'
  102. $save.SetBounds(300, 320, 94, 30)
  103. $save.Add_Click({
  104. try {
  105. $off = for ($i = 0; $i -lt $choices.Count; $i++) { if (-not $list.GetItemChecked($i)) { $choices[$i].slug } }
  106. Save-ModelSelection $off
  107. $form.Close()
  108. } catch { [void][Windows.Forms.MessageBox]::Show($form, $_.Exception.Message, 'Model Picker Settings') }
  109. })
  110. $form.Controls.AddRange(@($label, $list, $hint, $defaults, $save))
  111. $form.AcceptButton = $save
  112. [void]$form.ShowDialog()
  113. $form.Dispose()
  114. } catch { [void][Windows.Forms.MessageBox]::Show($_.Exception.Message, 'Model Picker Settings') }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment