Skip to content

Commit

Permalink
add: added test on messageCount
Browse files Browse the repository at this point in the history
  • Loading branch information
namwoam committed Jun 27, 2024
1 parent b0501be commit 4ac0c1e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ai/anthropic/v0/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ type MockAnthropicClient struct{}

func (m *MockAnthropicClient) generateTextChat(request messagesReq) (messagesResp, error) {

messageCount := len(request.Messages)
message := fmt.Sprintf("Hi! My name is Claude. (messageCount: %d)", messageCount)
resp := messagesResp{
ID: "msg_013Zva2CMHLNnXjNJJKqJ2EF",
Type: "message",
Role: "assistant",
Content: []content{{Text: "Hi! My name is Claude.", Type: "text"}},
Content: []content{{Text: message, Type: "text"}},
Model: "claude-3-5-sonnet-20240620",
StopReason: "end_turn",
Usage: usage{InputTokens: 10, OutputTokens: 25},
Expand All @@ -179,12 +181,17 @@ func TestComponent_Generation(t *testing.T) {
bc := base.Component{Logger: zap.NewNop()}
connector := Init(bc)

mockHistory := []message{
{Role: "user", Content: []content{{Type: "text", Text: "Answer the following question in traditional chinses"}}},
{Role: "assistant", Content: []content{{Type: "text", Text: "沒問題"}}},
}

tc := struct {
input map[string]any
wantResp messagesOutput
}{
input: map[string]any{"prompt": "Hi! What's your name?"},
wantResp: messagesOutput{Text: "Hi! My name is Claude."},
input: map[string]any{"prompt": "Hi! What's your name?", "chat-history": mockHistory},
wantResp: messagesOutput{Text: "Hi! My name is Claude. (messageCount: 3)"},
}

c.Run("ok - generation", func(c *qt.C) {
Expand Down

0 comments on commit 4ac0c1e

Please sign in to comment.