Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5fcbe39
added embedding changes
AzeezIsh Jul 28, 2025
fe9c478
functional Go changes
AzeezIsh Jul 31, 2025
c4039da
collection changes
AzeezIsh Jul 31, 2025
0211a13
checkstyle
AzeezIsh Jul 31, 2025
76b9739
unnecessary logging
AzeezIsh Jul 31, 2025
328402a
Merge branch 'main' into hybrid_embedding
AzeezIsh Jul 31, 2025
2073980
removed style comments, keyword fixing
AzeezIsh Aug 1, 2025
e6e7c7c
Merge branch 'hybrid_embedding' of https://github.com/ansys/aali-flow…
AzeezIsh Aug 1, 2025
c2a47b0
removed internal functions joined with param
AzeezIsh Aug 4, 2025
8be07da
shifted test case to match new function output
AzeezIsh Aug 4, 2025
f14bf28
introduced variadic params for backward compatibility, unified to a s…
AzeezIsh Aug 4, 2025
f1940bc
checkstyle
AzeezIsh Aug 4, 2025
5513ead
sample one point to determine collection
AzeezIsh Aug 4, 2025
925cfc2
generalist search rather than keyword. too specific for varying colle…
AzeezIsh Aug 5, 2025
4b271a1
handling set collection types and detect dynamically
AzeezIsh Aug 5, 2025
cffa8c4
added helper functions for dbresponse collection types
AzeezIsh Aug 5, 2025
2fe0517
fixed mapping and introduced nil check instead of variadic param
AzeezIsh Aug 7, 2025
47a68f3
pre-commit files
AzeezIsh Aug 7, 2025
984c2c4
Merge branch 'main' of https://github.com/ansys/aali-flowkit into hyb…
AzeezIsh Aug 7, 2025
0dae870
grpc handled functions incorperation
AzeezIsh Aug 8, 2025
51dcdc8
better empty case handling
AzeezIsh Aug 8, 2025
e3ce1ca
include func testing changes
AzeezIsh Aug 8, 2025
f6d3685
direct go function calls don't include grpc layer
AzeezIsh Aug 8, 2025
7872370
improved summary fields focus and text refinement
AzeezIsh Aug 12, 2025
3168211
more checkstyle
AzeezIsh Aug 12, 2025
806991c
moved mapping logic and dbresponses to a seperate PR
AzeezIsh Aug 13, 2025
9b21693
Merge branch 'main' of https://github.com/ansys/aali-flowkit into hyb…
AzeezIsh Aug 13, 2025
a48fd0c
code_gen elements changes
AzeezIsh Aug 19, 2025
e684cfe
added fluent wrapper in flowkit
AzeezIsh Aug 22, 2025
40d0097
Merge branch 'main' of https://github.com/ansys/aali-flowkit into flu…
AzeezIsh Aug 25, 2025
471803f
fluent testing and workflow wrapper changes
AzeezIsh Aug 25, 2025
29dff3a
resolved local changes
AzeezIsh Aug 25, 2025
d85090f
syntax error
AzeezIsh Aug 25, 2025
44078fe
workaround for display problems
AzeezIsh Aug 25, 2025
5b6bb13
Merge branch 'main' of https://github.com/ansys/aali-flowkit into flu…
gyeole Sep 2, 2025
33f3e13
US100000 : Fix graphdb issue
gyeole Sep 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ var mcpFile string
//go:embed pkg/externalfunctions/rhsc.go
var rhscFile string

//go:embed pkg/externalfunctions/fluent.go
var fluentFile string


func init() {
// initialize config
config.InitConfig([]string{}, map[string]interface{}{
Expand Down Expand Up @@ -110,6 +114,7 @@ func main() {
"auth": authFile,
"mcp": mcpFile,
"rhsc": rhscFile,
"fluent": fluentFile,
}

// Load function definitions
Expand Down
31 changes: 31 additions & 0 deletions pkg/externalfunctions/dataextraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,15 @@ func mapToSparseVec(m map[uint]float32) *qdrant.Vector {
return qdrant.NewVectorSparse(keys, vals)
}

// Helper function
func jsonMarshal(v interface{}) string {
bytes, err := json.Marshal(v)
if err != nil {
return "{}"
}
return string(bytes)
}

// StoreElementsInVectorDatabase stores elements in the vector database.
//
// Tags:
Expand Down Expand Up @@ -798,6 +807,25 @@ func StoreElementsInVectorDatabase(elements []sharedtypes.CodeGenerationElement,
// vectorElements := []codegeneration.VectorDatabaseElement{}
points := make([]*qdrant.PointStruct, len(elements))
for i, element := range elements {
// Convert parameters to a map for easier querying
parametersMap := make([]interface{}, len(element.Parameters))
for j, param := range element.Parameters {
parametersMap[j] = map[string]interface{}{
"name": param.Name,
"type": param.Type,
"description": param.Description,
}
}

// Convert example to a map
exampleMap := map[string]interface{}{
"description": element.Example.Description,
"code": map[string]interface{}{
"type": element.Example.Code.Type,
"text": element.Example.Code.Text,
},
}

points[i] = &qdrant.PointStruct{
Id: qdrant.NewIDUUID(element.Guid.String()),
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{
Expand All @@ -808,8 +836,11 @@ func StoreElementsInVectorDatabase(elements []sharedtypes.CodeGenerationElement,
"name": element.Name,
"name_pseudocode": element.NamePseudocode,
"name_formatted": element.NameFormatted,
"summary": element.Summary,
"type": string(element.Type),
"parent_class": strings.Join(element.Dependencies, "."),
"parameters": jsonMarshal(parametersMap),
"example": jsonMarshal(exampleMap),
"metadata": element.VectorDBMetadata,
}),
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/externalfunctions/externalfunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var ExternalFunctionsMap = map[string]interface{}{
"JsonPath": JsonPath,
"StringConcat": StringConcat,
"StringFormat": StringFormat,
"FluentCodeGenTest": FluentCodeGenTest,

// code generation
"LoadCodeGenerationElements": LoadCodeGenerationElements,
Expand Down Expand Up @@ -188,4 +189,7 @@ var ExternalFunctionsMap = map[string]interface{}{

// rhsc
"SetCopilotGenerateRequestJsonBody": SetCopilotGenerateRequestJsonBody,

// fluent
"FluentCodeGen": FluentCodeGen,
}
105 changes: 105 additions & 0 deletions pkg/externalfunctions/fluent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
// SPDX-License-Identifier: MIT
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package externalfunctions

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
)

// FluentCodeGen sends a raw user message to the Fluent container and returns the response
//
// Tags:
// - @displayName: Fluent Code Gen
//
// Parameters:
// - message: the raw user message to send to the container
//
// Returns:
// - response: the response from the Fluent container as a string
func FluentCodeGen(message string) (response string) {
url := "http://aali-fluent:8000/chat"

// Create the JSON payload directly
jsonData := fmt.Sprintf(`{"message": "%s"}`, message)

// Create HTTP request
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonData))
if err != nil {
panic(fmt.Sprintf("Error creating HTTP request: %v", err))
}

// Set headers
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")

// Execute the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(fmt.Sprintf("Error executing HTTP request: %v", err))
}
defer resp.Body.Close()

// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(fmt.Sprintf("Error reading response body: %v", err))
}

// Check if the response code is successful (2xx)
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
panic(fmt.Sprintf("HTTP request failed with status code %d: %s", resp.StatusCode, string(body)))
}

// Parse JSON response to extract just the response content
var responseData map[string]interface{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(fmt.Sprintf("Error parsing JSON response: %v", err))
}

// Extract the response field
if responseField, exists := responseData["response"]; exists {
if responseArray, ok := responseField.([]interface{}); ok && len(responseArray) > 0 {
// Concatenate all items in the response array with a newline
var concatenatedResponse string
for _, item := range responseArray {
if str, ok := item.(string); ok {
concatenatedResponse += str + "\n"
} else {
concatenatedResponse += fmt.Sprintf("%v\n", item)
}
}
// Remove the trailing newline
concatenatedResponse = strings.TrimRight(concatenatedResponse, "\n")
return "```python\n" + concatenatedResponse + "```"
}
}

// Fallback to raw response if parsing fails
return string(body)
}
74 changes: 74 additions & 0 deletions pkg/externalfunctions/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,77 @@ func StringFormat(data any, format string) string {
}
return fmt.Sprintf(format, data)
}

// FluentCodeGen sends a raw user message to the Fluent container and returns the response.
// It takes a user message and posts it to the Fluent API endpoint to generate code.
//
// Tags:
// - @displayName: Fluent Code Gen Test
//
// Parameters:
// - message: the raw user message to send to the container
//
// Returns:
// - response: the response from the Fluent container as a string
func FluentCodeGenTest(message string) (response string) {
url := "http://aali-fluent:8000/chat"

// Create the JSON payload directly
jsonData := fmt.Sprintf(`{"message": "%s"}`, message)

// Create HTTP request
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonData))
if err != nil {
panic(fmt.Sprintf("Error creating HTTP request: %v", err))
}

// Set headers
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")

// Execute the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(fmt.Sprintf("Error executing HTTP request: %v", err))
}
defer resp.Body.Close()

// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(fmt.Sprintf("Error reading response body: %v", err))
}

// Check if the response code is successful (2xx)
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
panic(fmt.Sprintf("HTTP request failed with status code %d: %s", resp.StatusCode, string(body)))
}

// Parse JSON response to extract just the response content
var responseData map[string]interface{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(fmt.Sprintf("Error parsing JSON response: %v", err))
}

// Extract the response field
if responseField, exists := responseData["response"]; exists {
if responseArray, ok := responseField.([]interface{}); ok && len(responseArray) > 0 {
// Concatenate all items in the response array with a newline
var concatenatedResponse string
for _, item := range responseArray {
if str, ok := item.(string); ok {
concatenatedResponse += str + "\n"
} else {
concatenatedResponse += fmt.Sprintf("%v\n", item)
}
}
// Remove the trailing newline
concatenatedResponse = strings.TrimRight(concatenatedResponse, "\n")
return "```python\n" + concatenatedResponse + "```"
}
}

// Fallback to raw response if parsing fails
return string(body)
}
11 changes: 10 additions & 1 deletion pkg/externalfunctions/privatefunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,16 @@ func codeGenerationProcessHybridSearchEmbeddings(elements []sharedtypes.CodeGene
batchData := elements[i:end]
batchTextToEmbed := make([]string, len(batchData))
for j, data := range batchData {
batchTextToEmbed[j] = data.NameFormatted + "\n" + data.NamePseudocode + "\n" + data.Summary + "\n" + strings.Join(data.Dependencies, " ") + "\n" + strings.Join(data.Dependencies, ".")
// Build parameter text
paramText := ""
for _, param := range data.Parameters {
paramText += param.Name + " " + param.Type + " " + param.Description + " "
}

// Build example text
exampleText := data.Example.Description + " " + data.Example.Code.Text

batchTextToEmbed[j] = data.NameFormatted + "\n" + data.NamePseudocode + "\n" + data.Summary + "\n" + strings.Join(data.Dependencies, " ") + "\n" + strings.Join(data.Dependencies, ".") + "\n" + paramText + "\n" + exampleText
}

// Send http request
Expand Down