Skip to content

Commit

Permalink
Making memory and llm spec optional fields (#398)
Browse files Browse the repository at this point in the history
* Making memory and llm spec optional fields

Signed-off-by: Joshua Palis <[email protected]>

* Removing second null llmModelId check

Signed-off-by: Joshua Palis <[email protected]>

---------

Signed-off-by: Joshua Palis <[email protected]>
(cherry picked from commit f8e822f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 11, 2024
1 parent a37e83b commit f1292a1
Showing 1 changed file with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.opensearch.ExceptionsHelper;
import org.opensearch.common.Nullable;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.indices.FlowFrameworkIndicesHandler;
import org.opensearch.flowframework.util.ParseUtils;
Expand Down Expand Up @@ -176,30 +175,23 @@ public void onFailure(Exception e) {
llmModelId = getLlmModelId(previousNodeInputs, outputs);
}

// Case when modelId is not present at all
if (llmModelId == null) {
registerAgentModelFuture.completeExceptionally(
new FlowFrameworkException(
"llm model id is not provided for workflow: " + workflowId + " on node: " + currentNodeId,
RestStatus.BAD_REQUEST
)
);
return registerAgentModelFuture;
}

LLMSpec llmSpec = getLLMSpec(llmModelId, llmParameters, workflowId, currentNodeId);

MLAgentBuilder builder = MLAgent.builder().name(name);

if (description != null) {
builder.description(description);
}
if (memory != null) {
builder.memory(memory);
}
if (llmSpec != null) {
builder.llm(llmSpec);
}

builder.type(type)
.llm(llmSpec)
.tools(toolsList)
.parameters(parameters)
.memory(memory)
.createdTime(createdTime)
.lastUpdateTime(lastUpdateTime)
.appType(appType);
Expand Down Expand Up @@ -264,10 +256,7 @@ private String getLlmModelId(Map<String, String> previousNodeInputs, Map<String,

private LLMSpec getLLMSpec(String llmModelId, Map<String, String> llmParameters, String workflowId, String currentNodeId) {
if (llmModelId == null) {
throw new FlowFrameworkException(
"model id for llm is null for workflow: " + workflowId + " on node: " + currentNodeId,
RestStatus.BAD_REQUEST
);
return null;

Check warning on line 259 in src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java#L259

Added line #L259 was not covered by tests
}
LLMSpec.LLMSpecBuilder builder = LLMSpec.builder();
builder.modelId(llmModelId);
Expand All @@ -279,6 +268,9 @@ private LLMSpec getLLMSpec(String llmModelId, Map<String, String> llmParameters,
}

private MLMemorySpec getMLMemorySpec(Object mlMemory) {
if (mlMemory == null) {
return null;

Check warning on line 272 in src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java#L272

Added line #L272 was not covered by tests
}

Map<?, ?> map = (Map<?, ?>) mlMemory;
String type = null;
Expand Down

0 comments on commit f1292a1

Please sign in to comment.