-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Filter out unsupported codex tool type #1748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,14 +251,18 @@ export function responseApiInputToRawMessagesForLogging(body: OpenAI.Responses.R | |
| } | ||
| }); | ||
| break; | ||
| case 'function_call_output': | ||
| case 'function_call_output': { | ||
| flushPendingFunctionCalls(); | ||
| messages.push({ | ||
| role: Raw.ChatRole.Tool, | ||
| content: [{ type: Raw.ChatCompletionContentPartKind.Text, text: item.output }], | ||
| toolCallId: item.call_id | ||
| }); | ||
| if (isResponseFunctionCallOutputItem(item)) { | ||
| const content = responseFunctionOutputToRawContents(item.output); | ||
| messages.push({ | ||
| role: Raw.ChatRole.Tool, | ||
| content, | ||
| toolCallId: item.call_id | ||
| }); | ||
| } | ||
| break; | ||
| } | ||
| case 'reasoning': | ||
| // We can't perfectly reconstruct the original thinking data | ||
| // but we can add a placeholder for logging | ||
|
|
@@ -295,6 +299,10 @@ function isResponseInputItemMessage(item: OpenAI.Responses.ResponseInputItem): i | |
| return 'role' in item && item.role === 'assistant' && (!('type' in item) || item.type !== 'message'); | ||
| } | ||
|
|
||
| function isResponseFunctionCallOutputItem(item: OpenAI.Responses.ResponseInputItem): item is OpenAI.Responses.ResponseInputItem.FunctionCallOutput { | ||
| return 'type' in item && item.type === 'function_call_output'; | ||
| } | ||
|
|
||
| function ensureContentArray(content: string | OpenAI.Responses.ResponseInputMessageContentList): OpenAI.Responses.ResponseInputMessageContentList { | ||
| if (typeof content === 'string') { | ||
| return [{ type: 'input_text', text: content }]; | ||
|
|
@@ -329,6 +337,36 @@ function responseOutputToRawContent(part: OpenAI.Responses.ResponseOutputText | | |
| } | ||
| } | ||
|
|
||
| function responseFunctionOutputItemToRawContent(part: OpenAI.Responses.ResponseFunctionCallOutputItem): Raw.ChatCompletionContentPart | undefined { | ||
| if (part.type === 'input_text') { | ||
| return { type: Raw.ChatCompletionContentPartKind.Text, text: part.text }; | ||
| } | ||
| if (part.type === 'input_image') { | ||
| const detail = part.detail && part.detail !== 'auto' ? part.detail : undefined; | ||
| return { | ||
| type: Raw.ChatCompletionContentPartKind.Image, | ||
| imageUrl: { | ||
| url: part.image_url || '', | ||
| detail | ||
| } | ||
| }; | ||
| } | ||
| if (part.type === 'input_file') { | ||
| return { | ||
| type: Raw.ChatCompletionContentPartKind.Opaque, | ||
| value: `[File Output - Filename: ${part.filename || 'unknown'}]` | ||
| }; | ||
| } | ||
| return undefined; | ||
| } | ||
|
Comment on lines
+340
to
+361
|
||
|
|
||
| function responseFunctionOutputToRawContents(output: string | OpenAI.Responses.ResponseFunctionCallOutputItemList): Raw.ChatCompletionContentPart[] { | ||
| if (typeof output === 'string') { | ||
| return [{ type: Raw.ChatCompletionContentPartKind.Text, text: output }]; | ||
| } | ||
| return coalesce(output.map(responseFunctionOutputItemToRawContent)); | ||
| } | ||
|
|
||
| export async function processResponseFromChatEndpoint(instantiationService: IInstantiationService, telemetryService: ITelemetryService, logService: ILogService, response: Response, expectedNumChoices: number, finishCallback: FinishedCallback, telemetryData: TelemetryData): Promise<AsyncIterableObject<ChatCompletion>> { | ||
| const body = (await response.body()) as ClientHttp2Stream; | ||
| return new AsyncIterableObject<ChatCompletion>(async feed => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type guard check on line 256 is redundant. Since we're already inside a
case 'function_call_output':block (line 254), the item type is already narrowed to havetype: 'function_call_output'. The type guardisResponseFunctionCallOutputItemperforms the same check again. Consider removing the conditional wrapper and callingresponseFunctionOutputToRawContentsdirectly.