Parsing bug fixes

This commit is contained in:
Mahesh Kommareddi 2024-07-17 03:51:54 -04:00
parent e0b542d243
commit 93d244cb36
5 changed files with 26 additions and 5 deletions

View File

@ -66,15 +66,18 @@ public class ConversationFSM {
} else {
String stateTransitionTask = "Decide the next conversation state based on this message: " + message.getContent() +
"\nCurrent state: " + currentState +
"\nParticipants: " + participants;
"\nParticipants: " + participants +
"\nPossible states: " + Arrays.toString(ConversationState.values());
String reasoning = model.generate(stateTransitionTask, null);
String decisionPrompt = "Based on this reasoning:\n" + reasoning +
"\nProvide the next conversation state (DISCUSSION, TASK_ASSIGNMENT, EXECUTION, or CONCLUSION).";
"\nProvide the next conversation state. Choose from: " +
Arrays.toString(ConversationState.values()) +
"\nResponse format: STATE: <state_name>";
String response = model.generate(decisionPrompt, null);
ConversationState newState = ConversationState.valueOf(response.trim());
ConversationState newState = parseStateFromResponse(response);
transitionTo(newState);
// Broadcast the message to all participants
@ -85,10 +88,24 @@ public class ConversationFSM {
}
webSocketService.sendUpdate("conversation_message", message);
}
}
private ConversationState parseStateFromResponse(String response) {
String[] parts = response.split(":");
if (parts.length > 1) {
String stateName = parts[1].trim().toUpperCase();
try {
return ConversationState.valueOf(stateName);
} catch (IllegalArgumentException e) {
System.out.println("Invalid state name: " + stateName + ". Defaulting to DISCUSSION.");
return ConversationState.DISCUSSION;
}
}
System.out.println("Could not parse state from response: " + response + ". Defaulting to DISCUSSION.");
return ConversationState.DISCUSSION;
}
private void handleVote(String agentId) {
votes.put(agentId, true);
checkVotes();

View File

@ -1,5 +1,9 @@
package com.ioa.conversation;
public enum ConversationState {
DISCUSSION, TASK_ASSIGNMENT, EXECUTION, CONCLUSION
DISCUSSION,
TASK_GATHERING_INFO,
TASK_ASSIGNMENT,
EXECUTION,
CONCLUSION
}