Skip to content

Commit

Permalink
additional info cannot be null and update getTraces
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt committed Nov 15, 2023
1 parent 13b50ea commit 6fba0d8
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.search.sort.SortOrder;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;

/**
* Memory manager for Memories. It contains ML memory related operations like create, read interactions etc.
*/
@Log4j2
@AllArgsConstructor
public class MLMemoryManager {
public static final int DEFAULT_TIMEOUT_IN_MILLIS = 5000;

private Client client;
private ClusterService clusterService;
Expand Down Expand Up @@ -99,6 +97,8 @@ public void createInteraction(
Preconditions.checkNotNull(conversationId);
Preconditions.checkNotNull(input);
Preconditions.checkNotNull(response);
// additionalInfo cannot be null as flat object
additionalInfo = (additionalInfo == null)? new HashMap<>():additionalInfo;
try {
client.execute(
CreateInteractionAction.INSTANCE,
Expand Down Expand Up @@ -138,6 +138,8 @@ public void getFinalInteractions(String conversationId, int lastNInteraction, Ac
}
}, e -> { actionListener.onFailure(e); });
conversationMetaIndex.checkAccess(conversationId, accessListener);
} catch (Exception e) {
actionListener.onFailure(e);
}
}

Expand Down Expand Up @@ -195,19 +197,9 @@ public void getTraces(String parentInteractionId, ActionListener<List<Interactio
actionListener.onResponse(List.of());
return;
}
ActionListener<Boolean> accessListener = ActionListener.wrap(access -> {
if (access) {
innerGetTraces(parentInteractionId, actionListener);
} else {
String userstr = client
.threadPool()
.getThreadContext()
.getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
String user = User.parse(userstr) == null ? ActionConstants.DEFAULT_USERNAME_FOR_ERRORS : User.parse(userstr).getName();
throw new OpenSearchSecurityException("User [" + user + "] does not have access to interaction " + parentInteractionId);
}
}, e -> { actionListener.onFailure(e); });
conversationMetaIndex.checkAccess(parentInteractionId, accessListener);
innerGetTraces(parentInteractionId, actionListener);
} catch (Exception e) {
actionListener.onFailure(e);
}
}

Expand Down

0 comments on commit 6fba0d8

Please sign in to comment.