Skip to content

Commit 520c45c

Browse files
Update src/services/apis/openai-api.mjs
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent 712eb8e commit 520c45c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/services/apis/openai-api.mjs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,24 @@ export async function generateAnswersWithChatgptApiCompat(
202202
console.debug('No choice in response data for reasoning model')
203203
return
204204
}
205-
const content = choice.message?.content ?? choice.text
205+
let content = choice.message?.content ?? choice.text
206+
if (Array.isArray(content)) {
207+
// Prefer output_text segments; fallback to any string content
208+
const parts = content
209+
.map((p) => {
210+
if (typeof p === 'string') return p
211+
if (p && typeof p === 'object') {
212+
if (typeof p.output_text === 'string') return p.output_text
213+
if (typeof p.text === 'string') return p.text
214+
}
215+
return ''
216+
})
217+
.filter(Boolean)
218+
content = parts.join('')
219+
}
206220
if (content !== undefined && content !== null) {
207-
answer = content
221+
answer = String(content)
222+
}
208223
port.postMessage({ answer, done: false, session: null })
209224
}
210225
if (choice.finish_reason || content !== undefined) {

0 commit comments

Comments
 (0)