Skip to content

Commit

Permalink
add displayName to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
laurasgkadri98 committed Sep 9, 2024
1 parent ad91c76 commit 83fcf5b
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 62 deletions.
36 changes: 36 additions & 0 deletions pkg/externalfunctions/ansysgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (

// AnsysGPTCheckProhibitedWords checks the user query for prohibited words
//
// Tags:
// - @displayName: Check Prohibited Words
//
// Parameters:
// - query: the user query
// - prohibitedWords: the list of prohibited words
Expand Down Expand Up @@ -76,6 +79,9 @@ func AnsysGPTCheckProhibitedWords(query string, prohibitedWords []string, errorR

// AnsysGPTExtractFieldsFromQuery extracts the fields from the user query
//
// Tags:
// - @displayName: Extract Fields
//
// Parameters:
// - query: the user query
// - fieldValues: the field values that the user query can contain
Expand Down Expand Up @@ -151,6 +157,9 @@ func AnsysGPTExtractFieldsFromQuery(query string, fieldValues map[string][]strin

// AnsysGPTPerformLLMRephraseRequest performs a rephrase request to LLM
//
// Tags:
// - @displayName: Rephrase Request
//
// Parameters:
// - template: the template for the rephrase request
// - query: the user query
Expand Down Expand Up @@ -191,6 +200,9 @@ func AnsysGPTPerformLLMRephraseRequest(template string, query string, history []

// AnsysGPTPerformLLMRephraseRequestOld performs a rephrase request to LLM
//
// Tags:
// - @displayName: Rephrase Request Old
//
// Parameters:
// - template: the template for the rephrase request
// - query: the user query
Expand Down Expand Up @@ -233,6 +245,9 @@ func AnsysGPTPerformLLMRephraseRequestOld(template string, query string, history

// AnsysGPTBuildFinalQuery builds the final query for Ansys GPT
//
// Tags:
// - @displayName: Build Final Query
//
// Parameters:
// - refrasedQuery: the refrased query
// - context: the context
Expand Down Expand Up @@ -260,6 +275,9 @@ func AnsysGPTBuildFinalQuery(refrasedQuery string, context []sharedtypes.ACSSear

// AnsysGPTPerformLLMRequest performs a request to Ansys GPT
//
// Tags:
// - @displayName: LLM Request
//
// Parameters:
// - finalQuery: the final query
// - history: the conversation history
Expand Down Expand Up @@ -312,6 +330,9 @@ func AnsysGPTPerformLLMRequest(finalQuery string, history []sharedtypes.Historic

// AnsysGPTReturnIndexList returns the index list for Ansys GPT
//
// Tags:
// - @displayName: List Indexes
//
// Parameters:
// - indexGroups: the index groups
//
Expand Down Expand Up @@ -346,6 +367,9 @@ func AnsysGPTReturnIndexList(indexGroups []string) (indexList []string) {

// AnsysGPTACSSemanticHybridSearchs performs a semantic hybrid search in ACS
//
// Tags:
// - @displayName: ACS Semantic Hybrid Search
//
// Parameters:
// - query: the query string
// - embeddedQuery: the embedded query
Expand Down Expand Up @@ -380,6 +404,9 @@ func AnsysGPTACSSemanticHybridSearchs(

// AnsysGPTRemoveNoneCitationsFromSearchResponse removes none citations from search response
//
// Tags:
// - @displayName: Remove None Citations
//
// Parameters:
// - semanticSearchOutput: the search response
// - citations: the citations
Expand All @@ -406,6 +433,9 @@ func AnsysGPTRemoveNoneCitationsFromSearchResponse(semanticSearchOutput []shared

// AnsysGPTReorderSearchResponseAndReturnOnlyTopK reorders the search response
//
// Tags:
// - @displayName: Reorder Search Response
//
// Parameters:
// - semanticSearchOutput: the search response
// - topK: the number of results to be returned
Expand All @@ -429,6 +459,12 @@ func AnsysGPTReorderSearchResponseAndReturnOnlyTopK(semanticSearchOutput []share

// AnsysGPTGetSystemPrompt returns the system prompt for Ansys GPT
//
// Tags:
// - @displayName: Get System Prompt
//
// Parameters:
// - rephrasedQuery: the rephrased query
//
// Returns:
// - systemPrompt: the system prompt
func AnsysGPTGetSystemPrompt(rephrasedQuery string) string {
Expand Down
86 changes: 25 additions & 61 deletions pkg/externalfunctions/dataextraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"sync"

"github.com/ansys/allie-flowkit/pkg/internalstates"
"github.com/ansys/allie-sharedtypes/pkg/config"
"github.com/ansys/allie-sharedtypes/pkg/logging"
"github.com/ansys/allie-sharedtypes/pkg/sharedtypes"
"github.com/google/go-github/v56/github"
Expand All @@ -25,6 +24,9 @@ import (

// DataExtractionGetGithubFilesToExtract gets all files from github that need to be extracted.
//
// Tags:
// - @displayName: List Github Files
//
// Parameters:
// - githubRepoName: name of the github repository.
// - githubRepoOwner: owner of the github repository.
Expand Down Expand Up @@ -74,6 +76,9 @@ func DataExtractionGetGithubFilesToExtract(githubRepoName string, githubRepoOwne

// DataExtractionGetLocalFilesToExtract gets all files from local that need to be extracted.
//
// Tags:
// - @displayName: List Local Files
//
// Parameters:
// - localPath: path to the local directory.
// - localFileExtensions: local file extensions.
Expand Down Expand Up @@ -117,6 +122,9 @@ func DataExtractionGetLocalFilesToExtract(localPath string, localFileExtensions

// DataExtractionAppendStringSlices creates a new slice by appending all elements of the provided slices.
//
// Tags:
// - @displayName: Append String Slices
//
// Parameters:
// - slice1, slice2, slice3, slice4, slice5: slices to append.
//
Expand All @@ -137,6 +145,9 @@ func DataExtractionAppendStringSlices(slice1, slice2, slice3, slice4, slice5 []s

// DataExtractionDownloadGithubFileContent downloads file content from github and returns checksum and content.
//
// Tags:
// - @displayName: Download Github File Content
//
// Parameters:
// - githubRepoName: name of the github repository.
// - githubRepoOwner: owner of the github repository.
Expand Down Expand Up @@ -178,6 +189,10 @@ func DataExtractionDownloadGithubFileContent(githubRepoName string, githubRepoOw
}

// DataExtractionGetLocalFileContent reads local file and returns checksum and content.
//
// Tags:
// - @displayName: Get Local File Content
//
// Parameters:
// - localFilePath: path to file.
//
Expand Down Expand Up @@ -215,6 +230,9 @@ func DataExtractionGetLocalFileContent(localFilePath string) (checksum string, c

// DataExtractionGetDocumentType returns the document type of a file.
//
// Tags:
// - @displayName: Get Document Type
//
// Parameters:
// - filePath: path to file.
//
Expand All @@ -230,6 +248,9 @@ func DataExtractionGetDocumentType(filePath string) (documentType string) {

// DataExtractionLangchainSplitter splits content into chunks using langchain.
//
// Tags:
// - @displayName: Split Content
//
// Parameters:
// - content: content to split.
// - documentType: type of document.
Expand Down Expand Up @@ -315,6 +336,9 @@ func DataExtractionLangchainSplitter(content string, documentType string, chunkS

// DataExtractionGenerateDocumentTree generates a tree structure from the document chunks.
//
// Tags:
// - @displayName: Document Tree
//
// Parameters:
// - documentName: name of the document.
// - documentId: id of the document.
Expand Down Expand Up @@ -502,63 +526,3 @@ func DataExtractionGenerateDocumentTree(documentName string, documentId string,

return returnedDocumentData
}

// DataExtractionAddDataRequest sends a request to the add_data endpoint.
//
// Parameters:
// - collectionName: name of the collection the request is sent to.
// - data: the data to add.
func DataExtractionAddDataRequest(collectionName string, documentData []sharedtypes.DbData) {
// Create the AddDataInput object
requestObject := sharedtypes.DbAddDataInput{
CollectionName: collectionName,
Data: documentData,
}

// Create the URL
url := fmt.Sprintf("%s/%s", config.GlobalConfig.KNOWLEDGE_DB_ENDPOINT, "add_data")

// Send the HTTP POST request
var response sharedtypes.DbAddDataOutput
err, _ := createPayloadAndSendHttpRequest(url, requestObject, &response)
if err != nil {
errorMessage := fmt.Sprintf("Error sending request to add_data endpoint: %v", err)
logging.Log.Error(internalstates.Ctx, errorMessage)
panic(errorMessage)
}

logging.Log.Debugf(internalstates.Ctx, "Added data to collection: %s \n", collectionName)

return
}

// DataExtractionCreateCollectionRequest sends a request to the collection endpoint.
//
// Parameters:
// - collectionName: the name of the collection to create.
func DataExtractionCreateCollectionRequest(collectionName string) {
// Create the CreateCollectionInput object
requestObject := sharedtypes.DbCreateCollectionInput{
CollectionName: collectionName,
}

// Create the URL
url := fmt.Sprintf("%s/%s", config.GlobalConfig.KNOWLEDGE_DB_ENDPOINT, "create_collection")

// Send the HTTP POST request
var response sharedtypes.DbCreateCollectionOutput
err, statusCode := createPayloadAndSendHttpRequest(url, requestObject, &response)
if err != nil {
if statusCode == 409 {
logging.Log.Warn(internalstates.Ctx, "Collection already exists")
} else {
errorMessage := fmt.Sprintf("Error sending request to create_collection endpoint: %v", err)
logging.Log.Error(internalstates.Ctx, errorMessage)
panic(errorMessage)
}
}

logging.Log.Debugf(internalstates.Ctx, "Created collection: %s \n", collectionName)

return
}
6 changes: 6 additions & 0 deletions pkg/externalfunctions/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (

// SendAPICall sends an API call to the specified URL with the specified headers and query parameters.
//
// Tags:
// - @displayName: REST Call
//
// Parameters:
// - requestType: the type of the request (GET, POST, PUT, PATCH, DELETE)
// - urlString: the URL to send the request to
Expand Down Expand Up @@ -76,6 +79,9 @@ func SendRestAPICall(requestType string, endpoint string, header map[string]stri

// AssignStringToString assigns a string to another string
//
// Tags:
// - @displayName: Assign String to String
//
// Parameters:
// - inputString: the input string
//
Expand Down
Loading

0 comments on commit 83fcf5b

Please sign in to comment.