waylaidwanderer / node-chatgpt-api

A client implementation for ChatGPT and Bing AI. Available as a Node.js module, REST API server, and CLI app.
https://www.npmjs.com/package/@waylaidwanderer/chatgpt-api
MIT License
4.2k stars 738 forks source link

timeout for fetch #74

Closed ikechan8370 closed 1 year ago

ikechan8370 commented 1 year ago

It seems there is no timeout option like timeoutMs for the function. Sometimes a request gets stuck for a long time。

waylaidwanderer commented 1 year ago

Do you have any examples of messages/prompts that cause this issue? Are you using sendMessage() and are you using onProgress (or stream with the API)?

eamd-wq commented 1 year ago

I also encountered, not using onProgress, just receiving callbacks; (from bing)

waylaidwanderer commented 1 year ago

@eamd-wq if you can enable debug mode on the bing client and reproduce, that would be helpful.

ikechan8370 commented 1 year ago

I'm using BingAIClient. I enable debug mode and found out what happend from the log:

[{"type":2,"invocationId":"3","item":{"firstNewMessageIndex":null,"suggestedResponses":null,"conversationId":"51D|BingProd|8D378A9505C06FB6903157F43142B53F6FAE438F7F2DE4A36DAB309971B9875A","requestId":"bd1a5297-8c32-4221-9c5c
-6bcdfa2f9d97","telemetry":{"metrics":null,"startTime":"2023-02-15T03:06:25.6056157Z"},"result":{"value":"InternalError","message":"Unhandled Exception","error":"Unhandled Exception\n ---> Object reference not set to an insta
nce of an object.","exception":"Microsoft.TuringBot.Common.ServiceInternalError: Unhandled Exception\r\n ---> System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at BotClientLibrary.Exte
nsions.DeepLeoOrchestrator.GetMessageWithModelClassification(ExtensionRequest request, Message message) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\DeepLeoOrchestrator.cs:line 240\r\n   at B
otClientLibrary.Extensions.DeepLeoOrchestrator.Run(ExtensionRequest request, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\DeepLeoOrchestrator.cs:line 121\
r\n   at BotClientLibrary.Extensions.ExtensionRunner.RunExtension(Conversation conversation, ExtensionConfig extension, ExtensionRequestOptions customOptions, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\servic
es\\TuringBot\\src\\BotClientLibrary\\Extensions\\ExtensionRunner.cs:line 375\r\n   at BotClientLibrary.Extensions.ExtensionRunner.RunExtensions(Conversation conversation, CancellationToken cancellationToken, ComponentPriorit
y minPriority, ComponentPriority maxPriority, ExtensionRequestOptions customOptions) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\ExtensionRunner.cs:line 99\r\n   at BotClientLibrary.ServiceC
lients.Orchestrator.PreOrchestrate(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\Orchestrator.cs:line 568\r\n   at BotClient
Library.BotConnection.InternalRun(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 638\r\n   at BotClientLibrary.BotConne
ction.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 396\r\n   --- End of inner exception stack trace --
-\r\n   at BotClientLibrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 396\r\n   at Bo
tClientLibrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 396\r\n   at BotClientLibrar
y.BotConnection.Run(CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 136\r\n   at Microsoft.Falcon.TuringBot.ChatApiImplementation.Run(BaseRequest r
equest, BaseResponse response, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\Service\\Implementation\\ApiImplementation\\ChatApiImplementation.cs:line 88\r\n   at Microsoft.Falcon.Turin
gBot.RequestProcessor.Run(BaseRequest request, BaseResponse response, IRequestContextInitializer contextInitializer, IRequestValidator requestValidator, IApiImplementation apiImplementation, IAsyncApiEndStep apiEndStep, String apiName, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\Service\\Implementation\\RequestProcessor.cs:line 206","serviceVersion":"20230214.55"}}},{"type":3,"invocationId":"3"}]
[{"type":6}]
[{"type":6}]

It print [{"type":6}] forever and won't stop or return anything. I thought it's timeout error but now I think it's a internal error from microsoft. How to handle error like this?

JieyueCoding commented 1 year ago

I attach my full information. This problem occurs in some message situations. No error occurs when asking the same question in the browser. If the error cannot be resolved, the situation should be terminated immediately, not wait forever.

Type "!" to access the command menu.
? Write a message: 想拉屎厕所没坑位怎么办

⠇ Bing is typing...{
  conversationId: '51D|BingProd|D3BC4F73FFDF0753E7AD431858B85D96ACA314782AB44AE54FCE51A8040CC1AF',
  clientId: '914798183666223',
  conversationSignature: 'XWsVe/pPc7RePY52UmyvTnyE5IS27rvKmR2woRymih4=',
  result: { value: 'Success', message: null }

⠧ Bing is typing...handshake established
{"arguments":[{"source":"cib","optionsSets":["nlu_direct_response_filter","deepleo","enable_debug_commands","disable_emoji_spoken_text","responsible_ai_policy_235","enablemm"],"isStartOfSession":true,"message":{"author":"user","inputMethod":"Keyboard","text":"
想拉屎厕所没坑位怎么办","messageType":"Chat"},"conversationSignature":"XWsVe/pPc7RePY52UmyvTnyE5IS27rvKmR2woRymih4=","participant":{"id":"914798183666223"},"conversationId":"51D|BingProd|D3BC4F73FFDF0753E7AD431858B85D96ACA314782AB44AE54FCE51A8040CC1AF"}],"invoc

⠴ Bing is typing...[{"type":2,"invocationId":"0","item":{"firstNewMessageIndex":null,"suggestedResponses":null,"conversationId":"51D|BingProd|D3BC4F73FFDF0753E7AD431858B85D96ACA314782AB44AE54FCE51A8040CC1AF","requestId":"8fb54a68-87eb-4160-a0de-c991327caf45","telemetry":{"metrics":null,"startTime":"2023-02-15T06:31:34.8405486Z"},"result":{"value":"InternalError","message":"Unhandled Dependency Failure: Bing","error":"Unhandled Dependency Failure: Bing\n ---> ServiceClient failure for Bing","exception":"Microsoft.TuringBot.Common.ServiceInternalError: Unhandled Dependency Failure: Bing\r\n ---> Microsoft.TuringBot.Common.ServiceClientException: ServiceClient failure for Bing\r\n ---> System.Net.Http.HttpRequestException: Failed to call \"Bing\" at \"https://www.bing.com/api/v7/search?appid=[REDACTED]&q=%e6%83%b3%e6%8b%89%e5%b1%8e%e5%8e%95%e6%89%80%e6%b2%a1%e5%9d%91%e4%bd%8d%e6%80%8e%e4%b9%88%e5%8a%9e&format=json&conversation=true&screenshotstyle=small&setLang=en-us&mkt=en-us\". StatusCode=Redirect - ReasonPhrase=Found.\r\n   
at BotClientLibrary.ServiceClients.ServiceClient.SendHttpRequest(String url, HttpRequestMessage request, TelemetryScope scope, CancellationToken cancellationToken, String serviceName, ServiceClientOptions options) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\ServiceClient.cs:line 549\r\n   at BotClientLibrary.ServiceClients.ServiceClient.Run(Conversation conversation, Message message, CancellationToken cancellationToken, BatchRequest batchRequest, ServiceClientOptions options) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\ServiceClient.cs:line 354\r\n   --- End of inner exception stack trace ---\r\n   at BotClientLibrary.ServiceClients.PassageFinder.PassageFinder.Run(Conversation conversation, Message message, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\PassageFinder\\PassageFinder.cs:line 138\r\n   at BotClientLibrary.Extensions.DeepLeoOrchestrator.DoWebSearch(ExtensionResponse result, Conversation conversation, Message searchQueryMessage, DeepLeoConfiguration config, Dictionary`2 searchResultScenarioMapping, DeepLeoMessageFactory messageFactory, IEnumerable`1 searchResultFilters, RenderCardMessageFilter renderCardFilter, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\DeepLeoOrchestrator.cs:line 539\r\n   at BotClientLibrary.Extensions.DeepLeoOrchestrator.RunDeepLeoEngine(ExtensionResponse result, Conversation conversation, TuringBotConfiguration config, Message message, DeepLeoMessageFactory messageFactory) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\DeepLeoOrchestrator.cs:line 412\r\n   at BotClientLibrary.Extensions.DeepLeoOrchestrator.Run(Exbrary\\Extensions\\ExtensionRunner.cs:line 375\r\n   at BotClientLibrary.Extensions.ExtensionRunner.RunExtensions(Conversation conversation, CancellationToken cancellationToken, ComponentPriority minPriority, ComposionRunner.RunExtension(Conversation conversatinentPriority maxPriority, ExtensionRequestOptions customOptions) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\ExtensionRunner.cs:line 99\r\n   at BotClientLibrary.ServiceClients.Orr\n   at BotClientLibrary.Extensions.ExtensionRchestrator.PreOrchestrate(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\Orchestrator.cs:line 568\r\n   at BotCliees\\TuringBot\\src\\BotClientLibrary\\ExtensionntLibrary.BotConnection.InternalRun(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 638\r\n   at BotClientLibtClientLibrary\\ServiceClients\\Orchestrator.csrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 396\r\n   --- End of inner  638\r\n   at BotClientLibrary.BotConnection.Ex
exception stack trace ---\r\n   at BotClientLibrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Bo ---\r\n   at BotClientLibrary.BotConnection.ExtConnection.cs:line 396\r\n   at BotClientLibrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotCuteBotTurn(Conversation conversation, Cancellatonnection.cs:line 396\r\n   at BotClientLibrary.BotConnection.Run(CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 136\r\n   at Microsoftork\\1\\s\\services\\TuringBot\\src\\BotClientL.Falcon.TuringBot.ChatApiImplementation.Run(BaseRequest request, BaseResponse response, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\Service\\Implementation\\ApiImplementatingBot\\src\\Service\\Implementation\\ApiImplemeon\\ChatApiImplementation.cs:line 88\r\n   at Microsoft.Falcon.TuringBot.RequestProcessor.Run(BaseRequest request, BaseResponse response, IRequestContextInitializer contextInitializer, IRequestValidator requestValitValidator, IApiImplementation apiImplementatiodator, IApiImplementation apiImplementatio

⠋ Bing is typing...
ikechan8370 commented 1 year ago

I attach my full information. This problem occurs in some message situations. No error occurs when asking the same question in the browser. If the error cannot be resolved, the situation should be terminated immediately, not wait forever.

Type "!" to access the command menu.
? Write a message: 想拉屎厕所没坑位怎么办

⠇ Bing is typing...{
  conversationId: '51D|BingProd|D3BC4F73FFDF0753E7AD431858B85D96ACA314782AB44AE54FCE51A8040CC1AF',
  clientId: '914798183666223',
  conversationSignature: 'XWsVe/pPc7RePY52UmyvTnyE5IS27rvKmR2woRymih4=',
  result: { value: 'Success', message: null }

⠧ Bing is typing...handshake established
{"arguments":[{"source":"cib","optionsSets":["nlu_direct_response_filter","deepleo","enable_debug_commands","disable_emoji_spoken_text","responsible_ai_policy_235","enablemm"],"isStartOfSession":true,"message":{"author":"user","inputMethod":"Keyboard","text":"
想拉屎厕所没坑位怎么办","messageType":"Chat"},"conversationSignature":"XWsVe/pPc7RePY52UmyvTnyE5IS27rvKmR2woRymih4=","participant":{"id":"914798183666223"},"conversationId":"51D|BingProd|D3BC4F73FFDF0753E7AD431858B85D96ACA314782AB44AE54FCE51A8040CC1AF"}],"invoc

⠴ Bing is typing...[{"type":2,"invocationId":"0","item":{"firstNewMessageIndex":null,"suggestedResponses":null,"conversationId":"51D|BingProd|D3BC4F73FFDF0753E7AD431858B85D96ACA314782AB44AE54FCE51A8040CC1AF","requestId":"8fb54a68-87eb-4160-a0de-c991327caf45","telemetry":{"metrics":null,"startTime":"2023-02-15T06:31:34.8405486Z"},"result":{"value":"InternalError","message":"Unhandled Dependency Failure: Bing","error":"Unhandled Dependency Failure: Bing\n ---> ServiceClient failure for Bing","exception":"Microsoft.TuringBot.Common.ServiceInternalError: Unhandled Dependency Failure: Bing\r\n ---> Microsoft.TuringBot.Common.ServiceClientException: ServiceClient failure for Bing\r\n ---> System.Net.Http.HttpRequestException: Failed to call \"Bing\" at \"https://www.bing.com/api/v7/search?appid=[REDACTED]&q=%e6%83%b3%e6%8b%89%e5%b1%8e%e5%8e%95%e6%89%80%e6%b2%a1%e5%9d%91%e4%bd%8d%e6%80%8e%e4%b9%88%e5%8a%9e&format=json&conversation=true&screenshotstyle=small&setLang=en-us&mkt=en-us\". StatusCode=Redirect - ReasonPhrase=Found.\r\n   
at BotClientLibrary.ServiceClients.ServiceClient.SendHttpRequest(String url, HttpRequestMessage request, TelemetryScope scope, CancellationToken cancellationToken, String serviceName, ServiceClientOptions options) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\ServiceClient.cs:line 549\r\n   at BotClientLibrary.ServiceClients.ServiceClient.Run(Conversation conversation, Message message, CancellationToken cancellationToken, BatchRequest batchRequest, ServiceClientOptions options) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\ServiceClient.cs:line 354\r\n   --- End of inner exception stack trace ---\r\n   at BotClientLibrary.ServiceClients.PassageFinder.PassageFinder.Run(Conversation conversation, Message message, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\PassageFinder\\PassageFinder.cs:line 138\r\n   at BotClientLibrary.Extensions.DeepLeoOrchestrator.DoWebSearch(ExtensionResponse result, Conversation conversation, Message searchQueryMessage, DeepLeoConfiguration config, Dictionary`2 searchResultScenarioMapping, DeepLeoMessageFactory messageFactory, IEnumerable`1 searchResultFilters, RenderCardMessageFilter renderCardFilter, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\DeepLeoOrchestrator.cs:line 539\r\n   at BotClientLibrary.Extensions.DeepLeoOrchestrator.RunDeepLeoEngine(ExtensionResponse result, Conversation conversation, TuringBotConfiguration config, Message message, DeepLeoMessageFactory messageFactory) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\DeepLeoOrchestrator.cs:line 412\r\n   at BotClientLibrary.Extensions.DeepLeoOrchestrator.Run(Exbrary\\Extensions\\ExtensionRunner.cs:line 375\r\n   at BotClientLibrary.Extensions.ExtensionRunner.RunExtensions(Conversation conversation, CancellationToken cancellationToken, ComponentPriority minPriority, ComposionRunner.RunExtension(Conversation conversatinentPriority maxPriority, ExtensionRequestOptions customOptions) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Extensions\\ExtensionRunner.cs:line 99\r\n   at BotClientLibrary.ServiceClients.Orr\n   at BotClientLibrary.Extensions.ExtensionRchestrator.PreOrchestrate(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\ServiceClients\\Orchestrator.cs:line 568\r\n   at BotCliees\\TuringBot\\src\\BotClientLibrary\\ExtensionntLibrary.BotConnection.InternalRun(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 638\r\n   at BotClientLibtClientLibrary\\ServiceClients\\Orchestrator.csrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 396\r\n   --- End of inner  638\r\n   at BotClientLibrary.BotConnection.Ex
exception stack trace ---\r\n   at BotClientLibrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\Bo ---\r\n   at BotClientLibrary.BotConnection.ExtConnection.cs:line 396\r\n   at BotClientLibrary.BotConnection.ExecuteBotTurn(Conversation conversation, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotCuteBotTurn(Conversation conversation, Cancellatonnection.cs:line 396\r\n   at BotClientLibrary.BotConnection.Run(CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\BotClientLibrary\\BotConnection.cs:line 136\r\n   at Microsoftork\\1\\s\\services\\TuringBot\\src\\BotClientL.Falcon.TuringBot.ChatApiImplementation.Run(BaseRequest request, BaseResponse response, CancellationToken cancellationToken) in C:\\a\\_work\\1\\s\\services\\TuringBot\\src\\Service\\Implementation\\ApiImplementatingBot\\src\\Service\\Implementation\\ApiImplemeon\\ChatApiImplementation.cs:line 88\r\n   at Microsoft.Falcon.TuringBot.RequestProcessor.Run(BaseRequest request, BaseResponse response, IRequestContextInitializer contextInitializer, IRequestValidator requestValitValidator, IApiImplementation apiImplementatiodator, IApiImplementation apiImplementatio

⠋ Bing is typing...

I use the p-timeout package to temporarily solve this problem.

waylaidwanderer commented 1 year ago

Hi, please update to 1.16.4 which fixes this issue.

waylaidwanderer commented 1 year ago

Sorry, not 1.16.2, 1.16.3.

waylaidwanderer commented 1 year ago

Pushed another patch that detects errors better, 1.16.4.