Skip to content

Commit 16a2c5c

Browse files
authored
update synthesize process (#232)
1 parent d1b89d0 commit 16a2c5c

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

pkg/externalfunctions/ansysmeshpilot.go

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,17 @@ func SynthesizeActionsTool2(message string, actions []map[string]string) (update
565565
//
566566
// Returns:
567567
// - updatedActions: the list of synthesized actions
568-
func SynthesizeActionsTool3(message_1 string, message_2 string, actions []map[string]string) (updatedActions []map[string]string) {
568+
func SynthesizeActionsTool3(message_1 string, message_2 string, target_object string, actions []map[string]string) (updatedActions []map[string]string) {
569569
ctx := &logging.ContextMap{}
570570

571571
// Clean up the input messages
572572
message_1 = strings.TrimSpace(strings.Trim(message_1, "\""))
573573
message_2 = strings.TrimSpace(strings.Trim(message_2, "\""))
574+
target_object = strings.TrimSpace(strings.Trim(target_object, "\""))
574575

575576
logging.Log.Debugf(ctx, "Tool 3 Synthesize Message 1: %s\n", message_1)
576577
logging.Log.Debugf(ctx, "Tool 3 Synthesize Message 2: %s\n", message_2)
578+
logging.Log.Debugf(ctx, "Tool 3 Target Object: %s\n", target_object)
577579

578580
// Get synthesize actions find key from configuration
579581
synthesizeActionsFindKey1, exists := config.GlobalConfig.WORKFLOW_CONFIG_VARIABLES["APP_PROMPT_TEMPLATE_SYNTHESIZE_ACTION_TOOL3_VALUE"]
@@ -590,20 +592,52 @@ func SynthesizeActionsTool3(message_1 string, message_2 string, actions []map[st
590592
panic(errorMessage)
591593
}
592594

595+
APP_TOOL_ACTIONS_TARGET_5, exists := config.GlobalConfig.WORKFLOW_CONFIG_VARIABLES["APP_TOOL_ACTIONS_TARGET_5"]
596+
if !exists {
597+
errorMessage := fmt.Sprintf("failed to load APP_TOOL_ACTIONS_TARGET_5 from the configuration")
598+
logging.Log.Error(ctx, errorMessage)
599+
panic(errorMessage)
600+
}
601+
602+
APP_TOOL_ACTIONS_TARGET_6, exists := config.GlobalConfig.WORKFLOW_CONFIG_VARIABLES["APP_TOOL_ACTIONS_TARGET_6"]
603+
if !exists {
604+
errorMessage := fmt.Sprintf("failed to load APP_TOOL_ACTIONS_TARGET_6 from the configuration")
605+
logging.Log.Error(ctx, errorMessage)
606+
panic(errorMessage)
607+
}
608+
593609
// Initialize updatedActions with the input actions
594610
updatedActions = actions
595611

596-
// Check the first dictionary in actions
597-
if len(updatedActions) > 0 {
598-
firstAction := updatedActions[0]
599-
if _, ok := firstAction[synthesizeActionsFindKey1]; ok && len(message_1) != 0 {
600-
// Replace the value with the input message
601-
firstAction[synthesizeActionsFindKey1] = message_1
612+
if target_object == APP_TOOL_ACTIONS_TARGET_5 {
613+
// Check the first dictionary in actions
614+
if len(updatedActions) > 0 {
615+
firstAction := updatedActions[0]
616+
if _, ok := firstAction[synthesizeActionsFindKey1]; ok {
617+
// Replace the value with the input message
618+
firstAction[synthesizeActionsFindKey1] = message_1
619+
}
620+
621+
if _, ok := firstAction[synthesizeActionsFindKey2]; ok && len(message_2) != 0 {
622+
firstAction[synthesizeActionsFindKey2] = message_2
623+
}
602624
}
625+
} else if target_object == APP_TOOL_ACTIONS_TARGET_6 {
626+
// Check if there is a third dictionary in actions
627+
if len(updatedActions) > 2 {
628+
thirdAction := updatedActions[2]
629+
if _, ok := thirdAction[synthesizeActionsFindKey1]; ok {
630+
// Replace the value with the input message
631+
thirdAction[synthesizeActionsFindKey1] = message_1
632+
}
603633

604-
if _, ok := firstAction[synthesizeActionsFindKey2]; ok && len(message_2) != 0 {
605-
firstAction[synthesizeActionsFindKey2] = message_2
634+
updatedActions = []map[string]string{thirdAction}
635+
} else {
636+
logging.Log.Warnf(ctx, "No third action found in updatedActions for target_object: %s", target_object)
606637
}
638+
} else {
639+
// Skip if target_object is neither APP_TOOL_ACTIONS_TARGET_5 nor APP_TOOL_ACTIONS_TARGET_6
640+
logging.Log.Infof(ctx, "Skipping action synthesis for target_object: %s", target_object)
607641
}
608642

609643
logging.Log.Debugf(ctx, "The Updated Actions: %q\n", updatedActions)
@@ -1813,12 +1847,15 @@ func ParseSlashCommand(userInput string) (slashCmd, targetCmd string, hasCmd boo
18131847
// Parameters:
18141848
// - slashCmd: the slash command
18151849
// - targetCmd: the target command
1850+
// - finalizeResult: the finalize result from previous step
18161851
//
18171852
// Returns:
18181853
// - result: the synthesized string
18191854
func SynthesizeSlashCommand(slashCmd, targetCmd, finalizeResult string) (result string) {
18201855
ctx := &logging.ContextMap{}
18211856

1857+
logging.Log.Debugf(ctx, "finalizeResult: %q, targetCmd: %q, slashCmd: %q", finalizeResult, targetCmd, slashCmd)
1858+
18221859
message, exists := config.GlobalConfig.WORKFLOW_CONFIG_VARIABLES["APP_ACTION_TOOL_17_SUCCESS_MESSAGE"]
18231860
if !exists {
18241861
errorMessage := fmt.Sprintf("failed to load APP_ACTION_TOOL_17_SUCCESS_MESSAGE from the configuration")

0 commit comments

Comments
 (0)