Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekko0114 committed Jul 7, 2024
1 parent 2bfc79f commit 93965e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- run: make lint

test:
env:
OPENAI_API_KEY: 'dummy'
runs-on: ubuntu-22.04
strategy:
matrix:
Expand Down
3 changes: 0 additions & 3 deletions pkg/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (c *ChatOpenAI) SendMessage(message []Message) (*Response, error) {
if err != nil {
return nil, fmt.Errorf("Error marshaling request body: %w", err)
}

// Create a new HTTP request
req, err := http.NewRequest("POST", openaiURL, bytes.NewBuffer(requestBodyJSON))
if err != nil {
Expand All @@ -50,13 +49,11 @@ func (c *ChatOpenAI) SendMessage(message []Message) (*Response, error) {
// Set the necessary headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+c.apiKey)

resp, err := c.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("Error sending HTTP request: %w", err)
}
defer resp.Body.Close()

// Read the response body
respBody, err := io.ReadAll(resp.Body)

Check failure on line 58 in pkg/openai/openai.go

View workflow job for this annotation

GitHub Actions / lint (1.22)

ineffectual assignment to err (ineffassign)

Expand Down
5 changes: 4 additions & 1 deletion pkg/openai/openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func TestSendMessage(t *testing.T) {
return resp, nil
})

client, _ := NewChatOpenAI("gpt-3.5-turbo")
client, err := NewChatOpenAI("gpt-3.5-turbo")
if err != nil {
t.Fatalf("Error happens: %v", err)
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
have, err := client.SendMessage(tc.message)
Expand Down

0 comments on commit 93965e9

Please sign in to comment.