Skip to content

Commit 9d1cb38

Browse files
authored
Jali/pilot (#225)
1 parent 727c742 commit 9d1cb38

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

pkg/externalfunctions/ansysmeshpilot.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,63 @@ func SynthesizeActionsTool2(message string, actions []map[string]string) (update
554554
return
555555
}
556556

557+
// SynthesizeActionsTool3 update action as per user instruction
558+
// // Tags:
559+
// - @displayName: SynthesizeActionsTool3
560+
//
561+
// Parameters:
562+
// - message_1: the first message from the llm
563+
// - message_2: the second message from the llm
564+
// - actions: the list of actions
565+
//
566+
// Returns:
567+
// - updatedActions: the list of synthesized actions
568+
func SynthesizeActionsTool3(message_1 string, message_2 string, actions []map[string]string) (updatedActions []map[string]string) {
569+
ctx := &logging.ContextMap{}
570+
571+
// Clean up the input messages
572+
message_1 = strings.TrimSpace(strings.Trim(message_1, "\""))
573+
message_2 = strings.TrimSpace(strings.Trim(message_2, "\""))
574+
575+
logging.Log.Debugf(ctx, "Tool 3 Synthesize Message 1: %s\n", message_1)
576+
logging.Log.Debugf(ctx, "Tool 3 Synthesize Message 2: %s\n", message_2)
577+
578+
// Get synthesize actions find key from configuration
579+
synthesizeActionsFindKey1, exists := config.GlobalConfig.WORKFLOW_CONFIG_VARIABLES["APP_PROMPT_TEMPLATE_SYNTHESIZE_ACTION_TOOL3_VALUE"]
580+
if !exists {
581+
errorMessage := fmt.Sprintf("failed to load synthesize actions tool 3 find key from the configuration")
582+
logging.Log.Error(ctx, errorMessage)
583+
panic(errorMessage)
584+
}
585+
586+
synthesizeActionsFindKey2, exists := config.GlobalConfig.WORKFLOW_CONFIG_VARIABLES["APP_PROMPT_TEMPLATE_SYNTHESIZE_ACTION_FIND_KEY"]
587+
if !exists {
588+
errorMessage := fmt.Sprintf("failed to load synthesize actions tool 3 find key from the configuration")
589+
logging.Log.Error(ctx, errorMessage)
590+
panic(errorMessage)
591+
}
592+
593+
// Initialize updatedActions with the input actions
594+
updatedActions = actions
595+
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
602+
}
603+
604+
if _, ok := firstAction[synthesizeActionsFindKey2]; ok && len(message_2) != 0 {
605+
firstAction[synthesizeActionsFindKey2] = message_2
606+
}
607+
}
608+
609+
logging.Log.Debugf(ctx, "The Updated Actions: %q\n", updatedActions)
610+
611+
return
612+
}
613+
557614
// SynthesizeActionsTool11 synthesize actions based on user instruction
558615
//
559616
// Tags:
@@ -1846,6 +1903,39 @@ func SynthesizeSlashCommand(slashCmd, targetCmd, finalizeResult string) (result
18461903
return result
18471904
}
18481905

1906+
// ProcessMWWorkflowInfo parses the mwWorkflowInfo string and logs its content.
1907+
//
1908+
// Parameters:
1909+
// - mwWorkflowInfo: the workflow information in string format
1910+
//
1911+
// Returns:
1912+
// - None
1913+
func ProcessMWWorkflowInfo(mwWorkflowInfo string) {
1914+
ctx := &logging.ContextMap{}
1915+
1916+
// Replace single quotes with double quotes to make it valid JSON
1917+
normalizedInfo := strings.ReplaceAll(mwWorkflowInfo, "'", "\"")
1918+
1919+
// Parse the JSON string into a generic map
1920+
var parsedData map[string]interface{}
1921+
err := json.Unmarshal([]byte(normalizedInfo), &parsedData)
1922+
if err != nil {
1923+
logging.Log.Errorf(ctx, "Failed to parse mwWorkflowInfo: %v", err)
1924+
return
1925+
}
1926+
1927+
// Convert the parsed data back to a single string
1928+
// parsedString, err := json.MarshalIndent(parsedData, "", " ")
1929+
parsedString, err := json.Marshal(parsedData)
1930+
if err != nil {
1931+
logging.Log.Errorf(ctx, "Failed to convert parsed data to string: %v", err)
1932+
return
1933+
}
1934+
1935+
// Log the entire content as a single string
1936+
logging.Log.Infof(ctx, "MWWorkflowInfo Content: %s", string(parsedString))
1937+
}
1938+
18491939
// GenerateActionsSubWorkflowPrompt generates system and user prompts for subworkflow identification.
18501940
//
18511941
// Tags:

pkg/externalfunctions/externalfunctions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var ExternalFunctionsMap = map[string]interface{}{
131131
"GetActionsFromConfig": GetActionsFromConfig,
132132
"ParseHistory": ParseHistory,
133133
"SynthesizeActionsTool2": SynthesizeActionsTool2,
134+
"SynthesizeActionsTool3": SynthesizeActionsTool3,
134135
"SynthesizeActionsTool11": SynthesizeActionsTool11,
135136
"SynthesizeActionsTool12": SynthesizeActionsTool12,
136137
"SynthesizeActionsTool17": SynthesizeActionsTool17,
@@ -141,6 +142,7 @@ var ExternalFunctionsMap = map[string]interface{}{
141142
"ParseHistoryToHistoricMessages": ParseHistoryToHistoricMessages,
142143
"ParseSlashCommand": ParseSlashCommand,
143144
"SynthesizeSlashCommand": SynthesizeSlashCommand,
145+
"ProcessMWWorkflowInfo": ProcessMWWorkflowInfo,
144146
"FinalizeMessage": FinalizeMessage,
145147
"GenerateUserPrompt": GenerateUserPrompt,
146148
"GenerateUserPromptWithList": GenerateUserPromptWithList,

0 commit comments

Comments
 (0)