File tree Expand file tree Collapse file tree
main/java/ai/gradientlabs/client/request
test/java/ai/gradientlabs/client/request Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,8 +12,12 @@ public class FinishConversationRequest {
1212 @ JsonProperty ("reason" )
1313 private final String reason ;
1414
15+ @ JsonProperty ("reason_code" )
16+ private final String reasonCode ;
17+
1518 private FinishConversationRequest (Builder builder ) {
1619 this .reason = builder .reason ;
20+ this .reasonCode = builder .reasonCode ;
1721 }
1822
1923 public static Builder builder () {
@@ -28,8 +32,13 @@ public String getReason() {
2832 return reason ;
2933 }
3034
35+ public String getReasonCode () {
36+ return reasonCode ;
37+ }
38+
3139 public static class Builder {
3240 private String reason ;
41+ private String reasonCode ;
3342
3443 private Builder () {
3544 }
@@ -39,6 +48,11 @@ public Builder reason(String reason) {
3948 return this ;
4049 }
4150
51+ public Builder reasonCode (String reasonCode ) {
52+ this .reasonCode = reasonCode ;
53+ return this ;
54+ }
55+
4256 public FinishConversationRequest build () {
4357 return new FinishConversationRequest (this );
4458 }
Original file line number Diff line number Diff line change 1+ package ai .gradientlabs .client .request ;
2+
3+ import com .fasterxml .jackson .databind .JsonNode ;
4+ import com .fasterxml .jackson .databind .ObjectMapper ;
5+ import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
6+ import org .junit .jupiter .api .Test ;
7+
8+ import static org .junit .jupiter .api .Assertions .assertEquals ;
9+ import static org .junit .jupiter .api .Assertions .assertFalse ;
10+
11+ class FinishConversationRequestTest {
12+
13+ private final ObjectMapper objectMapper = new ObjectMapper ().registerModule (new JavaTimeModule ());
14+
15+ @ Test
16+ void serializesReasonCode () throws Exception {
17+ FinishConversationRequest request = FinishConversationRequest .builder ()
18+ .reason ("The customer said goodbye" )
19+ .reasonCode ("customer-ended-chat" )
20+ .build ();
21+
22+ JsonNode json = objectMapper .valueToTree (request );
23+
24+ assertEquals ("The customer said goodbye" , json .get ("reason" ).asText ());
25+ assertEquals ("customer-ended-chat" , json .get ("reason_code" ).asText ());
26+ assertEquals ("customer-ended-chat" , request .getReasonCode ());
27+ }
28+
29+ @ Test
30+ void omitsReasonCodeWhenNotSet () throws Exception {
31+ FinishConversationRequest request = FinishConversationRequest .builder ()
32+ .reason ("The customer said goodbye" )
33+ .build ();
34+
35+ JsonNode json = objectMapper .valueToTree (request );
36+
37+ assertFalse (json .has ("reason_code" ));
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments