-
Notifications
You must be signed in to change notification settings - Fork 7
feat(aitaskbuilder): support star_rating instruction type #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Adam1451991B
wants to merge
1
commit into
main
Choose a base branch
from
feat/aitb-star-rating-instruction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
cmd/aitaskbuilder/batch_instructions_starrating_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package aitaskbuilder_test | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "bytes" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/golang/mock/gomock" | ||
| "github.com/prolific-oss/cli/client" | ||
| "github.com/prolific-oss/cli/cmd/aitaskbuilder" | ||
| "github.com/prolific-oss/cli/mock_client" | ||
| "github.com/prolific-oss/cli/model" | ||
| ) | ||
|
|
||
| func TestNewBatchInstructionsCommandWithStarRating(t *testing.T) { | ||
| fiveStars := 5 | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| instructionsJSON string | ||
| payloadMaxStars *int | ||
| }{ | ||
| { | ||
| name: "with explicit max_stars", | ||
| instructionsJSON: `[{ | ||
| "type": "star_rating", | ||
| "created_by": "Sean", | ||
| "description": "How would you rate the overall quality of this response?", | ||
| "max_stars": 5 | ||
| }]`, | ||
| payloadMaxStars: &fiveStars, | ||
| }, | ||
| { | ||
| // max_stars is optional - the API defaults it to 5 when omitted. | ||
| name: "without max_stars", | ||
| instructionsJSON: `[{ | ||
| "type": "star_rating", | ||
| "created_by": "Sean", | ||
| "description": "How would you rate the overall quality of this response?" | ||
| }]`, | ||
| payloadMaxStars: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
| c := mock_client.NewMockAPI(ctrl) | ||
|
|
||
| batchID := "01954894-65b3-779e-aaf6-348698e12360" | ||
|
|
||
| expectedPayload := client.CreateAITaskBuilderInstructionsPayload{ | ||
| Instructions: []client.Instruction{ | ||
| { | ||
| Type: "star_rating", | ||
| CreatedBy: "Sean", | ||
| Description: "How would you rate the overall quality of this response?", | ||
| MaxStars: tc.payloadMaxStars, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| response := client.CreateAITaskBuilderInstructionsResponse{ | ||
| model.Instruction{ | ||
| ID: "inst-star-1", | ||
| Type: "star_rating", | ||
| BatchID: batchID, | ||
| CreatedBy: "Sean", | ||
| Description: "How would you rate the overall quality of this response?", | ||
| MaxStars: tc.payloadMaxStars, | ||
| }, | ||
| } | ||
|
|
||
| c.EXPECT().CreateAITaskBuilderInstructions(batchID, expectedPayload).Return(&response, nil) | ||
|
|
||
| var buf bytes.Buffer | ||
| writer := bufio.NewWriter(&buf) | ||
| cmd := aitaskbuilder.NewBatchInstructionsCommand(c, writer) | ||
| cmd.SetArgs([]string{"-b", batchID, "-j", tc.instructionsJSON}) | ||
|
|
||
| if err := cmd.Execute(); err != nil { | ||
| t.Fatalf("expected no error; got %s", err.Error()) | ||
| } | ||
|
|
||
| writer.Flush() | ||
|
|
||
| expectedOutput := "Successfully added 1 instruction(s) to batch " + batchID | ||
| if !strings.Contains(buf.String(), expectedOutput) { | ||
| t.Fatalf("expected output to contain '%s'; got %s", expectedOutput, buf.String()) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestNewBatchInstructionsCommandStarRatingInvalidMaxStars(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
| c := mock_client.NewMockAPI(ctrl) | ||
|
|
||
| batchID := "01954894-65b3-779e-aaf6-348698e12362" | ||
|
|
||
| var buf bytes.Buffer | ||
| writer := bufio.NewWriter(&buf) | ||
|
|
||
| cmd := aitaskbuilder.NewBatchInstructionsCommand(c, writer) | ||
|
|
||
| instructionsJSON := `[{ | ||
| "type": "star_rating", | ||
| "created_by": "Sean", | ||
| "description": "Rate this response", | ||
| "max_stars": 11 | ||
| }]` | ||
|
|
||
| cmd.SetArgs([]string{ | ||
| "-b", batchID, | ||
| "-j", instructionsJSON, | ||
| }) | ||
|
|
||
| err := cmd.Execute() | ||
| if err == nil { | ||
| t.Fatal("expected an error for max_stars out of range; got none") | ||
| } | ||
|
|
||
| if !strings.Contains(err.Error(), "max_stars must be between 1 and 10") { | ||
| t.Fatalf("expected error about max_stars range; got %s", err.Error()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,12 @@ func renderAITaskBuilderResponses(c client.API, opts BatchGetResponsesOptions, w | |
| } else { | ||
| fmt.Fprintf(w, " Uploaded Files: \n") | ||
| } | ||
| case model.AITaskBuilderResponseTypeStarRating: | ||
| if len(resp.Response.Answer) > 0 && resp.Response.Answer[0].Value != "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(non-blocking): make this a little more readable or add comments |
||
| fmt.Fprintf(w, " Star Rating: %s\n", resp.Response.Answer[0].Value) | ||
| } else { | ||
| fmt.Fprintf(w, " Star Rating: \n") | ||
| } | ||
| } | ||
|
|
||
| if i < len(response.Results)-1 { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: this kind of validation logic sits server side, we don't duplicate it in the client - the rule of thumb means we keep validation in one place and do risk it getting out of sync between server and different clients. Remove the
validateStarRatingrelated code.