forked from opensearch-project/ml-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: HenryL27 <[email protected]>
- Loading branch information
Showing
36 changed files
with
763 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
28 changes: 28 additions & 0 deletions
28
...rc/test/java/org/opensearch/ml/conversational/action/memory/conversation/ActionTests.java
This file contains 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,28 @@ | ||
/* | ||
* Copyright 2023 Aryn | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.opensearch.ml.conversational.action.memory.conversation; | ||
|
||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class ActionTests extends OpenSearchTestCase { | ||
public void testActions() { | ||
assert(CreateConversationAction.INSTANCE instanceof CreateConversationAction); | ||
assert(DeleteConversationAction.INSTANCE instanceof DeleteConversationAction); | ||
assert(GetConversationsAction.INSTANCE instanceof GetConversationsAction); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...nsearch/ml/conversational/action/memory/conversation/CreateConversationResponseTests.java
This file contains 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,54 @@ | ||
/* | ||
* Copyright 2023 Aryn | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.opensearch.ml.conversational.action.memory.conversation; | ||
|
||
import java.io.IOException; | ||
|
||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.common.xcontent.XContentType; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
import org.opensearch.core.common.io.stream.BytesStreamInput; | ||
import org.opensearch.core.common.io.stream.OutputStreamStreamOutput; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class CreateConversationResponseTests extends OpenSearchTestCase { | ||
|
||
public void testCreateConversationResponseStreaming() throws IOException { | ||
CreateConversationResponse response = new CreateConversationResponse("test-id"); | ||
assert(response.getId().equals("test-id")); | ||
BytesStreamOutput outbytes = new BytesStreamOutput(); | ||
StreamOutput osso = new OutputStreamStreamOutput(outbytes); | ||
response.writeTo(osso); | ||
StreamInput in = new BytesStreamInput(BytesReference.toBytes(outbytes.bytes())); | ||
CreateConversationResponse newResp = new CreateConversationResponse(in); | ||
assert(newResp.getId().equals("test-id")); | ||
} | ||
|
||
public void testToXContent() throws IOException { | ||
CreateConversationResponse response = new CreateConversationResponse("createme"); | ||
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent()); | ||
String expected = "{\"conversationId\":\"createme\"}"; | ||
response.toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
String result = BytesReference.bytes(builder).utf8ToString(); | ||
assert(result.equals(expected)); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...earch/ml/conversational/action/memory/conversation/CreateConversationRestActionTests.java
This file contains 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,62 @@ | ||
/* | ||
* Copyright 2023 Aryn | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.opensearch.ml.conversational.action.memory.conversation; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.mockito.ArgumentCaptor; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.ml.common.conversational.ActionConstants; | ||
import org.opensearch.rest.RestHandler.Route; | ||
import org.opensearch.rest.RestChannel; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.test.rest.FakeRestRequest; | ||
|
||
public class CreateConversationRestActionTests extends OpenSearchTestCase { | ||
public void testBasics() { | ||
CreateConversationRestAction action = new CreateConversationRestAction(); | ||
assert(action.getName().equals("conversational_create_conversation")); | ||
List<Route> routes = action.routes(); | ||
assert(routes.size() == 1); | ||
assert(routes.get(0).equals(new Route(RestRequest.Method.POST, ActionConstants.CREATE_CONVERSATION_PATH))); | ||
} | ||
|
||
public void testPrepareRequest() throws Exception { | ||
CreateConversationRestAction action = new CreateConversationRestAction(); | ||
RestRequest request = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) | ||
.withParams(Map.of(ActionConstants.REQUEST_CONVERSATION_NAME_FIELD, "test-name")) | ||
.build(); | ||
|
||
NodeClient client = mock(NodeClient.class); | ||
RestChannel channel = mock(RestChannel.class); | ||
action.handleRequest(request, channel, client); | ||
|
||
ArgumentCaptor<CreateConversationRequest> argumentCaptor = ArgumentCaptor.forClass(CreateConversationRequest.class); | ||
verify(client, times(1)).execute(eq(CreateConversationAction.INSTANCE), argumentCaptor.capture(), any()); | ||
assert(argumentCaptor.getValue().getName().equals("test-name")); | ||
} | ||
} |
Oops, something went wrong.