upped timeout and changed error msg (#341)

This commit is contained in:
Cole Lashley 2024-02-26 22:21:28 -08:00 committed by GitHub
parent b120a7952d
commit f27f0d3958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,7 +24,7 @@ const DefaultMaxTokens = 1000
const DefaultModel = "gpt-3.5-turbo" const DefaultModel = "gpt-3.5-turbo"
const DefaultStreamChanSize = 10 const DefaultStreamChanSize = 10
const CloudWebsocketConnectTimeout = 5 * time.Second const CloudWebsocketConnectTimeout = 1 * time.Minute
func convertUsage(resp openaiapi.ChatCompletionResponse) *packet.OpenAIUsageType { func convertUsage(resp openaiapi.ChatCompletionResponse) *packet.OpenAIUsageType {
if resp.Usage.TotalTokens == 0 { if resp.Usage.TotalTokens == 0 {
@ -86,7 +86,9 @@ func RunCloudCompletionStream(ctx context.Context, clientId string, opts *sstore
websocketContext, dialCancelFn := context.WithTimeout(context.Background(), CloudWebsocketConnectTimeout) websocketContext, dialCancelFn := context.WithTimeout(context.Background(), CloudWebsocketConnectTimeout)
defer dialCancelFn() defer dialCancelFn()
conn, _, err := websocket.DefaultDialer.DialContext(websocketContext, pcloud.GetWSEndpoint(), nil) conn, _, err := websocket.DefaultDialer.DialContext(websocketContext, pcloud.GetWSEndpoint(), nil)
if err != nil { if err == context.DeadlineExceeded {
return nil, nil, fmt.Errorf("OpenAI request, timed out connected to cloud server: %v", err)
} else if err != nil {
return nil, nil, fmt.Errorf("OpenAI request, websocket connect error: %v", err) return nil, nil, fmt.Errorf("OpenAI request, websocket connect error: %v", err)
} }
reqPk := packet.MakeOpenAICloudReqPacket() reqPk := packet.MakeOpenAICloudReqPacket()