Skip to content

Commit e0b4f1a

Browse files
committed
fix: implement completePrompt using Responses API non-streaming mode
Instead of throwing an error, completePrompt now properly uses the Responses API with stream: false to generate completions for all OpenAI Native models.
1 parent 2022e28 commit e0b4f1a

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

src/api/providers/openai-native.ts

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,80 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
11651165
}
11661166

11671167
async completePrompt(prompt: string): Promise<string> {
1168-
// ALL models now use the Responses API which doesn't support non-streaming completion
1169-
throw new Error(`completePrompt is not supported. Use createMessage (Responses API) instead.`)
1168+
try {
1169+
const model = this.getModel()
1170+
const { verbosity, reasoning } = model
1171+
1172+
// Resolve reasoning effort for models that support it
1173+
const reasoningEffort = this.getReasoningEffort(model)
1174+
1175+
// Build request body for Responses API
1176+
const requestBody: any = {
1177+
model: model.id,
1178+
input: [
1179+
{
1180+
role: "user",
1181+
content: [{ type: "input_text", text: prompt }],
1182+
},
1183+
],
1184+
stream: false, // Non-streaming for completePrompt
1185+
store: false, // Don't store prompt completions
1186+
}
1187+
1188+
// Add reasoning if supported
1189+
if (reasoningEffort) {
1190+
requestBody.reasoning = {
1191+
effort: reasoningEffort,
1192+
...(this.options.enableGpt5ReasoningSummary ? { summary: "auto" as const } : {}),
1193+
}
1194+
}
1195+
1196+
// Only include temperature if the model supports it
1197+
if (model.info.supportsTemperature !== false) {
1198+
requestBody.temperature =
1199+
this.options.modelTemperature ??
1200+
(model.id.startsWith(GPT5_MODEL_PREFIX)
1201+
? GPT5_DEFAULT_TEMPERATURE
1202+
: OPENAI_NATIVE_DEFAULT_TEMPERATURE)
1203+
}
1204+
1205+
// Include max_output_tokens if available
1206+
if (model.maxTokens) {
1207+
requestBody.max_output_tokens = model.maxTokens
1208+
}
1209+
1210+
// Include text.verbosity only when the model explicitly supports it
1211+
if (model.info.supportsVerbosity === true) {
1212+
requestBody.text = { verbosity: (verbosity || "medium") as VerbosityLevel }
1213+
}
1214+
1215+
// Make the non-streaming request
1216+
const response = await (this.client as any).responses.create(requestBody)
1217+
1218+
// Extract text from the response
1219+
if (response?.output && Array.isArray(response.output)) {
1220+
for (const outputItem of response.output) {
1221+
if (outputItem.type === "message" && outputItem.content) {
1222+
for (const content of outputItem.content) {
1223+
if (content.type === "output_text" && content.text) {
1224+
return content.text
1225+
}
1226+
}
1227+
}
1228+
}
1229+
}
1230+
1231+
// Fallback: check for direct text in response
1232+
if (response?.text) {
1233+
return response.text
1234+
}
1235+
1236+
return ""
1237+
} catch (error) {
1238+
if (error instanceof Error) {
1239+
throw new Error(`OpenAI Native completion error: ${error.message}`)
1240+
}
1241+
throw error
1242+
}
11701243
}
11711244
}

0 commit comments

Comments
 (0)