-
Notifications
You must be signed in to change notification settings - Fork 147
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
Added Conversation API in MLClient #2211
Changes from all commits
9a7075d
309617f
0b1a6e4
f762a75
8ef2686
b16b06e
499f6c4
ab1e054
1e74bab
03d19b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import org.opensearch.ml.common.transport.register.MLRegisterModelInput; | ||
import org.opensearch.ml.common.transport.register.MLRegisterModelResponse; | ||
import org.opensearch.ml.common.transport.undeploy.MLUndeployModelsResponse; | ||
import org.opensearch.ml.memory.action.conversation.CreateConversationResponse; | ||
|
||
/** | ||
* A client to provide interfaces for machine learning jobs. This will be used by other plugins. | ||
|
@@ -428,4 +429,22 @@ default ActionFuture<ToolMetadata> getTool(String toolName) { | |
*/ | ||
void getTool(String toolName, ActionListener<ToolMetadata> listener); | ||
|
||
/** | ||
* Create conversational memory for conversation | ||
* @param name name of the conversation, refer: https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory/ | ||
* @return the result future | ||
*/ | ||
default ActionFuture<CreateConversationResponse> createConversation(String name) { | ||
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. I don't think we should add this API. We should create a new conversation automatically when conversation id not set. 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. Oh okay @ylwu-amzn so if we want users to be able to do one click creation for conversation use case with some defaults for demo/poc purpose, we can just skip this step and not give rag processor the conversation ID? 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. I think you do want the ability to give conversations human-readable names. cc: @HenryL27 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. The main reason I am currently adding this is so we can have default use cases ready to go for conversational search opensearch-project/flow-framework#588 We want to be able to do something like setting up the whole e2e with just:
all fields can be overriden but at least for easy poc/dev I thought it would be useful, If we have some nice human-readable name in the processor for memory will it even be seen. I was thinking this part creates the memory id to give here, not conversation ID:
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.
memory=conversation. message=interaction. Sorry about the confusion here... we probably need to rename the internal classes to match the API names. 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. Yes, we need to follow the new names. Use Memory to replace Conversation, and Message to replace Interaction. Can you update based on the API name in the doc https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory? |
||
PlainActionFuture<CreateConversationResponse> actionFuture = PlainActionFuture.newFuture(); | ||
createConversation(name, actionFuture); | ||
return actionFuture; | ||
} | ||
|
||
/** | ||
* Create conversational memory for conversation | ||
* @param name name of the conversation, refer: https://opensearch.org/docs/latest/ml-commons-plugin/api/memory-apis/create-memory/ | ||
* @param listener action listener | ||
*/ | ||
void createConversation(String name, ActionListener<CreateConversationResponse> listener); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,21 @@ | |
*/ | ||
package org.opensearch.ml.memory.action.conversation; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.InputStreamStreamInput; | ||
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.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.ml.common.conversation.ActionConstants; | ||
import org.opensearch.ml.common.transport.connector.MLCreateConnectorResponse; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
|
@@ -67,4 +73,20 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par | |
return builder; | ||
} | ||
|
||
public static CreateConversationResponse fromActionResponse(ActionResponse actionResponse) { | ||
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. Let's add a test. |
||
if (actionResponse instanceof MLCreateConnectorResponse) { | ||
return (CreateConversationResponse) actionResponse; | ||
} | ||
|
||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) { | ||
actionResponse.writeTo(osso); | ||
try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) { | ||
return new CreateConversationResponse(input); | ||
} | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("failed to parse ActionResponse into CreateConversationResponse", e); | ||
} | ||
|
||
} | ||
|
||
} |
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.
Just curious to know if we should mark this as
shadow
?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.
Memory package doesn't have a publishing task that's why @jngz-es suggested to keep it like this.