Skip to content

Commit 3a3b462

Browse files
committed
Add new built-in tools
- Code Interpreter - Image Generation - Local Shell
1 parent 7525816 commit 3a3b462

2 files changed

Lines changed: 185 additions & 4 deletions

File tree

Public/Responses/Request-Response.ps1

Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,69 @@ function Request-Response {
182182
[Parameter()]
183183
[System.Collections.IDictionary]$MCPOptionalHeaders,
184184
#endregion Remote MCP
185+
186+
#region Code Interpreter
187+
[Parameter()]
188+
[switch]$UseCodeInterpreter,
189+
190+
[Parameter(DontShow)]
191+
[string]$CodeInterpreterType = 'code_interpreter', # Always 'code_interpreter'
192+
193+
[Parameter()]
194+
[string]$ContainerId = 'auto',
195+
196+
[Parameter()]
197+
[string[]]$ContainerFileIds,
198+
#endregion Code Interpreter
199+
200+
#region Image Generation
201+
[Parameter()]
202+
[switch]$UseImageGeneration,
203+
204+
[Parameter(DontShow)]
205+
[string]$ImageGenerationType = 'image_generation', # Always 'image_generation'
206+
207+
[Parameter()]
208+
[Completions('gpt-image-1')]
209+
[string]$ImageGenerationModel,
210+
211+
[Parameter()]
212+
[Completions('transparent', 'opaque', 'auto')]
213+
[string]$ImageGenerationBackGround = 'auto',
214+
215+
[Parameter()]
216+
[string]$ImageGenerationInputImageMask,
217+
218+
[Parameter()]
219+
[string]$ImageGenerationModeration = 'auto',
220+
221+
[Parameter()]
222+
[ValidateRange(0, 100)]
223+
[int]$ImageGenerationOutputCompression,
224+
225+
[Parameter()]
226+
[ValidateSet('png', 'jpeg', 'webp')]
227+
[string][LowerCaseTransformation()]$ImageGenerationOutputFormat = 'png',
228+
229+
[Parameter()]
230+
[ValidateRange(0, 3)]
231+
[int]$ImageGenerationPartialImages,
232+
233+
[Parameter()]
234+
[ValidateSet('low', 'medium', 'high', 'auto')]
235+
[string][LowerCaseTransformation()]$ImageGenerationQuality = 'auto',
236+
237+
[Parameter()]
238+
[ValidateSet('auto', '1024x1024', '1536x1024', '1024x1536')]
239+
[string]$ImageGenerationSize = 'auto',
240+
#endregion Image Generation
241+
242+
#region Local shell
243+
[Parameter()]
244+
[switch]$UseLocalShell,
245+
246+
[Parameter(DontShow)]
247+
[string]$LocalShellType = 'local_shell', # Always 'local_shell'
185248
#endregion Tools
186249

187250
[Parameter()]
@@ -449,7 +512,7 @@ function Request-Response {
449512
$Tools += $Functions
450513
}
451514

452-
# File Search
515+
#region File Search
453516
if ($UseFileSearch) {
454517
if ($FileSearchVectorStoreIds.Count -eq 0) {
455518
Write-Error 'VectorStore Ids must be specified.'
@@ -481,7 +544,7 @@ function Request-Response {
481544
}
482545
}
483546

484-
# Web Search
547+
#region Web Search
485548
if ($UseWebSearch) {
486549
$UserLocation = @{}
487550
$WebSearchTool = @{
@@ -512,7 +575,7 @@ function Request-Response {
512575
$Tools += $WebSearchTool
513576
}
514577

515-
# Computer Use
578+
#region Computer Use
516579
if ($UseComputerUse) {
517580
# Computer Use should be used with 'truncation=auto'
518581
$PostBody.truncation = 'auto'
@@ -541,7 +604,7 @@ function Request-Response {
541604
$Tools += $ComputerUseTool
542605
}
543606

544-
# Remote MCP
607+
#region Remote MCP
545608
if ($UseMCP) {
546609
# Server label and URL are required.
547610
if ([string]::IsNullOrWhiteSpace($MCPServerLabel)) {
@@ -587,6 +650,74 @@ function Request-Response {
587650
$Tools += $MCPTool
588651
}
589652

653+
#region Code Interpreter
654+
if ($UseCodeInterpreter) {
655+
$CodeInterpreterTool = @{
656+
type = $CodeInterpreterType
657+
container = $ContainerId
658+
}
659+
if ($ContainerId -eq 'auto') {
660+
# Auto container
661+
$CodeInterpreterTool.container = @{type = 'auto' }
662+
if ($PSBoundParameters.ContainsKey('ContainerFileIds')) {
663+
$CodeInterpreterTool.container.file_ids = $ContainerFileIds
664+
}
665+
}
666+
$Tools += $CodeInterpreterTool
667+
}
668+
669+
#region Image Generation
670+
if ($UseImageGeneration) {
671+
$ImageGenerationTool = @{
672+
type = $ImageGenerationType
673+
}
674+
if ($PSBoundParameters.ContainsKey('ImageGenerationModel')) {
675+
$ImageGenerationTool.model = $ImageGenerationModel
676+
}
677+
if ($PSBoundParameters.ContainsKey('ImageGenerationBackGround')) {
678+
$ImageGenerationTool.background = $ImageGenerationBackGround
679+
}
680+
if ($PSBoundParameters.ContainsKey('ImageGenerationInputImageMask')) {
681+
if (Test-Path -LiteralPath $ImageGenerationInputImageMask -PathType Leaf) {
682+
# local file
683+
$image_url = Convert-ImageToDataURL $ImageGenerationInputImageMask
684+
$ImageGenerationTool.input_image_mask = @{image_url = $image_url }
685+
}
686+
else {
687+
# File id
688+
$ImageGenerationTool.input_image_mask = @{file_id = $ImageGenerationInputImageMask }
689+
}
690+
}
691+
if ($PSBoundParameters.ContainsKey('ImageGenerationModeration')) {
692+
$ImageGenerationTool.moderation = $ImageGenerationModeration
693+
}
694+
if ($PSBoundParameters.ContainsKey('ImageGenerationOutputCompression')) {
695+
$ImageGenerationTool.output_compression = $ImageGenerationOutputCompression
696+
}
697+
if ($PSBoundParameters.ContainsKey('ImageGenerationOutputFormat')) {
698+
$ImageGenerationTool.output_format = $ImageGenerationOutputFormat
699+
}
700+
if ($PSBoundParameters.ContainsKey('ImageGenerationPartialImages')) {
701+
$ImageGenerationTool.partial_images = $ImageGenerationPartialImages
702+
}
703+
if ($PSBoundParameters.ContainsKey('ImageGenerationQuality')) {
704+
$ImageGenerationTool.quality = $ImageGenerationQuality
705+
}
706+
if ($PSBoundParameters.ContainsKey('ImageGenerationSize')) {
707+
$ImageGenerationTool.size = $ImageGenerationSize
708+
}
709+
710+
$Tools += $ImageGenerationTool
711+
}
712+
713+
#region Local Shell
714+
if ($UseLocalShell) {
715+
$LocalShellTool = @{
716+
type = $LocalShellType
717+
}
718+
$Tools += $LocalShellTool
719+
}
720+
590721
if ($Tools.Count -gt 0) {
591722
$PostBody.tools = $Tools
592723
}

Tests/Responses/Request-Response.tests.ps1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,56 @@ Ping Source Address Latency(ms) BufferSize(B) Status
845845
$Result.LastUserMessage | Should -Be 'Check the latest OpenAI news on Google.'
846846
$Result.output[-1].type | Should -Be 'mcp_approval_request'
847847
}
848+
849+
It 'Tools - Code Interpreter' {
850+
{
851+
$param = @{
852+
Message = "How Many R's in 'Strawberry'? Solve it use with Python tools."
853+
Model = 'gpt-4.1-mini'
854+
UseCodeInterpreter = $true
855+
ToolChoice = 'required'
856+
Store = $false
857+
TimeoutSec = 30
858+
}
859+
860+
$script:Result = Request-Response @param -ea Stop } | Should -Not -Throw
861+
$Result.object | Should -Be 'response'
862+
$Result.output.type | Should -Contain 'code_interpreter_call'
863+
}
864+
865+
It 'Tools - Image Generation' {
866+
{
867+
$param = @{
868+
Message = 'Create an illustration of a young man wearing a brown bucket hat, holding a cola in his left hand and chicken in his right hand.'
869+
Model = 'gpt-4.1-mini'
870+
UseImageGeneration = $true
871+
ImageGenerationOutputFormat = 'jpeg'
872+
ImageGenerationQuality = 'low'
873+
ImageGenerationSize = '1024x1024'
874+
ImageGenerationOutputCompression = 80
875+
Store = $false
876+
TimeoutSec = 150
877+
}
878+
879+
$script:Result = Request-Response @param -ea Stop } | Should -Not -Throw
880+
$Result.object | Should -Be 'response'
881+
$Result.output.type | Should -Contain 'image_generation_call'
882+
}
883+
884+
It 'Tools - Local Shell' {
885+
{
886+
$param = @{
887+
Message = 'List all files that the size is larger than 100MB in /var/logs'
888+
Model = 'codex-mini-latest'
889+
UseLocalShell = $true
890+
Store = $false
891+
TimeoutSec = 30
892+
}
893+
894+
$script:Result = Request-Response @param -ea Stop } | Should -Not -Throw
895+
$Result.object | Should -Be 'response'
896+
$Result.output.type | Should -Contain 'local_shell_call'
897+
}
848898
}
849899

850900
Context 'Integration tests (Azure OpenAI)' -Tag 'Azure' {

0 commit comments

Comments
 (0)