Skip to content

Commit 22239f9

Browse files
committed
fix(chat): increase timeout to 120s and retry once on transient network/abort errors during long generations
1 parent ee6283c commit 22239f9

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/lib/pollinations-client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { PolliClient, DEFAULT_REFERRER } from '../Libs/pollilib/index.js';
22

33
export async function createPollinationsClient({ referrer } = {}) {
44
const inferredReferrer = referrer ?? inferReferrer() ?? DEFAULT_REFERRER;
5-
const client = new PolliClient();
5+
// Use a slightly higher timeout to accommodate longer generations
6+
const client = new PolliClient({ timeoutMs: 120_000 });
67
try { globalThis.__POLLINATIONS_REFERRER__ = inferredReferrer; } catch {}
78
return {
89
client,

src/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ async function requestChatCompletion(model, endpoints) {
16651665
const attemptErrors = [];
16661666
for (const endpoint of endpoints) {
16671667
let retried429 = false;
1668+
let retriedNetwork = false;
16681669
for (;;) {
16691670
try {
16701671
const response = await chat(
@@ -1705,6 +1706,12 @@ async function requestChatCompletion(model, endpoints) {
17051706
await sleep(750);
17061707
continue;
17071708
}
1709+
// Retry once on transient network/abort errors which surface during long generations
1710+
if (!retriedNetwork && /(NetworkError|Failed to fetch|AbortError|aborted|network error|The user aborted a request)/i.test(message)) {
1711+
retriedNetwork = true;
1712+
await sleep(700);
1713+
continue;
1714+
}
17081715
break;
17091716
}
17101717
}

0 commit comments

Comments
 (0)