Skip to content

Commit

Permalink
make linter happy (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashabaranov authored Feb 15, 2024
1 parent a7954c8 commit 11ad4b6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion embeddings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestAzureEmbeddingEndpoint(t *testing.T) {

server.RegisterHandler(
"/openai/deployments/text-embedding-ada-002/embeddings",
func(w http.ResponseWriter, r *http.Request) {
func(w http.ResponseWriter, _ *http.Request) {
resBytes, _ := json.Marshal(openai.EmbeddingResponse{Data: sampleEmbeddings})
fmt.Fprintln(w, string(resBytes))
},
Expand Down
10 changes: 5 additions & 5 deletions files_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func handleCreateFile(w http.ResponseWriter, r *http.Request) {
func TestDeleteFile(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/files/deadbeef", func(w http.ResponseWriter, r *http.Request) {})
server.RegisterHandler("/v1/files/deadbeef", func(http.ResponseWriter, *http.Request) {})
err := client.DeleteFile(context.Background(), "deadbeef")
checks.NoError(t, err, "DeleteFile error")
}

func TestListFile(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/files", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/files", func(w http.ResponseWriter, _ *http.Request) {
resBytes, _ := json.Marshal(openai.FilesList{})
fmt.Fprintln(w, string(resBytes))
})
Expand All @@ -105,7 +105,7 @@ func TestListFile(t *testing.T) {
func TestGetFile(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/files/deadbeef", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/files/deadbeef", func(w http.ResponseWriter, _ *http.Request) {
resBytes, _ := json.Marshal(openai.File{})
fmt.Fprintln(w, string(resBytes))
})
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestGetFileContentReturnError(t *testing.T) {
}`
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/files/deadbeef/content", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/files/deadbeef/content", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, wantErrorResp)
})
Expand All @@ -178,7 +178,7 @@ func TestGetFileContentReturnError(t *testing.T) {
func TestGetFileContentReturnTimeoutError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/files/deadbeef/content", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/files/deadbeef/content", func(http.ResponseWriter, *http.Request) {
time.Sleep(10 * time.Nanosecond)
})
ctx := context.Background()
Expand Down
10 changes: 5 additions & 5 deletions image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestImageFormBuilderFailures(t *testing.T) {
_, err := client.CreateEditImage(ctx, req)
checks.ErrorIs(t, err, mockFailedErr, "CreateImage should return error if form builder fails")

mockBuilder.mockCreateFormFile = func(name string, file *os.File) error {
mockBuilder.mockCreateFormFile = func(name string, _ *os.File) error {
if name == "mask" {
return mockFailedErr
}
Expand All @@ -69,12 +69,12 @@ func TestImageFormBuilderFailures(t *testing.T) {
_, err = client.CreateEditImage(ctx, req)
checks.ErrorIs(t, err, mockFailedErr, "CreateImage should return error if form builder fails")

mockBuilder.mockCreateFormFile = func(name string, file *os.File) error {
mockBuilder.mockCreateFormFile = func(string, *os.File) error {
return nil
}

var failForField string
mockBuilder.mockWriteField = func(fieldname, value string) error {
mockBuilder.mockWriteField = func(fieldname, _ string) error {
if fieldname == failForField {
return mockFailedErr
}
Expand Down Expand Up @@ -125,12 +125,12 @@ func TestVariImageFormBuilderFailures(t *testing.T) {
_, err := client.CreateVariImage(ctx, req)
checks.ErrorIs(t, err, mockFailedErr, "CreateVariImage should return error if form builder fails")

mockBuilder.mockCreateFormFile = func(name string, file *os.File) error {
mockBuilder.mockCreateFormFile = func(string, *os.File) error {
return nil
}

var failForField string
mockBuilder.mockWriteField = func(fieldname, value string) error {
mockBuilder.mockWriteField = func(fieldname, _ string) error {
if fieldname == failForField {
return mockFailedErr
}
Expand Down
4 changes: 2 additions & 2 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Message struct {
ThreadID string `json:"thread_id"`
Role string `json:"role"`
Content []MessageContent `json:"content"`
FileIds []string `json:"file_ids"`
FileIds []string `json:"file_ids"` //nolint:revive //backwards-compatibility
AssistantID *string `json:"assistant_id,omitempty"`
RunID *string `json:"run_id,omitempty"`
Metadata map[string]any `json:"metadata"`
Expand Down Expand Up @@ -54,7 +54,7 @@ type ImageFile struct {
type MessageRequest struct {
Role string `json:"role"`
Content string `json:"content"`
FileIds []string `json:"file_ids,omitempty"`
FileIds []string `json:"file_ids,omitempty"` //nolint:revive // backwards-compatibility
Metadata map[string]any `json:"metadata,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func handleGetModelEndpoint(w http.ResponseWriter, _ *http.Request) {
func TestGetModelReturnTimeoutError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/models/text-davinci-003", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/models/text-davinci-003", func(http.ResponseWriter, *http.Request) {
time.Sleep(10 * time.Nanosecond)
})
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Run struct {
Model string `json:"model"`
Instructions string `json:"instructions,omitempty"`
Tools []Tool `json:"tools"`
FileIDS []string `json:"file_ids"`
FileIDS []string `json:"file_ids"` //nolint:revive // backwards-compatibility
Metadata map[string]any `json:"metadata"`
Usage Usage `json:"usage,omitempty"`

Expand Down
14 changes: 7 additions & 7 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCompletionsStreamWrongModel(t *testing.T) {
func TestCreateCompletionStream(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")

// Send test responses
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestCreateCompletionStream(t *testing.T) {
func TestCreateCompletionStreamError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")

// Send test responses
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestCreateCompletionStreamError(t *testing.T) {
func TestCreateCompletionStreamRateLimitError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(429)

Expand Down Expand Up @@ -182,7 +182,7 @@ func TestCreateCompletionStreamRateLimitError(t *testing.T) {
func TestCreateCompletionStreamTooManyEmptyStreamMessagesError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")

// Send test responses
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestCreateCompletionStreamTooManyEmptyStreamMessagesError(t *testing.T) {
func TestCreateCompletionStreamUnexpectedTerminatedError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")

// Send test responses
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestCreateCompletionStreamUnexpectedTerminatedError(t *testing.T) {
func TestCreateCompletionStreamBrokenJSONError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")

// Send test responses
Expand Down Expand Up @@ -305,7 +305,7 @@ func TestCreateCompletionStreamBrokenJSONError(t *testing.T) {
func TestCreateCompletionStreamReturnTimeoutError(t *testing.T) {
client, server, teardown := setupOpenAITestServer()
defer teardown()
server.RegisterHandler("/v1/completions", func(w http.ResponseWriter, r *http.Request) {
server.RegisterHandler("/v1/completions", func(http.ResponseWriter, *http.Request) {
time.Sleep(10 * time.Nanosecond)
})
ctx := context.Background()
Expand Down

0 comments on commit 11ad4b6

Please sign in to comment.