@@ -17,17 +17,17 @@ class Config {
1717 'Accept-Encoding' : 'gzip, deflate, br, zstd' ,
1818 'Accept-Language' : 'zh-CN,zh;q=0.9' ,
1919 Origin : 'https://duckduckgo.com/' ,
20- Cookie : 'l=wt-wt; ah=wt-wt; dcm=6 ' ,
20+ Cookie : 'dcm=3 ' ,
2121 Dnt : '1' ,
2222 Priority : 'u=1, i' ,
2323 Referer : 'https://duckduckgo.com/' ,
24- 'Sec-Ch-Ua' : '"Microsoft Edge ";v="129 ", "Not(A:Brand ";v="8 ", "Chromium ";v="129 "' ,
24+ 'Sec-Ch-Ua' : '"Chromium ";v="130 ", "Microsoft Edge ";v="130 ", "Not?A_Brand ";v="99 "' ,
2525 'Sec-Ch-Ua-Mobile' : '?0' ,
2626 'Sec-Ch-Ua-Platform' : '"Windows"' ,
2727 'Sec-Fetch-Dest' : 'empty' ,
2828 'Sec-Fetch-Mode' : 'cors' ,
2929 'Sec-Fetch-Site' : 'same-origin' ,
30- 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127 .0.0.0 Safari/537.36' ,
30+ 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130 .0.0.0 Safari/537.36 Edg/130.0.0.0 ' ,
3131 }
3232 }
3333}
@@ -117,7 +117,7 @@ async function createCompletion(model, content, returnStream, retryCount = 0) {
117117 } )
118118
119119 if ( ! response . ok ) {
120- throw new Error ( `HTTP error! status: ${ response . status } ` )
120+ throw new Error ( `Create Completion error! status: ${ response . status } ` )
121121 }
122122 return handlerStream ( model , response . body , returnStream )
123123 } catch ( err ) {
@@ -225,20 +225,19 @@ function messagesPrepare(messages) {
225225}
226226
227227async function requestToken ( ) {
228- const response = await fetch ( `https://duckduckgo.com/duckchat/v1/status` , {
229- method : 'GET' ,
230- headers : {
231- ...config . FAKE_HEADERS ,
232- 'x-vqd-accept' : '1' ,
233- } ,
234- } )
235-
236- if ( ! response . ok ) {
237- throw new Error ( `HTTP error! status: ${ response . status } ` )
228+ try {
229+ const response = await fetch ( `https://duckduckgo.com/duckchat/v1/status` , {
230+ method : 'GET' ,
231+ headers : {
232+ ...config . FAKE_HEADERS ,
233+ 'x-vqd-accept' : '1' ,
234+ } ,
235+ } )
236+ const token = response . headers . get ( 'x-vqd-4' )
237+ return token
238+ } catch ( error ) {
239+ console . log ( "Request token error: " , err )
238240 }
239-
240- const token = response . headers . get ( 'x-vqd-4' )
241- return token
242241}
243242
244243function convertModel ( inputModel ) {
@@ -315,7 +314,7 @@ function newChatCompletionWithModel(text, model) {
315314
316315// Serverless Service
317316
318- ; ( async ( ) => {
317+ ( async ( ) => {
319318 //For Cloudflare Workers
320319 if ( typeof addEventListener === 'function' ) return
321320 // For Nodejs
0 commit comments