Skip to content

Commit 820e973

Browse files
committed
remove useless code
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent be250b5 commit 820e973

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

common/src/main/java/org/opensearch/ml/common/connector/HttpConnector.java

+2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ public <T> T createPredictPayload(Map<String, String> parameters) {
289289
payload = fillNullParameters(parameters, payload);
290290
StringSubstitutor substitutor = new StringSubstitutor(parameters, "${parameters.", "}");
291291
payload = substitutor.replace(payload);
292+
log.info("to llm");
293+
log.info(payload);
292294
if (!isJson(payload)) {
293295
throw new IllegalArgumentException("Invalid payload: " + payload);
294296
}

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/AgentUtils.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@
1010
import static org.opensearch.ml.common.utils.StringUtils.isJson;
1111
import static org.opensearch.ml.common.utils.StringUtils.toJson;
1212
import static org.opensearch.ml.engine.algorithms.agent.MLAgentExecutor.MESSAGE_HISTORY_LIMIT;
13-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.ACTION;
14-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.ACTION_INPUT;
15-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.CHAT_HISTORY;
16-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.CONTEXT;
17-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.EXAMPLES;
18-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.FINAL_ANSWER;
19-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.OS_INDICES;
20-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.THOUGHT;
21-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.THOUGHT_RESPONSE;
22-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.TOOL_DESCRIPTIONS;
23-
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.TOOL_NAMES;
13+
import static org.opensearch.ml.engine.algorithms.agent.MLChatAgentRunner.*;
2414
import static org.opensearch.ml.engine.memory.ConversationIndexMemory.LAST_N_INTERACTIONS;
2515

2616
import java.security.AccessController;
@@ -223,7 +213,7 @@ public static Map<String, String> parseLLMOutput(
223213
modelOutput.remove(ACTION);
224214
}
225215
}
226-
if (!modelOutput.containsKey(ACTION) && !modelOutput.containsKey(FINAL_ANSWER)) {
216+
if (!modelOutput.containsKey(ACTION) && !modelOutput.containsKey(FINAL_ANSWER) && !modelOutput.containsKey(EMPTY_LABEL)) {
227217
modelOutput.put(FINAL_ANSWER, modelOutput.get(THOUGHT_RESPONSE));
228218
}
229219
return modelOutput;

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLChatAgentRunner.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class MLChatAgentRunner implements MLAgentRunner {
8383
public static final String ACTION_INPUT = "action_input";
8484
public static final String FINAL_ANSWER = "final_answer";
8585
public static final String THOUGHT_RESPONSE = "thought_response";
86+
public static final String EMPTY_LABEL = "empty";
8687

8788
private Client client;
8889
private Settings settings;
@@ -419,6 +420,7 @@ private void getNextStep(
419420
} else {
420421
tmpParameters.put("prompt.format_instruction", PROMPT_FORMAT_INSTRUCTION_FOR_THOUGHT_EXTRACT);
421422
tmpParameters.put("prompt.suffix", PROMPT_TEMPLATE_SUFFIX_FOR_THOUGHT_EXTRACT);
423+
tmpParameters.remove(PROMPT);
422424
String thuoghtPrompt = constructLLMPrompt(tools, tmpParameters);
423425
StringSubstitutor tmpSubstitutor = new StringSubstitutor(
424426
Map.of(SCRATCHPAD, scratchpadBuilder.toString()),
@@ -485,7 +487,7 @@ private void getNextStep(
485487
tmpParameters.put("prompt.format_instruction", PROMPT_FORMAT_INSTRUCTION_FOR_ACTION_INPUT);
486488
tmpParameters.put("prompt.suffix", PROMPT_TEMPLATE_SUFFIX_FOR_ACTION_INPUT);
487489
tmpParameters.put("current_thought", thought);
488-
490+
tmpParameters.remove(PROMPT);
489491
String actionPrompt = constructLLMPrompt(ImmutableMap.of(action, tools.get(action)), tmpParameters);
490492
tmpParameters.put("prompt", tmpSubstitutor.replace(actionPrompt));
491493
ActionRequest getActionInputRequest = new MLPredictionTaskRequest(

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/AwsConnectorExecutor.java

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public void invokeRemoteModel(MLInput mlInput, Map<String, String> parameters, S
117117
throw new OpenSearchStatusException("No response from model", RestStatus.BAD_REQUEST);
118118
}
119119
String modelResponse = responseBuilder.toString();
120+
log.info("from LLM");
121+
log.info(modelResponse);
120122
if (statusCode < 200 || statusCode >= 300) {
121123
throw new OpenSearchStatusException(REMOTE_SERVICE_ERROR + modelResponse, RestStatus.fromCode(statusCode));
122124
}

0 commit comments

Comments
 (0)