Skip to content

Commit

Permalink
llm: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkCaster committed Dec 31, 2024
1 parent 89809fb commit 6b25f23
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions llm/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ func NewLLMConnector(operation string,
// try to setup output format from config and outputschema if applicable
// particular llm provider can still switch to plain format if schema is invalid or structured JSON output format is not supported
if format, err := utils.GetEnvString(fmt.Sprintf("%s_FORMAT_OP_%s", prefix, operation)); err == nil {
if strings.ToUpper(format) == "PLAIN" {
outputFormat = OutputPlain
outputSchema = map[string]interface{}{}
} else if strings.ToUpper(format) == "JSON" && len(outputSchema) > 0 {
if strings.ToUpper(format) == "JSON" {
if len(outputSchema) < 1 {
return nil, fmt.Errorf("output schema is empty, cannot use JSON mode")
}
if len(outputSchemaName) < 1 {
return nil, fmt.Errorf("output schema name is empty, cannot use JSON mode")
}
if len(outputSchemaDesc) < 1 {
return nil, fmt.Errorf("output schema description is empty, cannot use JSON mode")
}
outputFormat = OutputJson
} else {
outputFormat = OutputPlain
Expand Down

0 comments on commit 6b25f23

Please sign in to comment.