Skip to content

Commit

Permalink
Merge pull request #39 from sunist-c/main
Browse files Browse the repository at this point in the history
fix(openai): 优化 openai 测试的提示词,避免 openai 的智障导致测试失败
  • Loading branch information
sunist-c authored Oct 10, 2024
2 parents b780ee8 + bba9d2d commit 5c68322
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions thirdparty/openai/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ func TestOpenAiClient(t *testing.T) {
}

t.Run("CompleteChat", func(t *testing.T) {
response, err := client.CompleteChat(background, CompleteChatRequest{
Body: CompleteChatRequestBody{
Model: "gpt-4o",
Messages: []ChatMessageObject{
{
Role: ChatRoleEnumSystem,
Content: json.RawMessage(`"now testing api is working, please echo any input"`),
},
{
Role: ChatRoleEnumUser,
Content: json.RawMessage(`"testing"`),
for i := 0; i < 10; i++ {
response, err := client.CompleteChat(background, CompleteChatRequest{
Body: CompleteChatRequestBody{
Model: "gpt-4o-mini",
Messages: []ChatMessageObject{
{Role: ChatRoleEnumSystem, Content: json.RawMessage(`"Please echo the input content, without any changes"`)},
{Role: ChatRoleEnumUser, Content: json.RawMessage(`"testing"`)},
},
N: 1,
},
N: 1,
},
})
if err != nil {
t.Error(err)
}
})
if err != nil {
t.Error(err)
}

if len(response.Choices) == 0 || !strings.Contains(string(response.Choices[0].Message.Content), "testing") {
t.Error("response is not as expected")
if len(response.Choices) == 0 || !strings.Contains(strings.ToLower(string(response.Choices[0].Message.Content)), "testing") {
continue
}

return
}

t.Error("response is not as expected")
})

t.Run("Embedding", func(t *testing.T) {
Expand Down

0 comments on commit 5c68322

Please sign in to comment.