From 08390d43518a50dc2a995384d0669cfa50f5c3d8 Mon Sep 17 00:00:00 2001 From: AzeezIsh Date: Fri, 19 Sep 2025 12:23:48 -0400 Subject: [PATCH] downstream dbresponse changes, go updates with sharedtypes to new struct --- go.mod | 2 +- go.sum | 4 +- pkg/externalfunctions/llmhandler.go | 137 +++++++++++++++++++++++++++- 3 files changed, 137 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index d39ad4c8..49ac7e11 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ansys/aali-flowkit go 1.24.2 require ( - github.com/ansys/aali-sharedtypes v1.0.4-0.20250912172539-2fcf3e45b5ae + github.com/ansys/aali-sharedtypes v1.0.4-0.20250919153150-9a32e940f30d github.com/google/go-github/v56 v56.0.0 github.com/google/uuid v1.6.0 github.com/pandodao/tokenizer-go v0.2.0 diff --git a/go.sum b/go.sum index a5f06e88..ae6cefa7 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4 github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= -github.com/ansys/aali-sharedtypes v1.0.4-0.20250912172539-2fcf3e45b5ae h1:2Euh3dbT5zULzOMId2fwvbZKcaBNCJhQzgLs9k3Fqag= -github.com/ansys/aali-sharedtypes v1.0.4-0.20250912172539-2fcf3e45b5ae/go.mod h1:Ze0xVXbyl63d/dN95UKHJjoGs7ZmF5OrykBtKQxgO1U= +github.com/ansys/aali-sharedtypes v1.0.4-0.20250919153150-9a32e940f30d h1:W3iZGfrwaMjl4U7P5Pi3M0O84XDfMtMMD8VfeaFVbLk= +github.com/ansys/aali-sharedtypes v1.0.4-0.20250919153150-9a32e940f30d/go.mod h1:Ze0xVXbyl63d/dN95UKHJjoGs7ZmF5OrykBtKQxgO1U= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= diff --git a/pkg/externalfunctions/llmhandler.go b/pkg/externalfunctions/llmhandler.go index 05efd911..0735ab6a 100644 --- a/pkg/externalfunctions/llmhandler.go +++ b/pkg/externalfunctions/llmhandler.go @@ -1075,6 +1075,7 @@ func BuildLibraryContext(message string, libraryContext string) (messageWithCont // - @displayName: Final Query (General LLM Request) // // Parameters: + // - request: the original request // - knowledgedbResponse: the KnowledgeDB response // @@ -1088,9 +1089,72 @@ func BuildFinalQueryForGeneralLLMRequest(request string, knowledgedbResponse []s } // Build the final query using the KnowledgeDB response and the original request + // Append all non-empty fields to provide maximum context from comprehensive DbResponse finalQuery = "Based on the following examples:\n\n--- INFO START ---\n" for _, example := range knowledgedbResponse { - finalQuery += example.Text + "\n" + var contentParts []string + + // CodeGenerationElement fields (likely from API/Element collections) + if example.NameFormatted != "" { + contentParts = append(contentParts, example.NameFormatted) + } + if example.NamePseudocode != "" { + contentParts = append(contentParts, example.NamePseudocode) + } + if example.Name != "" { + contentParts = append(contentParts, example.Name) + } + if example.Type != "" { + contentParts = append(contentParts, "Type: "+example.Type) + } + if example.ParentClass != "" { + contentParts = append(contentParts, "Parent: "+example.ParentClass) + } + + // VectorDatabaseUserGuideSection fields (likely from User Guide collections) + if example.Title != "" { + contentParts = append(contentParts, example.Title) + } + if example.SectionName != "" { + contentParts = append(contentParts, "Section: "+example.SectionName) + } + if example.ParentSectionName != "" { + contentParts = append(contentParts, "Parent Section: "+example.ParentSectionName) + } + + // Common fields (from any collection type) + if example.DocumentName != "" { + contentParts = append(contentParts, "Document: "+example.DocumentName) + } + if example.Text != "" { + contentParts = append(contentParts, example.Text) + } + if example.Summary != "" { + contentParts = append(contentParts, "Summary: "+example.Summary) + } + if len(example.Dependencies) > 0 { + // Convert []interface{} to []string for joining + var deps []string + for _, dep := range example.Dependencies { + if depStr, ok := dep.(string); ok { + deps = append(deps, depStr) + } + } + if len(deps) > 0 { + contentParts = append(contentParts, "Dependencies: "+strings.Join(deps, ", ")) + } + } + if len(example.Keywords) > 0 { + contentParts = append(contentParts, "Keywords: "+strings.Join(example.Keywords, ", ")) + } + if len(example.Tags) > 0 { + contentParts = append(contentParts, "Tags: "+strings.Join(example.Tags, ", ")) + } + + // Add all content with spacing + if len(contentParts) > 0 { + finalQuery += strings.Join(contentParts, "\n") + "\n\n" + } } finalQuery += "--- INFO END ---\n\n" + request + "\n" @@ -1148,8 +1212,75 @@ func BuildFinalQueryForCodeLLMRequest(request string, knowledgedbResponse []shar for i, element := range knowledgedbResponse { // Add the example number finalQuery += "--- START EXAMPLE " + fmt.Sprint(i+1) + "---\n" - finalQuery += ">>> Summary:\n" + element.Summary + "\n\n" - finalQuery += ">>> Code snippet:\n```python\n" + element.Text + "\n```\n" + + // Build summary from all available non-empty fields + var summaryParts []string + + // CodeGenerationElement fields (likely from API/Element collections) + if element.NameFormatted != "" { + summaryParts = append(summaryParts, element.NameFormatted) + } + if element.Type != "" { + summaryParts = append(summaryParts, "Type: "+element.Type) + } + if element.ParentClass != "" { + summaryParts = append(summaryParts, "Parent: "+element.ParentClass) + } + + // VectorDatabaseUserGuideSection fields (likely from User Guide collections) + if element.Title != "" { + summaryParts = append(summaryParts, element.Title) + } + if element.SectionName != "" { + summaryParts = append(summaryParts, "Section: "+element.SectionName) + } + + // Common fields + if element.DocumentName != "" { + summaryParts = append(summaryParts, "Document: "+element.DocumentName) + } + if element.Summary != "" { + summaryParts = append(summaryParts, "Summary: "+element.Summary) + } + if len(element.Dependencies) > 0 { + // Convert []interface{} to []string for joining + var deps []string + for _, dep := range element.Dependencies { + if depStr, ok := dep.(string); ok { + deps = append(deps, depStr) + } + } + if len(deps) > 0 { + summaryParts = append(summaryParts, "Dependencies: "+strings.Join(deps, ", ")) + } + } + + // Build code content from all available fields + var codeParts []string + + if element.NamePseudocode != "" { + codeParts = append(codeParts, "# "+element.NamePseudocode) + } + if element.Name != "" { + codeParts = append(codeParts, "# Function: "+element.Name) + } + if element.Text != "" { + codeParts = append(codeParts, element.Text) + } + + // Use constructed content or fallback + summaryContent := strings.Join(summaryParts, " | ") + if summaryContent == "" { + summaryContent = "No summary available" + } + + codeContent := strings.Join(codeParts, "\n") + if codeContent == "" { + codeContent = "# No code content available" + } + + finalQuery += ">>> Summary:\n" + summaryContent + "\n\n" + finalQuery += ">>> Code snippet:\n```python\n" + codeContent + "\n```\n" finalQuery += "--- END EXAMPLE " + fmt.Sprint(i+1) + "---\n\n" } }