Skip to content

Commit 3668e28

Browse files
committed
feat(conversations): add conversation and model management APIs
- Add ConversationModels API for managing LLM model configurations - Add Conversations API for handling chat history and interactions - Implement CRUD operations for conversation models - Add integration tests for conversation model operations - Update Client class to support conversation operations - Use environment variables for OpenAI API key in tests build(gradle): fix JUnit platform tags configuration feat(client): add conversation support to base Client class feat(schema): add conversation data model interfaces feat(api): implement conversation model management feat(api): add conversation history management test(conversations): add integration tests for model operations feat(test-utils): add conversation collection and model setup
1 parent 1eee81d commit 3668e28

File tree

12 files changed

+598
-1
lines changed

12 files changed

+598
-1
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ dependencies {
120120
}
121121

122122
tasks.withType(Test).configureEach {
123-
useJUnitPlatform()
123+
useJUnitPlatform {
124+
if (System.getenv('CI')) {
125+
excludeTags 'excludeFromCI'
126+
}
127+
}
124128
}
125129

126130
swaggerSources {

src/main/java/org/typesense/api/Client.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class Client {
2424
private Stopwords stopwords;
2525
private Map<String, StopwordsSet> individualStopwordsSets;
2626

27+
private Conversations conversations;
28+
private Map<String, Conversation> individualConversations;
29+
2730
public Health health;
2831
public Operations operations;
2932
public Metrics metrics;
@@ -47,6 +50,8 @@ public Client(Configuration configuration){
4750
this.analytics = new Analytics(this.apiCall);
4851
this.stopwords = new Stopwords(this.apiCall);
4952
this.individualStopwordsSets = new HashMap<>();
53+
this.conversations = new Conversations(this.apiCall);
54+
this.individualConversations = new HashMap<>();
5055
}
5156

5257
public Collection collections(String name){
@@ -114,4 +119,19 @@ public StopwordsSet stopwords(String stopwordsSetId) {
114119
retVal = this.individualStopwordsSets.get(stopwordsSetId);
115120
return retVal;
116121
}
122+
123+
public Conversation conversations(String id) {
124+
Conversation retVal;
125+
126+
if (!this.individualConversations.containsKey(id)) {
127+
this.individualConversations.put(id, new Conversation(id, this.apiCall));
128+
}
129+
130+
retVal = this.individualConversations.get(id);
131+
return retVal;
132+
}
133+
134+
public Conversations conversations() {
135+
return this.conversations;
136+
}
117137
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
package org.typesense.api;
3+
4+
import org.typesense.api.utils.URLEncoding;
5+
import org.typesense.interfaces.ConversationDeleteSchema;
6+
import org.typesense.interfaces.ConversationSchema;
7+
import org.typesense.model.CollectionUpdateSchema;
8+
9+
public class Conversation {
10+
private final ApiCall apiCall;
11+
private final String conversationId;
12+
13+
public Conversation(String conversationId, ApiCall apiCall) {
14+
this.apiCall = apiCall;
15+
this.conversationId = conversationId;
16+
}
17+
18+
19+
public ConversationSchema retrieve() throws Exception {
20+
return this.apiCall.get(this.getEndpoint(), null, ConversationSchema.class);
21+
}
22+
23+
public ConversationDeleteSchema delete() throws Exception {
24+
return this.apiCall.delete(this.getEndpoint(), null, ConversationDeleteSchema.class);
25+
}
26+
27+
public CollectionUpdateSchema update(CollectionUpdateSchema schema) throws Exception {
28+
return this.apiCall.put(this.getEndpoint(), schema, null, CollectionUpdateSchema.class);
29+
}
30+
31+
private String getEndpoint() {
32+
return Conversations.RESOURCE_PATH + "/" + URLEncoding.encodeURIComponent(conversationId);
33+
}
34+
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
package org.typesense.api;
3+
4+
import org.typesense.api.utils.URLEncoding;
5+
import org.typesense.model.ConversationModelSchema;
6+
import org.typesense.model.ConversationModelUpdateSchema;
7+
8+
public class ConversationModel {
9+
10+
private final ApiCall apiCall;
11+
private final String id;
12+
13+
public ConversationModel(ApiCall apiCall, String id) {
14+
this.apiCall = apiCall;
15+
this.id = id;
16+
}
17+
18+
public ConversationModelUpdateSchema update(ConversationModelUpdateSchema schema) throws Exception {
19+
return this.apiCall.put(this.getEndpoint(), schema, null, ConversationModelUpdateSchema.class);
20+
}
21+
22+
public ConversationModelSchema retrieve() throws Exception {
23+
return this.apiCall.get(this.getEndpoint(), null, ConversationModelSchema.class);
24+
}
25+
26+
public ConversationModelSchema delete() throws Exception {
27+
return this.apiCall.delete(this.getEndpoint(), null, ConversationModelSchema.class);
28+
}
29+
30+
private String getEndpoint() {
31+
return ConversationModels.RESOURCE_PATH + "/" + URLEncoding.encodeURIComponent(this.id);
32+
}
33+
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.typesense.api;
2+
3+
import org.typesense.model.ConversationModelCreateSchema;
4+
import org.typesense.model.ConversationModelSchema;
5+
6+
public class ConversationModels {
7+
8+
private final ApiCall apiCall;
9+
public final static String RESOURCE_PATH = "/conversations/models";
10+
11+
public ConversationModels(ApiCall apiCall) {
12+
this.apiCall = apiCall;
13+
}
14+
15+
public ConversationModelCreateSchema create(ConversationModelCreateSchema schema) throws Exception {
16+
return this.apiCall.post(RESOURCE_PATH, schema, null, ConversationModelCreateSchema.class);
17+
}
18+
19+
public ConversationModelSchema[] retrieve() throws Exception {
20+
return this.apiCall.get(RESOURCE_PATH, null, ConversationModelSchema[].class);
21+
}
22+
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.typesense.api;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.typesense.interfaces.ConversationsRetrieveSchema;
7+
8+
public class Conversations {
9+
10+
private final ApiCall apiCall;
11+
public final static String RESOURCE_PATH = "/conversations";
12+
13+
private final ConversationModels conversationModels;
14+
private final Map<String, ConversationModel> individualConversations;
15+
16+
public Conversations(ApiCall apiCall) {
17+
this.apiCall = apiCall;
18+
this.conversationModels = new ConversationModels(this.apiCall);
19+
this.individualConversations = new HashMap<>();
20+
}
21+
22+
public ConversationsRetrieveSchema retrieve() throws Exception {
23+
return this.apiCall.get(Conversations.RESOURCE_PATH, null, ConversationsRetrieveSchema.class);
24+
}
25+
26+
public ConversationModels models() {
27+
return this.conversationModels;
28+
}
29+
30+
public ConversationModel models(String conversationId) {
31+
ConversationModel retVal;
32+
33+
if (!this.individualConversations.containsKey(conversationId)) {
34+
this.individualConversations.put(conversationId, new ConversationModel(apiCall, conversationId));
35+
}
36+
37+
retVal = this.individualConversations.get(conversationId);
38+
return retVal;
39+
}
40+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.typesense.interfaces;
2+
3+
import java.util.Objects;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
import io.swagger.v3.oas.annotations.media.Schema;
8+
9+
public class ConversationDeleteSchema {
10+
@JsonProperty("id")
11+
private Long id = null;
12+
13+
public ConversationDeleteSchema id(Long id) {
14+
this.id = id;
15+
return this;
16+
}
17+
18+
/**
19+
* The ID of the conversation to delete
20+
* @return id
21+
**/
22+
@Schema(required = true, description = "The ID of the conversation to delete")
23+
public Long getId() {
24+
return id;
25+
}
26+
27+
public void setId(Long id) {
28+
this.id = id;
29+
}
30+
31+
@Override
32+
public boolean equals(java.lang.Object o) {
33+
if (this == o) return true;
34+
if (o == null || getClass() != o.getClass()) return false;
35+
ConversationDeleteSchema that = (ConversationDeleteSchema) o;
36+
return Objects.equals(this.id, that.id);
37+
}
38+
39+
@Override
40+
public int hashCode() {
41+
return Objects.hash(id);
42+
}
43+
44+
@Override
45+
public String toString() {
46+
StringBuilder sb = new StringBuilder();
47+
sb.append("class ConversationDeleteSchema {\n");
48+
sb.append(" id: ").append(toIndentedString(id)).append("\n");
49+
sb.append("}");
50+
return sb.toString();
51+
}
52+
53+
private String toIndentedString(java.lang.Object o) {
54+
if (o == null) return "null";
55+
return o.toString().replace("\n", "\n ");
56+
}
57+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package org.typesense.interfaces;
2+
3+
4+
import java.util.Arrays;
5+
import java.util.Objects;
6+
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
11+
public class ConversationSchema {
12+
@JsonProperty("id")
13+
private Long id = null;
14+
15+
@JsonProperty("conversation")
16+
private Object[] conversation = null;
17+
18+
@JsonProperty("last_updated")
19+
private Long lastUpdated = null;
20+
21+
@JsonProperty("ttl")
22+
private Long ttl = null;
23+
24+
public ConversationSchema id(Long id) {
25+
this.id = id;
26+
return this;
27+
}
28+
29+
/**
30+
* The unique identifier of the conversation
31+
* @return id
32+
**/
33+
@Schema(required = true, description = "The unique identifier of the conversation")
34+
public Long getId() {
35+
return id;
36+
}
37+
38+
public void setId(Long id) {
39+
this.id = id;
40+
}
41+
42+
public ConversationSchema conversation(Object[] conversation) {
43+
this.conversation = conversation;
44+
return this;
45+
}
46+
47+
/**
48+
* Array of conversation objects
49+
* @return conversation
50+
**/
51+
@Schema(required = true, description = "Array of conversation objects")
52+
public Object[] getConversation() {
53+
return conversation;
54+
}
55+
56+
public void setConversation(Object[] conversation) {
57+
this.conversation = conversation;
58+
}
59+
60+
public ConversationSchema lastUpdated(Long lastUpdated) {
61+
this.lastUpdated = lastUpdated;
62+
return this;
63+
}
64+
65+
/**
66+
* Timestamp of when the conversation was last updated
67+
* @return lastUpdated
68+
**/
69+
@Schema(required = true, description = "Timestamp of when the conversation was last updated")
70+
public Long getLastUpdated() {
71+
return lastUpdated;
72+
}
73+
74+
public void setLastUpdated(Long lastUpdated) {
75+
this.lastUpdated = lastUpdated;
76+
}
77+
78+
public ConversationSchema ttl(Long ttl) {
79+
this.ttl = ttl;
80+
return this;
81+
}
82+
83+
/**
84+
* Time to live for the conversation in seconds
85+
* @return ttl
86+
**/
87+
@Schema(required = true, description = "Time to live for the conversation in seconds")
88+
public Long getTtl() {
89+
return ttl;
90+
}
91+
92+
public void setTtl(Long ttl) {
93+
this.ttl = ttl;
94+
}
95+
96+
@Override
97+
public boolean equals(java.lang.Object o) {
98+
if (this == o) return true;
99+
if (o == null || getClass() != o.getClass()) return false;
100+
ConversationSchema that = (ConversationSchema) o;
101+
return Objects.equals(this.id, that.id) &&
102+
Arrays.equals(this.conversation, that.conversation) &&
103+
Objects.equals(this.lastUpdated, that.lastUpdated) &&
104+
Objects.equals(this.ttl, that.ttl);
105+
}
106+
107+
@Override
108+
public int hashCode() {
109+
return Objects.hash(id, Arrays.hashCode(conversation), lastUpdated, ttl);
110+
}
111+
112+
@Override
113+
public String toString() {
114+
StringBuilder sb = new StringBuilder();
115+
sb.append("class ConversationSchema {\n");
116+
sb.append(" id: ").append(toIndentedString(id)).append("\n");
117+
sb.append(" conversation: ").append(toIndentedString(Arrays.toString(conversation))).append("\n");
118+
sb.append(" lastUpdated: ").append(toIndentedString(lastUpdated)).append("\n");
119+
sb.append(" ttl: ").append(toIndentedString(ttl)).append("\n");
120+
sb.append("}");
121+
return sb.toString();
122+
}
123+
124+
private String toIndentedString(java.lang.Object o) {
125+
if (o == null) return "null";
126+
return o.toString().replace("\n", "\n ");
127+
}
128+
}

0 commit comments

Comments
 (0)