Skip to content

Commit

Permalink
propagate name change to variables and parameters
Browse files Browse the repository at this point in the history
Signed-off-by: HenryL27 <[email protected]>
  • Loading branch information
HenryL27 committed Aug 30, 2023
1 parent 4aaf8f1 commit f0b4d55
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ActionConstants {
/** name of prompt template field in all requests */
public final static String PROMPT_TEMPLATE_FIELD = "prompt_template";
/** name of metadata field in all requests */
public final static String METADATA_FIELD = "additional_info";
public final static String ADDITIONAL_INFO_FIELD = "additional_info";
/** name of success field in all requests */
public final static String SUCCESS_FIELD = "success";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public class ConversationalIndexConstants {
/** Name of the interaction field for the response's origin */
public final static String INTERACTIONS_ORIGIN_FIELD = "origin";
/** Name of the interaction field for additional metadata */
public final static String INTERACTIONS_METADATA_FIELD = "additional_info";
public final static String INTERACTIONS_ADDITIONAL_INFO_FIELD = "additional_info";
/** Name of the interaction field for the timestamp */
public final static String INTERACTIONS_TIMESTAMP_FIELD = "create_time";
public final static String INTERACTIONS_CREATE_TIME_FIELD = "create_time";
/** Mappings for the interactions index */
public final static String INTERACTIONS_MAPPINGS = "{\n"
+ " \"_meta\": {\n"
Expand All @@ -77,7 +77,7 @@ public class ConversationalIndexConstants {
+ INTERACTIONS_CONVERSATION_ID_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ INTERACTIONS_TIMESTAMP_FIELD
+ INTERACTIONS_CREATE_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ INTERACTIONS_INPUT_FIELD
Expand All @@ -92,7 +92,7 @@ public class ConversationalIndexConstants {
+ INTERACTIONS_ORIGIN_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ INTERACTIONS_METADATA_FIELD
+ INTERACTIONS_ADDITIONAL_INFO_FIELD
+ "\": {\"type\": \"text\"}\n"
+ " }\n"
+ "}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Interaction implements Writeable, ToXContentObject {
@Getter
private String id;
@Getter
private Instant timestamp;
private Instant createTime;
@Getter
private String conversationId;
@Getter
Expand All @@ -54,7 +54,7 @@ public class Interaction implements Writeable, ToXContentObject {
@Getter
private String origin;
@Getter
private String metadata;
private String additionalInfo;

/**
* Creates an Interaction object from a map of fields in the OS index
Expand All @@ -63,14 +63,14 @@ public class Interaction implements Writeable, ToXContentObject {
* @return a new Interaction object representing the OS document
*/
public static Interaction fromMap(String id, Map<String, Object> fields) {
Instant timestamp = Instant.parse((String) fields.get(ConversationalIndexConstants.INTERACTIONS_TIMESTAMP_FIELD));
Instant createTime = Instant.parse((String) fields.get(ConversationalIndexConstants.INTERACTIONS_CREATE_TIME_FIELD));
String conversationId = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_CONVERSATION_ID_FIELD);
String input = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_INPUT_FIELD);
String promptTemplate = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_PROMPT_TEMPLATE_FIELD);
String response = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_RESPONSE_FIELD);
String origin = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_ORIGIN_FIELD);
String metadata = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_METADATA_FIELD);
return new Interaction(id, timestamp, conversationId, input, promptTemplate, response, origin, metadata);
String additionalInfo = (String) fields.get(ConversationalIndexConstants.INTERACTIONS_ADDITIONAL_INFO_FIELD);
return new Interaction(id, createTime, conversationId, input, promptTemplate, response, origin, additionalInfo);
}

/**
Expand All @@ -91,41 +91,41 @@ public static Interaction fromSearchHit(SearchHit hit) {
*/
public static Interaction fromStream(StreamInput in) throws IOException {
String id = in.readString();
Instant timestamp = in.readInstant();
Instant createTime = in.readInstant();
String conversationId = in.readString();
String input = in.readString();
String promptTemplate = in.readString();
String response = in.readString();
String origin = in.readString();
String metadata = in.readOptionalString();
return new Interaction(id, timestamp, conversationId, input, promptTemplate, response, origin, metadata);
String additionalInfo = in.readOptionalString();
return new Interaction(id, createTime, conversationId, input, promptTemplate, response, origin, additionalInfo);
}


@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
out.writeInstant(timestamp);
out.writeInstant(createTime);
out.writeString(conversationId);
out.writeString(input);
out.writeString(promptTemplate);
out.writeString(response);
out.writeString(origin);
out.writeOptionalString(metadata);
out.writeOptionalString(additionalInfo);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContentObject.Params params) throws IOException {
builder.startObject();
builder.field(ActionConstants.CONVERSATION_ID_FIELD, conversationId);
builder.field(ActionConstants.RESPONSE_INTERACTION_ID_FIELD, id);
builder.field(ConversationalIndexConstants.INTERACTIONS_TIMESTAMP_FIELD, timestamp);
builder.field(ConversationalIndexConstants.INTERACTIONS_CREATE_TIME_FIELD, createTime);
builder.field(ConversationalIndexConstants.INTERACTIONS_INPUT_FIELD, input);
builder.field(ConversationalIndexConstants.INTERACTIONS_PROMPT_TEMPLATE_FIELD, promptTemplate);
builder.field(ConversationalIndexConstants.INTERACTIONS_RESPONSE_FIELD, response);
builder.field(ConversationalIndexConstants.INTERACTIONS_ORIGIN_FIELD, origin);
if(metadata != null) {
builder.field(ConversationalIndexConstants.INTERACTIONS_METADATA_FIELD, metadata);
if(additionalInfo != null) {
builder.field(ConversationalIndexConstants.INTERACTIONS_ADDITIONAL_INFO_FIELD, additionalInfo);
}
builder.endObject();
return builder;
Expand All @@ -137,13 +137,13 @@ public boolean equals(Object other) {
other instanceof Interaction &&
((Interaction) other).id.equals(this.id) &&
((Interaction) other).conversationId.equals(this.conversationId) &&
((Interaction) other).timestamp.equals(this.timestamp) &&
((Interaction) other).createTime.equals(this.createTime) &&
((Interaction) other).input.equals(this.input) &&
((Interaction) other).promptTemplate.equals(this.promptTemplate) &&
((Interaction) other).response.equals(this.response) &&
((Interaction) other).origin.equals(this.origin) &&
( (((Interaction) other).metadata == null && this.metadata == null) ||
((Interaction) other).metadata.equals(this.metadata))
( (((Interaction) other).additionalInfo == null && this.additionalInfo == null) ||
((Interaction) other).additionalInfo.equals(this.additionalInfo))
);
}

Expand All @@ -152,12 +152,12 @@ public String toString() {
return "Interaction{"
+ "id=" + id
+ ",cid=" + conversationId
+ ",timestamp=" + timestamp
+ ",create_time=" + createTime
+ ",origin=" + origin
+ ",input=" + input
+ ",promt_template=" + promptTemplate
+ ",response=" + response
+ ",metadata=" + metadata
+ ",additional_info=" + additionalInfo
+ "}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface ConversationalMemoryHandler {
* @param promptTemplate the prompt template used for this interaction
* @param response the Gen AI response for this interaction
* @param origin the name of the GenAI agent in this interaction
* @param metadata additional inofrmation used in constructing the LLM prompt
* @param additionalInfo additional inofrmation used in constructing the LLM prompt
* @param listener gets the ID of the new interaction
*/
public void createInteraction(
Expand All @@ -72,7 +72,7 @@ public void createInteraction(
String promptTemplate,
String response,
String origin,
String metadata,
String additionalInfo,
ActionListener<String> listener
);

Expand All @@ -83,15 +83,15 @@ public void createInteraction(
* @param promptTemplate the prompt template used in this interaction
* @param response the Gen AI response for this interaction
* @param origin the name of the GenAI agent in this interaction
* @param metadata arbitrary JSON string of extra stuff
* @param additionalInfo additional inofrmation used in constructing the LLM prompt
* @return ActionFuture for the interactionId of the new interaction
*/
public ActionFuture<String> createInteraction(
String conversationId,
String input,
String promptTemplate,
String response,
String origin,
String additionalInfo,
String metadata
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CreateInteractionRequest extends ActionRequest {
@Getter
private String origin;
@Getter
private String metadata;
private String additionalInfo;

/**
* Constructor
Expand All @@ -62,7 +62,7 @@ public CreateInteractionRequest(StreamInput in) throws IOException {
this.promptTemplate = in.readString();
this.response = in.readString();
this.origin = in.readOptionalString();
this.metadata = in.readOptionalString();
this.additionalInfo = in.readOptionalString();
}

@Override
Expand All @@ -73,7 +73,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(promptTemplate);
out.writeString(response);
out.writeOptionalString(origin);
out.writeOptionalString(metadata);
out.writeOptionalString(additionalInfo);
}

@Override
Expand All @@ -98,8 +98,8 @@ public static CreateInteractionRequest fromRestRequest(RestRequest request) thro
String prmpt = body.get(ActionConstants.PROMPT_TEMPLATE_FIELD);
String rsp = body.get(ActionConstants.AI_RESPONSE_FIELD);
String ogn = body.get(ActionConstants.RESPONSE_ORIGIN_FIELD);
String metadata = body.get(ActionConstants.METADATA_FIELD);
return new CreateInteractionRequest(cid, inp, prmpt, rsp, ogn, metadata);
String addinf = body.get(ActionConstants.ADDITIONAL_INFO_FIELD);
return new CreateInteractionRequest(cid, inp, prmpt, rsp, ogn, addinf);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ protected void doExecute(Task task, CreateInteractionRequest request, ActionList
String rsp = request.getResponse();
String ogn = request.getOrigin();
String prompt = request.getPromptTemplate();
String metadata = request.getMetadata();
String additionalInfo = request.getAdditionalInfo();
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
ActionListener<CreateInteractionResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
ActionListener<String> al = ActionListener
.wrap(iid -> { internalListener.onResponse(new CreateInteractionResponse(iid)); }, e -> {
internalListener.onFailure(e);
});
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, metadata, al);
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al);
} catch (Exception e) {
log.error(e.toString());
actionListener.onFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public void createInteraction(
promptTemplate,
ConversationalIndexConstants.INTERACTIONS_RESPONSE_FIELD,
response,
ConversationalIndexConstants.INTERACTIONS_METADATA_FIELD,
ConversationalIndexConstants.INTERACTIONS_ADDITIONAL_INFO_FIELD,
metadata,
ConversationalIndexConstants.INTERACTIONS_TIMESTAMP_FIELD,
ConversationalIndexConstants.INTERACTIONS_CREATE_TIME_FIELD,
timestamp
);
try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().newStoredContext(true)) {
Expand Down Expand Up @@ -236,7 +236,7 @@ void innerGetInteractions(String conversationId, int from, int maxResults, Actio
TermQueryBuilder builder = new TermQueryBuilder(ConversationalIndexConstants.INTERACTIONS_CONVERSATION_ID_FIELD, conversationId);
request.source().query(builder);
request.source().from(from).size(maxResults);
request.source().sort(ConversationalIndexConstants.INTERACTIONS_TIMESTAMP_FIELD, SortOrder.DESC);
request.source().sort(ConversationalIndexConstants.INTERACTIONS_CREATE_TIME_FIELD, SortOrder.DESC);
try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) {
ActionListener<List<Interaction>> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore());
ActionListener<SearchResponse> al = ActionListener.wrap(response -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public ActionFuture<String> createConversation(String name) {
* @param promptTemplate the prompt template used for this interaction
* @param response the Gen AI response for this interaction
* @param origin the name of the GenAI agent in this interaction
* @param metadata additional inofrmation used in constructing the LLM prompt
* @param additionalInfo additional inofrmation used in constructing the LLM prompt
* @param listener gets the ID of the new interaction
*/
public void createInteraction(
Expand All @@ -111,11 +111,11 @@ public void createInteraction(
String promptTemplate,
String response,
String origin,
String metadata,
String additionalInfo,
ActionListener<String> listener
) {
Instant time = Instant.now();
interactionsIndex.createInteraction(conversationId, input, promptTemplate, response, origin, metadata, time, listener);
interactionsIndex.createInteraction(conversationId, input, promptTemplate, response, origin, additionalInfo, time, listener);
}

/**
Expand All @@ -125,7 +125,7 @@ public void createInteraction(
* @param promptTemplate the prompt template used in this interaction
* @param response the Gen AI response for this interaction
* @param origin the name of the GenAI agent in this interaction
* @param metadata arbitrary JSON string of extra stuff
* @param additionalInfo additional inofrmation used in constructing the LLM prompt
* @return ActionFuture for the interactionId of the new interaction
*/
public ActionFuture<String> createInteraction(
Expand All @@ -134,10 +134,10 @@ public ActionFuture<String> createInteraction(
String promptTemplate,
String response,
String origin,
String metadata
String additionalInfo
) {
PlainActionFuture<String> fut = PlainActionFuture.newFuture();
createInteraction(conversationId, input, promptTemplate, response, origin, metadata, fut);
createInteraction(conversationId, input, promptTemplate, response, origin, additionalInfo, fut);
return fut;
}

Expand All @@ -147,7 +147,7 @@ public ActionFuture<String> createInteraction(
* @param listener gets the interactionId of the newly created interaction
*/
public void createInteraction(InteractionBuilder builder, ActionListener<String> listener) {
builder.timestamp(Instant.now());
builder.createTime(Instant.now());
Interaction interaction = builder.build();
interactionsIndex
.createInteraction(
Expand All @@ -156,8 +156,8 @@ public void createInteraction(InteractionBuilder builder, ActionListener<String>
interaction.getPromptTemplate(),
interaction.getResponse(),
interaction.getOrigin(),
interaction.getMetadata(),
interaction.getTimestamp(),
interaction.getAdditionalInfo(),
interaction.getCreateTime(),
listener
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testFromRestRequest() throws IOException {
"response",
ActionConstants.RESPONSE_ORIGIN_FIELD,
"origin",
ActionConstants.METADATA_FIELD,
ActionConstants.ADDITIONAL_INFO_FIELD,
"metadata"
);
RestRequest rrequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY)
Expand All @@ -98,6 +98,6 @@ public void testFromRestRequest() throws IOException {
assert (request.getPromptTemplate().equals("pt"));
assert (request.getResponse().equals("response"));
assert (request.getOrigin().equals("origin"));
assert (request.getMetadata().equals("metadata"));
assert (request.getAdditionalInfo().equals("metadata"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testToXContent_MoreTokens() throws IOException {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
String result = BytesReference.bytes(builder).utf8ToString();
String expected = "{\"interactions\":[{\"conversation_id\":\"cid\",\"interaction_id\":\"id0\",\"create_time\":\""
+ interaction.getTimestamp()
+ interaction.getCreateTime()
+ "\",\"input\":\"input\",\"prompt_template\":\"pt\",\"response\":\"response\",\"origin\":\"origin\",\"additional_info\":\"metadata\"}],\"next_token\":2}";
log.info(result);
log.info(expected);
Expand All @@ -90,7 +90,7 @@ public void testToXContent_NoMoreTokens() throws IOException {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
String result = BytesReference.bytes(builder).utf8ToString();
String expected = "{\"interactions\":[{\"conversation_id\":\"cid\",\"interaction_id\":\"id0\",\"create_time\":\""
+ interaction.getTimestamp()
+ interaction.getCreateTime()
+ "\",\"input\":\"input\",\"prompt_template\":\"pt\",\"response\":\"response\",\"origin\":\"origin\",\"additional_info\":\"metadata\"}]}";
log.info(result);
log.info(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testCreateInteraction_FromBuilder_Success() {
.origin("origin")
.response("rsp")
.promptTemplate("pt")
.metadata("meta");
.additionalInfo("meta");
@SuppressWarnings("unchecked")
ActionListener<String> createInteractionListener = mock(ActionListener.class);
cmHandler.createInteraction(builder, createInteractionListener);
Expand All @@ -125,7 +125,7 @@ public void testCreateInteraction_FromBuilder_Future() {
.input("inp")
.response("rsp")
.promptTemplate("pt")
.metadata("meta");
.additionalInfo("meta");
ActionFuture<String> result = cmHandler.createInteraction(builder);
assert (result.actionGet(200).equals("iid"));
}
Expand Down
Loading

0 comments on commit f0b4d55

Please sign in to comment.