Skip to content

Commit 634af4d

Browse files
committed
test
1 parent 2bfc79f commit 634af4d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pkg/openai/openai.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,29 @@ func (c *ChatOpenAI) SendMessage(message []Message) (*Response, error) {
3636
Messages: message,
3737
}
3838

39+
fmt.Println("a")
3940
requestBodyJSON, err := json.Marshal(requestBody)
4041
if err != nil {
4142
return nil, fmt.Errorf("Error marshaling request body: %w", err)
4243
}
43-
44+
fmt.Println("b")
4445
// Create a new HTTP request
4546
req, err := http.NewRequest("POST", openaiURL, bytes.NewBuffer(requestBodyJSON))
4647
if err != nil {
4748
return nil, fmt.Errorf("Error creating HTTP request: %w", err)
4849
}
50+
fmt.Println("c")
4951

5052
// Set the necessary headers
5153
req.Header.Set("Content-Type", "application/json")
5254
req.Header.Set("Authorization", "Bearer "+c.apiKey)
53-
55+
fmt.Println("d")
5456
resp, err := c.httpClient.Do(req)
5557
if err != nil {
5658
return nil, fmt.Errorf("Error sending HTTP request: %w", err)
5759
}
5860
defer resp.Body.Close()
59-
61+
fmt.Println("d")
6062
// Read the response body
6163
respBody, err := io.ReadAll(resp.Body)
6264

pkg/openai/openai_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package openai
22

33
import (
4+
"fmt"
45
"net/http"
56
"reflect"
67
"testing"
@@ -44,10 +45,16 @@ func TestSendMessage(t *testing.T) {
4445
return resp, nil
4546
})
4647

47-
client, _ := NewChatOpenAI("gpt-3.5-turbo")
48+
client, err := NewChatOpenAI("gpt-3.5-turbo")
49+
if err != nil {
50+
t.Fatalf("Error happens: %v", err)
51+
}
4852
for _, tc := range tests {
4953
t.Run(tc.name, func(t *testing.T) {
54+
fmt.Println("1")
55+
fmt.Println(tc.message)
5056
have, err := client.SendMessage(tc.message)
57+
fmt.Println("2")
5158
if err != nil {
5259
t.Fatalf("Error happens: %v", err)
5360
}

0 commit comments

Comments
 (0)