From 6b25f237d97f41af28386e356709c45efb1b2302 Mon Sep 17 00:00:00 2001 From: DarkCaster Date: Tue, 31 Dec 2024 04:39:50 +0300 Subject: [PATCH] llm: minor refactor --- llm/llm.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/llm/llm.go b/llm/llm.go index b0107a9..5b63465 100644 --- a/llm/llm.go +++ b/llm/llm.go @@ -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