Skip to content

Commit 27063ce

Browse files
committed
fix(openai): avoid JSON mode for OpenAI endpoint; use plain text to prevent 400; maintain streaming SSE without Accept header
1 parent 8c49a84 commit 27063ce

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Libs/pollilib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ export async function* chatStream(payload, client) {
283283
} catch {}
284284
const resp = await c.fetch(url, {
285285
method: 'POST',
286-
headers: { 'Content-Type': 'application/json', 'Accept': 'text/event-stream' },
286+
// Do not set Accept: text/event-stream — Pollinations returns SSE without it,
287+
// and some gateways 500/400 if Accept is forced.
288+
headers: { 'Content-Type': 'application/json' },
287289
body: JSON.stringify(body),
288290
signal: controller.signal,
289291
});

src/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,13 +1749,14 @@ async function handleChatResponse(initialResponse, model, endpoint) {
17491749

17501750
if (Array.isArray(message.tool_calls) && message.tool_calls.length) {
17511751
await handleToolCalls(message.tool_calls);
1752+
const wantJsonAgain = endpoint !== 'openai';
17521753
response = await chat(
17531754
{
17541755
model: model.id,
17551756
endpoint,
17561757
messages: state.conversation,
17571758
...(shouldIncludeTools(model, endpoint) ? { tools: [IMAGE_TOOL], tool_choice: 'auto' } : {}),
1758-
response_format: { type: 'json_object' },
1759+
...(wantJsonAgain ? { response_format: { type: 'json_object' } } : {}),
17591760
},
17601761
client,
17611762
);
@@ -2265,13 +2266,14 @@ async function requestChatCompletion(model, endpoints) {
22652266
let retriedNetwork = false;
22662267
for (;;) {
22672268
try {
2269+
const wantJson = endpoint !== 'openai';
22682270
const response = await chat(
22692271
{
22702272
model: model.id,
22712273
endpoint,
22722274
messages: state.conversation,
22732275
...(shouldIncludeTools(model, endpoint) ? { tools: [IMAGE_TOOL], tool_choice: 'auto' } : {}),
2274-
response_format: { type: 'json_object' },
2276+
...(wantJson ? { response_format: { type: 'json_object' } } : {}),
22752277
},
22762278
client,
22772279
);

0 commit comments

Comments
 (0)