Skip to content

Commit

Permalink
feat(edit): enable predicted outputs for gpt-4o models (#6116)
Browse files Browse the repository at this point in the history
- Enables [the Predicted Outputs
feature](https://platform.openai.com/docs/guides/predicted-outputs) for
gpt-4o models used with Edit commands.
  • Loading branch information
valerybugakov authored Nov 13, 2024
1 parent 50521a4 commit 8795378
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/shared/src/sourcegraph-api/completions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export interface CompletionParameters {
topP?: number
model?: string
stream?: boolean
// Configuration for a Predicted Output, which can greatly improve response
// times when large parts of the model response are known ahead of time.
// https://platform.openai.com/docs/guides/latency-optimization#use-predicted-outputs
// https://platform.openai.com/docs/api-reference/chat/create#chat-create-prediction
prediction?: {
type: 'content'
content: string
}
}

export interface SerializedCompletionParameters extends Omit<CompletionParameters, 'messages'> {
Expand Down
10 changes: 10 additions & 0 deletions vscode/src/edit/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ export class EditProvider {
stopSequences,
maxTokensToSample: contextWindow.output,
} as CompletionParameters

if (model.includes('gpt-4o')) {
// Use Predicted Output for gpt-4o models.
// https://platform.openai.com/docs/guides/predicted-outputs
params.prediction = {
type: 'content',
content: this.config.task.original,
}
}

// Set stream param only when the model is disabled for streaming.
if (modelsService.isStreamDisabled(model)) {
params.stream = false
Expand Down

0 comments on commit 8795378

Please sign in to comment.