- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.7k
Add dependency injection to ChatCompletionStream for improved testability #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,199 @@ | ||||
| package openai_test | ||||
|  | ||||
| import ( | ||||
| "context" | ||||
| "errors" | ||||
| "io" | ||||
| "testing" | ||||
|  | ||||
| "github.com/sashabaranov/go-openai" | ||||
| ) | ||||
|  | ||||
| // This file demonstrates how to create mock clients for go-openai streaming | ||||
| // functionality. This pattern is useful when testing code that depends on | ||||
| // go-openai streaming but you want to control the responses for testing. | ||||
|  | ||||
| // MockOpenAIStreamClient demonstrates how to create a full mock client for go-openai. | ||||
| type MockOpenAIStreamClient struct { | ||||
| // Configure canned responses | ||||
| ChatCompletionResponse openai.ChatCompletionResponse | ||||
| 
     | ||||
| ChatCompletionResponse openai.ChatCompletionResponse | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -16,6 +16,8 @@ var ( | |
| errorPrefix = regexp.MustCompile(`^data:\s*{"error":`) | ||
| ) | ||
|  | ||
| var _ ChatStreamReader = (*streamReader[ChatCompletionStreamResponse])(nil) | ||
| 
     | ||
|  | ||
| type streamable interface { | ||
| ChatCompletionStreamResponse | CompletionResponse | ||
| } | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sashabaranov Does this approach fulfill your intent in the
Notecomment?