Skip to content

Commit f736105

Browse files
committed
Add Request-ResponseCompaction function
1 parent 3f426d5 commit f736105

6 files changed

Lines changed: 918 additions & 0 deletions

File tree

Docs/Request-ResponseCompaction.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
---
2+
external help file: PSOpenAI-help.xml
3+
Module Name: PSOpenAI
4+
online version: https://github.com/mkht/PSOpenAI/blob/main/Docs/Request-ResponseCompaction.md
5+
schema: 2.0.0
6+
---
7+
8+
# Request-ResponseCompaction
9+
10+
## SYNOPSIS
11+
Runs a compaction pass over a conversation. Compaction returns encrypted, opaque items and the underlying logic may evolve over time.
12+
13+
## SYNTAX
14+
15+
```
16+
Request-ResponseCompaction
17+
[[-Message] <String>]
18+
[-Role <String>]
19+
[-Model <String>]
20+
[-SystemMessage <String[]>]
21+
[-DeveloperMessage <String[]>]
22+
[-Instructions <String>]
23+
[-Images <String[]>]
24+
[-ImageDetail <String>]
25+
[-Files <String[]>]
26+
[-PreviousResponseId <String>]
27+
[-OutputRawResponse]
28+
[-Organization <String>]
29+
[-TimeoutSec <Int32>]
30+
[-MaxRetryCount <Int32>]
31+
[-ApiBase <Uri>]
32+
[-ApiKey <SecureString>]
33+
[-History <Object[]>]
34+
[<CommonParameters>]
35+
```
36+
37+
## DESCRIPTION
38+
Runs a compaction pass over a conversation. Compaction returns encrypted, opaque items and the underlying logic may evolve over time.
39+
40+
## EXAMPLES
41+
42+
### Example
43+
```powershell
44+
PS C:\> $Response = Request-Response 'Tell me about traditional Japanese cuisine.' -Model 'gpt-5.1'
45+
PS C:\> $CompactedRespomse = $Response | Request-ResponseCompaction -Model 'gpt-5.1'
46+
```
47+
48+
## PARAMETERS
49+
50+
### -Message
51+
A text input to the model.
52+
53+
```yaml
54+
Type: String
55+
Aliases: UserMessage, input
56+
Required: False
57+
Position: 0
58+
```
59+
60+
### -Role
61+
The role of the message input. One of `user`, `system`, or `developer`. The default is `user`.
62+
63+
```yaml
64+
Type: String
65+
Required: False
66+
Position: Named
67+
```
68+
69+
### -Model
70+
The name of model to use. The default value is `gpt-4o-mini`.
71+
72+
```yaml
73+
Type: String
74+
Required: False
75+
Position: Named
76+
Accept pipeline input: True (ByPropertyName)
77+
Default value: gpt-4o-mini
78+
```
79+
80+
### -SystemMessage
81+
(Instead of this parameter, the use of the `-Instructions` parameter is recommended.)
82+
Instructions that the model should follow.
83+
84+
```yaml
85+
Type: String[]
86+
Required: False
87+
Position: Named
88+
```
89+
90+
### -DeveloperMessage
91+
(Instead of this parameter, the use of the `-Instructions` parameter is recommended.)
92+
Instructions that the model should follow.
93+
94+
```yaml
95+
Type: String[]
96+
Required: False
97+
Position: Named
98+
```
99+
100+
### -Instructions
101+
A system (or developer) message inserted into the model's context.
102+
103+
```yaml
104+
Type: String
105+
Required: False
106+
Position: Named
107+
```
108+
109+
### -PreviousResponseId
110+
The unique ID of the previous response to the model. Use this to create multi-turn conversations.
111+
112+
```yaml
113+
Type: String
114+
Aliases: previous_response_id
115+
Required: False
116+
Position: Named
117+
Accept pipeline input: True (ByPropertyName)
118+
```
119+
120+
### -Images
121+
A list of images to passing the model. You can specify local image file or remote url.
122+
123+
```yaml
124+
Type: String[]
125+
Required: False
126+
Position: Named
127+
```
128+
129+
### -ImageDetail
130+
Controls how the model processes the image and generates its textual understanding. You can select from `Low` or `High`.
131+
132+
```yaml
133+
Type: String
134+
Accepted values: auto, low, high
135+
Required: False
136+
Position: Named
137+
Default value: auto
138+
```
139+
140+
### -Files
141+
A file input to the model.
142+
You can speciy a list of the local file path, the URL of the file or the ID of the file to be uploaded.
143+
144+
```yaml
145+
Type: String[]
146+
Required: False
147+
Position: Named
148+
```
149+
150+
### -OutputRawResponse
151+
If specifies this switch, an output of this function to be a raw response value from the API. (Normally JSON formatted string.)
152+
153+
```yaml
154+
Type: SwitchParameter
155+
Required: False
156+
Position: Named
157+
```
158+
159+
### -TimeoutSec
160+
Specifies how long the request can be pending before it times out.
161+
The default value is `0` (infinite).
162+
163+
```yaml
164+
Type: Int32
165+
Required: False
166+
Position: Named
167+
Default value: 0
168+
```
169+
170+
### -MaxRetryCount
171+
Number between `0` and `100`.
172+
Specifies the maximum number of retries if the request fails.
173+
The default value is `0` (No retry).
174+
Note : Retries will only be performed if the request fails with a `429 (Rate limit reached)` or `5xx (Server side errors)` error. Other errors (e.g., authentication failure) will not be performed.
175+
176+
```yaml
177+
Type: Int32
178+
Required: False
179+
Position: Named
180+
Default value: 0
181+
```
182+
183+
### -ApiBase
184+
Specifies an API endpoint URL such like: `https://your-api-endpoint.test/v1`
185+
If not specified, it will use `https://api.openai.com/v1`
186+
187+
```yaml
188+
Type: System.Uri
189+
Required: False
190+
Position: Named
191+
Default value: https://api.openai.com/v1
192+
```
193+
194+
### -ApiKey
195+
Specifies API key for authentication.
196+
The type of data should `[string]` or `[securestring]`.
197+
If not specified, it will try to use `$global:OPENAI_API_KEY` or `$env:OPENAI_API_KEY`
198+
199+
```yaml
200+
Type: Object
201+
Required: False
202+
Position: Named
203+
```
204+
205+
### -History
206+
An object for keeping the conversation history.
207+
208+
```yaml
209+
Type: Object[]
210+
Required: False
211+
Position: Named
212+
Accept pipeline input: True (ByPropertyName)
213+
```
214+
215+
## INPUTS
216+
217+
## OUTPUTS
218+
219+
## NOTES
220+
221+
## RELATED LINKS
222+
223+
## RELATED LINKS
224+
225+
https://platform.openai.com/docs/api-reference/responses/compact

PSOpenAI.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
'Get-Response',
102102
'Get-ResponseInputItem',
103103
'Remove-Response',
104+
'Request-ResponseCompaction',
104105
#### Conversations ####
105106
'New-Conversation',
106107
'Set-Conversation',

Private/Get-OpenAIAPIEndpoint.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ function Get-OpenAIAPIEndpoint {
279279
}
280280
continue
281281
}
282+
'Responses.Compact' {
283+
$UriBuilder.Path += 'responses/compact'
284+
@{
285+
Name = 'responses_compact'
286+
Method = 'Post'
287+
Uri = $UriBuilder.Uri
288+
ContentType = 'application/json'
289+
}
290+
continue
291+
}
282292
'Conversations' {
283293
$UriBuilder.Path += 'conversations'
284294
@{

Private/ObjectParser.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,44 @@ function ParseResponseObject {
410410
Write-Output $InputObject
411411
}
412412

413+
function ParseResponseCompactionObject {
414+
[CmdletBinding()]
415+
param (
416+
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
417+
[PSCustomObject]$InputObject,
418+
419+
[Parameter()]
420+
[System.Collections.Generic.List[object]]$Messages,
421+
422+
[Parameter()]
423+
[System.Collections.IDictionary]$CommonParams = @{}
424+
)
425+
426+
# Add custom type name and properties to output object.
427+
$InputObject.PSObject.TypeNames.Insert(0, 'PSOpenAI.Response.Compaction')
428+
429+
# Date and times
430+
@('created_at') | ForEach-Object {
431+
if ($null -ne $InputObject.$_ -and ($unixtime = $InputObject.$_ -as [long])) {
432+
# convert unixtime to [DateTime] for read suitable
433+
$InputObject | Add-Member -MemberType NoteProperty -Name $_ -Value ([System.DateTimeOffset]::FromUnixTimeSeconds($unixtime).LocalDateTime) -Force
434+
}
435+
}
436+
437+
# Add History
438+
if ($Messages.Count -gt 0) {
439+
$Messages | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'PSOpenAI.Response.Message') }
440+
$InputObject | Add-Member -MemberType NoteProperty -Name 'History' -Value $Messages.ToArray()
441+
}
442+
else {
443+
$InputObject | Add-Member -MemberType NoteProperty -Name 'History' -Value @()
444+
}
445+
446+
# Return
447+
Write-Output $InputObject
448+
}
449+
450+
413451

414452
function ParseVectorStoreObject {
415453
[CmdletBinding()]

0 commit comments

Comments
 (0)