Skip to content

Commit

Permalink
fix ansysgpt no output (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKuhnAnsys authored Nov 7, 2024
1 parent da717a8 commit 43e336e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
29 changes: 15 additions & 14 deletions pkg/externalfunctions/ansysgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,6 @@ func AisAcsSemanticHybridSearchs(
output = append(output, results...)
}

fmt.Println(len(output))

return output
}

Expand Down Expand Up @@ -738,20 +736,23 @@ func AisPerformLLMFinalRequest(systemTemplate string,
}

// create json string from context
contextString := "{"
chunkNr := 1
for _, example := range context {
json, err := json.Marshal(example)
if err != nil {
logging.Log.Errorf(internalstates.Ctx, "Error marshalling context: %v", err)
return "", nil
contextString := ""
if len(context) != 0 {
contextString += "{"
chunkNr := 1
for _, example := range context {
json, err := json.Marshal(example)
if err != nil {
logging.Log.Errorf(internalstates.Ctx, "Error marshalling context: %v", err)
return "", nil
}
contextString += fmt.Sprintf("\"chunk %v\": %v", chunkNr, string(json)) + ", "
chunkNr++
}
contextString += fmt.Sprintf("\"chunk %v\": %v", chunkNr, string(json)) + ", "
chunkNr++
// remove last comma, then add closing bracket
contextString = contextString[:len(contextString)-2]
contextString += "}"
}
// remove last comma, then add closing bracket
contextString = contextString[:len(contextString)-2]
contextString += "}"

// create string from prohibited words
prohibitedWordsString := ""
Expand Down
8 changes: 4 additions & 4 deletions pkg/grpcserver/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ func (s *server) RunFunction(ctx context.Context, req *allieflowkitgrpc.Function
var err error
inputs[i], err = typeconverters.ConvertStringToGivenType(input.Value, functionDefinition.Input[i].GoType)
if err != nil {
return nil, fmt.Errorf("error converting input %s to type %s: %v", input.Name, functionDefinition.Input[i].GoType, err)
return nil, fmt.Errorf("error converting input '%s' of function '%s' to type '%s': %v", input.Name, req.Name, functionDefinition.Input[i].GoType, err)
}

// check for option sets and convert values
if len(functionDefinition.Input[i].Options) > 0 {
// convert value to correct type
inputs[i], err = convertOptionSetValues(functionDefinition.Name, input.Name, inputs[i])
if err != nil {
return nil, fmt.Errorf("error converting input %s to type %s: %v", input.Name, functionDefinition.Input[i].GoType, err)
return nil, fmt.Errorf("error converting option set input '%s' of function '%s' to type '%s': %v", input.Name, req.Name, functionDefinition.Input[i].GoType, err)
}
}
}
Expand Down Expand Up @@ -230,15 +230,15 @@ func (s *server) StreamFunction(req *allieflowkitgrpc.FunctionInputs, stream all
var err error
inputs[i], err = typeconverters.ConvertStringToGivenType(input.Value, functionDefinition.Input[i].GoType)
if err != nil {
return fmt.Errorf("error converting input %s to type %s: %v", input.Name, functionDefinition.Input[i].GoType, err)
return fmt.Errorf("error converting input '%s' of function '%s' to type '%s': %v", input.Name, req.Name, functionDefinition.Input[i].GoType, err)
}

// check for option sets and convert values
if len(functionDefinition.Input[i].Options) > 0 {
// convert value to correct type
inputs[i], err = convertOptionSetValues(functionDefinition.Name, input.Name, inputs[i])
if err != nil {
return fmt.Errorf("error converting input %s to type %s: %v", input.Name, functionDefinition.Input[i].GoType, err)
return fmt.Errorf("error converting option set input '%s' of function '%s' to type '%s': %v", input.Name, req.Name, functionDefinition.Input[i].GoType, err)
}
}
}
Expand Down

0 comments on commit 43e336e

Please sign in to comment.