Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6cd599

Browse files
authored
Merge pull request#40 from letschers/main
[Chore!] Add error verification on callback from stream
2 parentsf29b15e +9c7ee13 commitc6cd599

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎gpt3.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type Client interface {
8383

8484
// ChatCompletion creates a completion with the Chat completion endpoint which
8585
// is what powers the ChatGPT experience.
86-
ChatCompletionStream(ctx context.Context,requestChatCompletionRequest,onDatafunc(*ChatCompletionStreamResponse))error
86+
ChatCompletionStream(ctx context.Context,requestChatCompletionRequest,onDatafunc(*ChatCompletionStreamResponse)error)error
8787

8888
// Completion creates a completion with the default engine. This is the main endpoint of the API
8989
// which auto-completes based on the given prompt.
@@ -211,7 +211,7 @@ func (c *client) ChatCompletion(ctx context.Context, request ChatCompletionReque
211211
func (c*client)ChatCompletionStream(
212212
ctx context.Context,
213213
requestChatCompletionRequest,
214-
onDatafunc(*ChatCompletionStreamResponse))error {
214+
onDatafunc(*ChatCompletionStreamResponse)error)error {
215215
ifrequest.Model=="" {
216216
request.Model=GPT3Dot5Turbo
217217
}
@@ -252,7 +252,9 @@ func (c *client) ChatCompletionStream(
252252
iferr:=json.Unmarshal(line,output);err!=nil {
253253
returnfmt.Errorf("invalid json stream data: %v",err)
254254
}
255-
onData(output)
255+
iferr:=onData(output);err!=nil {
256+
returnfmt.Errorf("callback returned an error: %v",err)
257+
}
256258
}
257259

258260
returnnil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp