From 8de6ecea99b9fc221a4cf0716666aaf0be8cc23d Mon Sep 17 00:00:00 2001 From: FelixKuhnAnsys Date: Wed, 11 Sep 2024 16:32:27 +0200 Subject: [PATCH] add index to ansysgpt --- pkg/externalfunctions/ansysgpt.go | 4 +-- pkg/externalfunctions/privatefunctions.go | 34 ++++++++++++++++++++++- pkg/externalfunctions/types.go | 25 +++++++++++++++++ pkg/functiontesting/functiontesting.go | 2 +- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/pkg/externalfunctions/ansysgpt.go b/pkg/externalfunctions/ansysgpt.go index 9173a90..29dad01 100644 --- a/pkg/externalfunctions/ansysgpt.go +++ b/pkg/externalfunctions/ansysgpt.go @@ -355,9 +355,9 @@ func AnsysGPTReturnIndexList(indexGroups []string) (indexList []string) { // indexList = append(indexList, "pyansys_help_documentation") // indexList = append(indexList, "pyansys-examples") case "Ansys Semiconductor": - // indexList = append(indexList, "ansysgpt-scbu") + indexList = append(indexList, "ansysgpt-scbu") default: - logging.Log.Warnf(internalstates.Ctx, "Invalid indexGroup: %v\n", indexGroup) + logging.Log.Errorf(internalstates.Ctx, "Invalid indexGroup: %v\n", indexGroup) return } } diff --git a/pkg/externalfunctions/privatefunctions.go b/pkg/externalfunctions/privatefunctions.go index 75a2b8d..5a1d429 100644 --- a/pkg/externalfunctions/privatefunctions.go +++ b/pkg/externalfunctions/privatefunctions.go @@ -689,6 +689,9 @@ func getFieldsAndReturnProperties(indexName string) (searchedEmbeddedFields stri case "lsdyna-documentation-r14": searchedEmbeddedFields = "contentVector, titleVector" returnedProperties = "title, url, token_size, physics, typeOFasset, content, product" + case "external-crtech-thermal-desktop": + searchedEmbeddedFields = "contentVector, sourceTitle_lvl1_vctr, sourceTitle_lvl2_vctr, sourceTitle_lvl3_vctr" + returnedProperties = "token_size, physics, typeOFasset, product, version, weight, bridge_id, content, sourceTitle_lvl2, sourceURL_lvl2, sourceTitle_lvl3, sourceURL_lvl3" default: errMessage := fmt.Sprintf("Index name not found: %s", indexName) logging.Log.Error(internalstates.Ctx, errMessage) @@ -716,6 +719,7 @@ func extractAndConvertACSResponse(body []byte, indexName string) (output []share logging.Log.Error(internalstates.Ctx, errMessage) panic(errMessage) } + output = respObject.Value case "ansysgpt-alh", "ansysgpt-scbu": respObjectAlh := ACSSearchResponseStructALH{} @@ -767,13 +771,41 @@ func extractAndConvertACSResponse(body []byte, indexName string) (output []share }) } + case "external-crtech-thermal-desktop": + respObjectCrtech := ACSSearchResponseStructCrtech{} + err := json.Unmarshal(body, &respObjectCrtech) + if err != nil { + errMessage := fmt.Sprintf("failed to unmarshal response body from ACS to ACSSearchResponseStructCrtech: %v", err) + logging.Log.Error(internalstates.Ctx, errMessage) + panic(errMessage) + } + + for _, item := range respObjectCrtech.Value { + fmt.Println("hashdsahdsha") + output = append(output, sharedtypes.ACSSearchResponse{ + SourceTitleLvl2: item.SourceTitleLvl2, + SourceURLLvl2: item.SourceURLLvl2, + SourceTitleLvl3: item.SourceTitleLvl3, + SourceURLLvl3: item.SourceURLLvl3, + Content: item.Content, + TypeOFasset: item.TypeOFasset, + Physics: item.Physics, + Product: item.Product, + Version: item.Version, + Weight: item.Weight, + TokenSize: item.TokenSize, + SearchScore: item.SearchScore, + SearchRerankerScore: item.SearchRerankerScore, + }) + } + default: errMessage := fmt.Sprintf("Index name not found: %s", indexName) logging.Log.Error(internalstates.Ctx, errMessage) panic(errMessage) } - return respObject.Value + return output } // dataExtractionFilterGithubTreeEntries filters the Github tree entries based on the specified filters. diff --git a/pkg/externalfunctions/types.go b/pkg/externalfunctions/types.go index f00b109..ef63395 100644 --- a/pkg/externalfunctions/types.go +++ b/pkg/externalfunctions/types.go @@ -148,6 +148,31 @@ type ACSSearchResponseLSdyna struct { SearchRerankerScore float64 `json:"@search.rerankerScore"` } +// ACSSearchResponseStructCrtech represents the response structure for the Azure Cognitive Search for external-crtech-thermal-desktop. +type ACSSearchResponseStructCrtech struct { + OdataContext string `json:"@odata.context"` + OdataCount int `json:"@odata.count"` + Value []ACSSearchResponseCrtech `json:"value"` +} + +// ACSSearchResponseCrtech represents the response structure for the Azure Cognitive Search for external-crtech-thermal-desktop. +type ACSSearchResponseCrtech struct { + Physics string `json:"physics"` + SourceTitleLvl3 string `json:"sourceTitle_lvl3"` + SourceURLLvl3 string `json:"sourceURL_lvl3"` + TokenSize int `json:"token_size"` + SourceTitleLvl2 string `json:"sourceTitle_lvl2"` + Weight float64 `json:"weight"` + SourceURLLvl2 string `json:"sourceURL_lvl2"` + Product string `json:"product"` + Content string `json:"content"` + TypeOFasset string `json:"typeOFasset"` + Version string `json:"version"` + BridgeId string `json:"bridge_id"` + SearchScore float64 `json:"@search.score"` + SearchRerankerScore float64 `json:"@search.rerankerScore"` +} + // DataExtractionBranch represents the branch structure for the data extraction. type DataExtractionBranch struct { Text string diff --git a/pkg/functiontesting/functiontesting.go b/pkg/functiontesting/functiontesting.go index f7bd8e2..bf5cc4f 100644 --- a/pkg/functiontesting/functiontesting.go +++ b/pkg/functiontesting/functiontesting.go @@ -28,7 +28,7 @@ func TestAnsysGPTACSSearchIndex(indexName string, query string) { filedValues := map[string][]string{ "physics": {"structures", "fluids", "electronics", "structural mechanics", "discovery", "optics", "photonics", "python", "scade", "materials", "stem", "student", "fluid dynamics", "semiconductors"}, "type_of_asset": {"aic", "km", "documentation", "youtube", "general_faq", "alh", "article", "white-paper", "brochure"}, - "product": {"forte", "scade", "mechanical", "mechanical apdl", "fluent", "embedded software", "avxcelerate", "designxplorer", "designmodeler", "cloud direct", "maxwell", "stk", "ls-dyna", "lsdyna", "gateway", "granta", "rocky", "icepak", "siwave", "cfx", "meshing", " lumerical", "motion", "autodyn", "minerva", "redhawk-sc", "totem", "totem-sc", "powerartist", "raptorx", "velocerf", "exalto", "pathfinder", "pathfinder-sc", "diakopto", "pragonx", "primex", "on-chip electromagnetics", "redhawk-sc electrothermal", "redhawk-sc security", "voltage-timing and clock jitter", "medini", "ensight", "forte", "discovery", "hfss", "sherlock", "spaceclaim", "twin builder", "additive prep", "additive print", "composite cure sim", "composite preppost", "ncode designlife", "spaceclaim directmodeler", "cfx pre", "cfx solver", "cfx turbogrid", "icem cfd", "workbench platform"}, + "product": {"additive prep", "additive print", "autodyn", "avxcelerate", "cfx", "cfx pre", "cfx solver", "cfx turbogrid", "clock jitter flow", "cloud direct", "composite cure sim", "composite preppost", "designmodeler", "designxplorer", "diakopto", "discovery", "embedded software", "ensight", "exalto", "fluent", "forte", "gateway", "granta", "hfss", "icem cfd", "icepak", "ls-dyna", "lsdyna", "lumerical", "maxwell", "mechanical", "mechanical apdl", "medini", "meshing", "minerva", "motion", "ncode designlife", "pathfinder", "pathfinder-sc", "powerartist", "pragonx", "primex", "raptorh", "raptorx", "redhawk-sc", "redhawk-sc electrothermal", "redhawk-sc security", "rocky", "scade", "sherlock", "siwave", "spaceclaim", "spaceclaim directmodeler", "stk", "totem", "totem-sc", "twin builder", "velocerf", "voltage-timing", "workbench platform"}, } // indexNames := []string{"granular-ansysgpt", "ansysgpt-documentation-2023r2", "scade-documentation-2023r2", "ansys-dot-com-marketing", "ibp-app-brief", "ansysgpt-alh", "ansysgpt-scbu", "lsdyna-documentation-r14"}