Skip to content

Commit aee05b3

Browse files
committed
Revert "Added Conversation API in MLClient (#3475)"
This reverts commit 627980a. Signed-off-by: Owais <owaiskazi19@gmail.com>
1 parent 627980a commit aee05b3

File tree

7 files changed

+2
-140
lines changed

7 files changed

+2
-140
lines changed

client/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ plugins {
1616
dependencies {
1717
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
1818
implementation project(path: ":${rootProject.name}-common", configuration: 'shadow')
19-
implementation project(path: ":${rootProject.name}-memory")
2019
compileOnly group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
2120
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
2221
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.15.2'

client/src/main/java/org/opensearch/ml/client/MachineLearningClient.java

-19
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.opensearch.ml.common.transport.register.MLRegisterModelInput;
3535
import org.opensearch.ml.common.transport.register.MLRegisterModelResponse;
3636
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsResponse;
37-
import org.opensearch.ml.memory.action.conversation.CreateConversationResponse;
3837

3938
/**
4039
* A client to provide interfaces for machine learning jobs. This will be used by other plugins.
@@ -554,22 +553,4 @@ default void getConfig(String configId, ActionListener<MLConfig> listener) {
554553
* @param listener a listener to be notified of the result
555554
*/
556555
void getConfig(String configId, String tenantId, ActionListener<MLConfig> listener);
557-
558-
/**
559-
* Create conversational memory for conversation
560-
* @param name name of the conversation, refer: https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory/
561-
* @return the result future
562-
*/
563-
default ActionFuture<CreateConversationResponse> createConversation(String name) {
564-
PlainActionFuture<CreateConversationResponse> actionFuture = PlainActionFuture.newFuture();
565-
createConversation(name, actionFuture);
566-
return actionFuture;
567-
}
568-
569-
/**
570-
* Create conversational memory for conversation
571-
* @param name name of the conversation, refer: https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory/
572-
* @param listener action listener
573-
*/
574-
void createConversation(String name, ActionListener<CreateConversationResponse> listener);
575556
}

client/src/main/java/org/opensearch/ml/client/MachineLearningNodeClient.java

-18
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@
8888
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsAction;
8989
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsRequest;
9090
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsResponse;
91-
import org.opensearch.ml.memory.action.conversation.CreateConversationAction;
92-
import org.opensearch.ml.memory.action.conversation.CreateConversationRequest;
93-
import org.opensearch.ml.memory.action.conversation.CreateConversationResponse;
9491
import org.opensearch.transport.client.Client;
9592

9693
import lombok.AccessLevel;
@@ -321,11 +318,6 @@ public void getConfig(String configId, String tenantId, ActionListener<MLConfig>
321318
client.execute(MLConfigGetAction.INSTANCE, mlConfigGetRequest, getMlGetConfigResponseActionListener(listener));
322319
}
323320

324-
public void createConversation(String name, ActionListener<CreateConversationResponse> listener) {
325-
CreateConversationRequest createConversationRequest = new CreateConversationRequest(name);
326-
client.execute(CreateConversationAction.INSTANCE, createConversationRequest, getCreateConversationResponseActionListener(listener));
327-
}
328-
329321
private ActionListener<MLToolsListResponse> getMlListToolsResponseActionListener(ActionListener<List<ToolMetadata>> listener) {
330322
ActionListener<MLToolsListResponse> internalListener = ActionListener.wrap(mlModelListResponse -> {
331323
listener.onResponse(mlModelListResponse.getToolMetadataList());
@@ -394,16 +386,6 @@ private ActionListener<MLRegisterModelResponse> getMLRegisterModelResponseAction
394386
return wrapActionListener(listener, MLRegisterModelResponse::fromActionResponse);
395387
}
396388

397-
private ActionListener<CreateConversationResponse> getCreateConversationResponseActionListener(
398-
ActionListener<CreateConversationResponse> listener
399-
) {
400-
ActionListener<CreateConversationResponse> actionListener = wrapActionListener(listener, response -> {
401-
CreateConversationResponse conversationResponse = CreateConversationResponse.fromActionResponse(response);
402-
return conversationResponse;
403-
});
404-
return actionListener;
405-
}
406-
407389
private <T extends ActionResponse> ActionListener<T> wrapActionListener(
408390
final ActionListener<T> listener,
409391
final Function<ActionResponse, T> recreate

client/src/test/java/org/opensearch/ml/client/MachineLearningClientTest.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.opensearch.ml.common.output.MLOutput;
5050
import org.opensearch.ml.common.output.MLTrainingOutput;
5151
import org.opensearch.ml.common.transport.agent.MLRegisterAgentResponse;
52+
import org.opensearch.ml.common.transport.config.MLConfigGetResponse;
5253
import org.opensearch.ml.common.transport.connector.MLCreateConnectorInput;
5354
import org.opensearch.ml.common.transport.connector.MLCreateConnectorResponse;
5455
import org.opensearch.ml.common.transport.deploy.MLDeployModelResponse;
@@ -58,7 +59,6 @@
5859
import org.opensearch.ml.common.transport.register.MLRegisterModelInput;
5960
import org.opensearch.ml.common.transport.register.MLRegisterModelResponse;
6061
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsResponse;
61-
import org.opensearch.ml.memory.action.conversation.CreateConversationResponse;
6262

6363
public class MachineLearningClientTest {
6464

@@ -107,7 +107,7 @@ public class MachineLearningClientTest {
107107
MLRegisterAgentResponse registerAgentResponse;
108108

109109
@Mock
110-
CreateConversationResponse createConversationResponse;
110+
MLConfigGetResponse configGetResponse;
111111

112112
private final String modekId = "test_model_id";
113113
private MLModel mlModel;
@@ -256,11 +256,6 @@ public void deleteAgent(String agentId, String tenantId, ActionListener<DeleteRe
256256
public void getConfig(String configId, String tenantId, ActionListener<MLConfig> listener) {
257257
listener.onResponse(mlConfig);
258258
}
259-
260-
@Override
261-
public void createConversation(String name, ActionListener<CreateConversationResponse> listener) {
262-
listener.onResponse(createConversationResponse);
263-
}
264259
};
265260
}
266261

@@ -559,9 +554,4 @@ public void listTools() {
559554
public void getConfig() {
560555
assertEquals(mlConfig, machineLearningClient.getConfig("configId").actionGet());
561556
}
562-
563-
@Test
564-
public void createConversation() {
565-
assertEquals(createConversationResponse, machineLearningClient.createConversation("Conversation for a RAG pipeline").actionGet());
566-
}
567557
}

client/src/test/java/org/opensearch/ml/client/MachineLearningNodeClientTest.java

-25
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@
140140
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsAction;
141141
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsRequest;
142142
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsResponse;
143-
import org.opensearch.ml.memory.action.conversation.CreateConversationAction;
144-
import org.opensearch.ml.memory.action.conversation.CreateConversationRequest;
145-
import org.opensearch.ml.memory.action.conversation.CreateConversationResponse;
146143
import org.opensearch.search.SearchHit;
147144
import org.opensearch.search.SearchHits;
148145
import org.opensearch.search.aggregations.InternalAggregations;
@@ -222,9 +219,6 @@ public class MachineLearningNodeClientTest {
222219
@Mock
223220
ActionListener<MLConfig> getMlConfigListener;
224221

225-
@Mock
226-
ActionListener<CreateConversationResponse> createConversationResponseActionListener;
227-
228222
@InjectMocks
229223
MachineLearningNodeClient machineLearningNodeClient;
230224

@@ -1461,25 +1455,6 @@ public void onFailure(Exception e) {
14611455
verify(client).execute(eq(MLTaskDeleteAction.INSTANCE), isA(MLTaskDeleteRequest.class), any());
14621456
}
14631457

1464-
public void createConversation() {
1465-
String name = "Conversation for a RAG pipeline";
1466-
String conversationId = "conversationId";
1467-
1468-
doAnswer(invocation -> {
1469-
ActionListener<CreateConversationResponse> actionListener = invocation.getArgument(2);
1470-
CreateConversationResponse output = new CreateConversationResponse(conversationId);
1471-
actionListener.onResponse(output);
1472-
return null;
1473-
}).when(client).execute(eq(CreateConversationAction.INSTANCE), any(), any());
1474-
1475-
ArgumentCaptor<CreateConversationResponse> argumentCaptor = ArgumentCaptor.forClass(CreateConversationResponse.class);
1476-
machineLearningNodeClient.createConversation(name, createConversationResponseActionListener);
1477-
1478-
verify(client).execute(eq(CreateConversationAction.INSTANCE), isA(CreateConversationRequest.class), any());
1479-
verify(createConversationResponseActionListener).onResponse(argumentCaptor.capture());
1480-
assertEquals(conversationId, argumentCaptor.getValue().getId());
1481-
}
1482-
14831458
private SearchResponse createSearchResponse(ToXContentObject o) throws IOException {
14841459
XContentBuilder content = o.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS);
14851460

memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponse.java

-22
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20-
import java.io.ByteArrayInputStream;
21-
import java.io.ByteArrayOutputStream;
2220
import java.io.IOException;
23-
import java.io.UncheckedIOException;
2421

2522
import org.opensearch.core.action.ActionResponse;
26-
import org.opensearch.core.common.io.stream.InputStreamStreamInput;
27-
import org.opensearch.core.common.io.stream.OutputStreamStreamOutput;
2823
import org.opensearch.core.common.io.stream.StreamInput;
2924
import org.opensearch.core.common.io.stream.StreamOutput;
3025
import org.opensearch.core.xcontent.ToXContent;
3126
import org.opensearch.core.xcontent.ToXContentObject;
3227
import org.opensearch.core.xcontent.XContentBuilder;
3328
import org.opensearch.ml.common.conversation.ActionConstants;
34-
import org.opensearch.ml.common.transport.connector.MLCreateConnectorResponse;
3529

3630
import lombok.AllArgsConstructor;
3731

@@ -73,20 +67,4 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
7367
return builder;
7468
}
7569

76-
public static CreateConversationResponse fromActionResponse(ActionResponse actionResponse) {
77-
if (actionResponse instanceof MLCreateConnectorResponse) {
78-
return (CreateConversationResponse) actionResponse;
79-
}
80-
81-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) {
82-
actionResponse.writeTo(osso);
83-
try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) {
84-
return new CreateConversationResponse(input);
85-
}
86-
} catch (IOException e) {
87-
throw new UncheckedIOException("failed to parse ActionResponse into CreateConversationResponse", e);
88-
}
89-
90-
}
91-
9270
}

memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponseTests.java

-43
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20-
import static org.junit.Assert.assertEquals;
21-
2220
import java.io.IOException;
23-
import java.io.UncheckedIOException;
2421

25-
import org.junit.Before;
26-
import org.junit.Test;
2722
import org.opensearch.common.io.stream.BytesStreamOutput;
2823
import org.opensearch.common.xcontent.XContentType;
29-
import org.opensearch.core.action.ActionResponse;
3024
import org.opensearch.core.common.bytes.BytesReference;
3125
import org.opensearch.core.common.io.stream.BytesStreamInput;
3226
import org.opensearch.core.common.io.stream.OutputStreamStreamOutput;
@@ -38,13 +32,6 @@
3832

3933
public class CreateConversationResponseTests extends OpenSearchTestCase {
4034

41-
CreateConversationResponse response;
42-
43-
@Before
44-
public void setup() {
45-
response = new CreateConversationResponse("test-id");
46-
}
47-
4835
public void testCreateConversationResponseStreaming() throws IOException {
4936
CreateConversationResponse response = new CreateConversationResponse("test-id");
5037
assert (response.getId().equals("test-id"));
@@ -64,34 +51,4 @@ public void testToXContent() throws IOException {
6451
String result = BytesReference.bytes(builder).utf8ToString();
6552
assert (result.equals(expected));
6653
}
67-
68-
@Test
69-
public void fromActionResponseWithCreateConversationResponseSuccess() {
70-
CreateConversationResponse responseFromActionResponse = CreateConversationResponse.fromActionResponse(response);
71-
assertEquals(response.getId(), responseFromActionResponse.getId());
72-
}
73-
74-
@Test
75-
public void fromActionResponseSuccess() {
76-
ActionResponse actionResponse = new ActionResponse() {
77-
@Override
78-
public void writeTo(StreamOutput out) throws IOException {
79-
response.writeTo(out);
80-
}
81-
};
82-
CreateConversationResponse responseFromActionResponse = CreateConversationResponse.fromActionResponse(actionResponse);
83-
assertNotSame(response, responseFromActionResponse);
84-
assertEquals(response.getId(), responseFromActionResponse.getId());
85-
}
86-
87-
@Test(expected = UncheckedIOException.class)
88-
public void fromActionResponseIOException() {
89-
ActionResponse actionResponse = new ActionResponse() {
90-
@Override
91-
public void writeTo(StreamOutput out) throws IOException {
92-
throw new IOException();
93-
}
94-
};
95-
CreateConversationResponse.fromActionResponse(actionResponse);
96-
}
9754
}

0 commit comments

Comments
 (0)