Skip to content

Commit

Permalink
refactor memory logs
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt committed Feb 16, 2024
1 parent 2c23a4c commit 8489eb2
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void doExecute(Task task, CreateConversationRequest request, ActionLis
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
ActionListener<CreateConversationResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
ActionListener<String> al = ActionListener.wrap(r -> { internalListener.onResponse(new CreateConversationResponse(r)); }, e -> {
log.error("Failed to create new conversation with name " + request.getName(), e);
log.error("Failed to create new memory with name " + request.getName(), e);
internalListener.onFailure(e);
});

Expand All @@ -96,7 +96,7 @@ protected void doExecute(Task task, CreateConversationRequest request, ActionLis
cmHandler.createConversation(name, applicationType, al);
}
} catch (Exception e) {
log.error("Failed to create new conversation with name " + request.getName(), e);
log.error("Failed to create new memory with name " + request.getName(), e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ protected void doExecute(Task task, CreateInteractionRequest request, ActionList
ActionListener<CreateInteractionResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
ActionListener<String> al = ActionListener.wrap(iid -> {
cmHandler.updateConversation(cid, new HashMap<>(), getUpdateResponseListener(cid, iid, internalListener));
log.info("Updating the memory {} after the message {} is created", cid, iid);
}, e -> { internalListener.onFailure(e); });
if (parintIid == null || traceNumber == null) {
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al);
} else {
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al, parintIid, traceNumber);
}
} catch (Exception e) {
log.error("Failed to create interaction for conversation " + cid, e);
log.error("Failed to create message for memory " + cid, e);
actionListener.onFailure(e);
}
}
Expand All @@ -117,21 +118,16 @@ private ActionListener<UpdateResponse> getUpdateResponseListener(
) {
return ActionListener.wrap(updateResponse -> {
if (updateResponse != null && updateResponse.getResult() == DocWriteResponse.Result.UPDATED) {
log
.debug(
"Successfully updated the Conversation with ID: {} after interaction {} is created",
conversationId,
interactionId
);
log.debug("Successfully updated the memory with ID: {} after message {} is created", conversationId, interactionId);
actionListener.onResponse(new CreateInteractionResponse(interactionId));
} else {
log.error("Failed to update the Conversation with ID: {} after interaction {} is created", conversationId, interactionId);
log.error("Failed to update the memory with ID: {} after message {} is created", conversationId, interactionId);
actionListener.onResponse(new CreateInteractionResponse(interactionId));
}
}, exception -> {
log
.error(
"Failed to update Conversation with ID {} after interaction {} is created. Details: {}",
"Failed to update memory with ID {} after message {} is created. Details: {}",
conversationId,
interactionId,
exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void doExecute(Task task, DeleteConversationRequest request, ActionListen
}, e -> { internalListener.onFailure(e); });
cmHandler.deleteConversation(conversationId, al);
} catch (Exception e) {
log.error("Failed to delete conversation " + conversationId, e);
log.error("Failed to delete memory " + conversationId, e);
listener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void doExecute(Task task, GetConversationRequest request, ActionListener<
}, e -> { internalListener.onFailure(e); });
cmHandler.getConversation(conversationId, al);
} catch (Exception e) {
log.error("Failed to get Conversation " + conversationId, e);
log.error("Failed to get memory " + conversationId, e);
actionListener.onFailure(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public void doExecute(Task task, GetConversationsRequest request, ActionListener
internalListener
.onResponse(new GetConversationsResponse(conversations, from + maxResults, conversations.size() == maxResults));
}, e -> {
log.error("Failed to get conversations", e);
log.error("Failed to get memories", e);
internalListener.onFailure(e);
});
cmHandler.getConversations(from, maxResults, al);
} catch (Exception e) {
log.error("Failed to get conversations", e);
log.error("Failed to get memories", e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void doExecute(Task task, GetInteractionRequest request, ActionListener<G
}, e -> { internalListener.onFailure(e); });
cmHandler.getInteraction(interactionId, al);
} catch (Exception e) {
log.error("Failed to get interaction " + interactionId, e);
log.error("Failed to get message " + interactionId, e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void doExecute(Task task, GetInteractionsRequest request, ActionListener<
}, e -> { internalListener.onFailure(e); });
cmHandler.getInteractions(request.getConversationId(), from, maxResults, al);
} catch (Exception e) {
log.error("Failed to get interactions for conversation " + request.getConversationId(), e);
log.error("Failed to get messages for memory " + request.getConversationId(), e);
actionListener.onFailure(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void doExecute(Task task, GetTracesRequest request, ActionListener<GetTra
}, e -> { internalListener.onFailure(e); });
cmHandler.getTraces(request.getInteractionId(), from, maxResults, al);
} catch (Exception e) {
log.error("Failed to get traces for conversation " + request.getInteractionId(), e);
log.error("Failed to get traces for message " + request.getInteractionId(), e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void doExecute(Task task, SearchRequest request, ActionListener<SearchRes
ActionListener<SearchResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
cmHandler.searchConversations(request, internalListener);
} catch (Exception e) {
log.error("Failed to search conversations", e);
log.error("Failed to search memories", e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void doExecute(Task task, SearchInteractionsRequest request, ActionListen
ActionListener<SearchResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
cmHandler.searchInteractions(request.getConversationId(), request, internalListener);
} catch (Exception e) {
log.error("Failed to search conversations", e);
log.error("Failed to search memories", e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Update

cmHandler.updateConversation(conversationId, updateContent, getUpdateResponseListener(conversationId, listener, context));
} catch (Exception e) {
log.error("Failed to update Conversation " + conversationId, e);
log.error("Failed to update Memory " + conversationId, e);
listener.onFailure(e);
}
}
Expand All @@ -84,14 +84,14 @@ private ActionListener<UpdateResponse> getUpdateResponseListener(
) {
return ActionListener.runBefore(ActionListener.wrap(updateResponse -> {
if (updateResponse != null && updateResponse.getResult() == DocWriteResponse.Result.UPDATED) {
log.info("Successfully updated the Conversation with ID: {}", conversationId);
log.info("Successfully updated the Memory with ID: {}", conversationId);
actionListener.onResponse(updateResponse);
} else {
log.info("Failed to update the Conversation with ID: {}", conversationId);
log.info("Failed to update the Memory with ID: {}", conversationId);
actionListener.onResponse(updateResponse);
}
}, exception -> {
log.error("Failed to update ML Conversation with ID " + conversationId, exception);
log.error("Failed to update ML Memory with ID " + conversationId, exception);
actionListener.onFailure(exception);
}), context::restore);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Update

cmHandler.updateInteraction(interactionId, updateContent, getUpdateResponseListener(interactionId, listener, context));
} catch (Exception e) {
log.error("Failed to update Interaction " + interactionId, e);
log.error("Failed to update Message " + interactionId, e);
listener.onFailure(e);
}
}
Expand All @@ -81,14 +81,14 @@ private ActionListener<UpdateResponse> getUpdateResponseListener(
) {
return ActionListener.runBefore(ActionListener.wrap(updateResponse -> {
if (updateResponse != null && updateResponse.getResult() == DocWriteResponse.Result.UPDATED) {
log.info("Successfully updated the interaction with ID: {}", interactionId);
log.info("Successfully updated the Message with ID: {}", interactionId);
actionListener.onResponse(updateResponse);
} else {
log.info("Failed to update the interaction with ID: {}", interactionId);
log.info("Failed to update the Message with ID: {}", interactionId);
actionListener.onResponse(updateResponse);
}
}, exception -> {
log.error("Failed to update ML interaction with ID " + interactionId, exception);
log.error("Failed to update ML Message with ID " + interactionId, exception);
actionListener.onFailure(exception);
}), context::restore);
}
Expand Down
Loading

0 comments on commit 8489eb2

Please sign in to comment.