Skip to content

Commit

Permalink
run_id string Optional (#855)
Browse files Browse the repository at this point in the history
Filter messages by the run ID that generated them.

Co-authored-by: wappi <support@wappi.pro>
  • Loading branch information
floodwm and wappipro authored Sep 20, 2024
1 parent 9a4f3a7 commit e095df5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Empty file added .zshrc
Empty file.
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestClientReturnsRequestBuilderErrors(t *testing.T) {
return client.CreateMessage(ctx, "", MessageRequest{})
}},
{"ListMessage", func() (any, error) {
return client.ListMessage(ctx, "", nil, nil, nil, nil)
return client.ListMessage(ctx, "", nil, nil, nil, nil, nil)
}},
{"RetrieveMessage", func() (any, error) {
return client.RetrieveMessage(ctx, "", "")
Expand Down
5 changes: 5 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (c *Client) ListMessage(ctx context.Context, threadID string,
order *string,
after *string,
before *string,
runID *string,
) (messages MessagesList, err error) {
urlValues := url.Values{}
if limit != nil {
Expand All @@ -114,6 +115,10 @@ func (c *Client) ListMessage(ctx context.Context, threadID string,
if before != nil {
urlValues.Add("before", *before)
}
if runID != nil {
urlValues.Add("run_id", *runID)
}

encodedValues := ""
if len(urlValues) > 0 {
encodedValues = "?" + urlValues.Encode()
Expand Down
5 changes: 3 additions & 2 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestMessages(t *testing.T) {
}

var msgs openai.MessagesList
msgs, err = client.ListMessage(ctx, threadID, nil, nil, nil, nil)
msgs, err = client.ListMessage(ctx, threadID, nil, nil, nil, nil, nil)
checks.NoError(t, err, "ListMessages error")
if len(msgs.Messages) != 1 {
t.Fatalf("unexpected length of fetched messages")
Expand All @@ -219,7 +219,8 @@ func TestMessages(t *testing.T) {
order := "desc"
after := "obj_foo"
before := "obj_bar"
msgs, err = client.ListMessage(ctx, threadID, &limit, &order, &after, &before)
runID := "run_abc123"
msgs, err = client.ListMessage(ctx, threadID, &limit, &order, &after, &before, &runID)
checks.NoError(t, err, "ListMessages error")
if len(msgs.Messages) != 1 {
t.Fatalf("unexpected length of fetched messages")
Expand Down

0 comments on commit e095df5

Please sign in to comment.