49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package generatedtext
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Tomorrow struct {
|
|
Summary string `json:"summary"`
|
|
ForecastDiscussion []string `json:"forecast_discussion"`
|
|
PrecipitationTiming string `json:"precipitation_timing,omitempty"`
|
|
Confidence string `json:"confidence,omitempty"`
|
|
}
|
|
|
|
func ValidateTomorrow(data []byte) (Tomorrow, []byte, error) {
|
|
value, err := decodeGeneratedText[Tomorrow](data, "tomorrow")
|
|
if err != nil {
|
|
return Tomorrow{}, nil, err
|
|
}
|
|
|
|
value.Summary = strings.TrimSpace(value.Summary)
|
|
value.PrecipitationTiming = strings.TrimSpace(value.PrecipitationTiming)
|
|
value.Confidence = strings.TrimSpace(value.Confidence)
|
|
value.ForecastDiscussion = trimNonEmpty(value.ForecastDiscussion)
|
|
if value.Summary == "" {
|
|
return Tomorrow{}, nil, fmt.Errorf("tomorrow generated text summary is required")
|
|
}
|
|
if len(value.ForecastDiscussion) == 0 {
|
|
return Tomorrow{}, nil, fmt.Errorf("tomorrow generated text forecast discussion is required")
|
|
}
|
|
|
|
normalized, err := normalizeGeneratedText(value, "tomorrow")
|
|
if err != nil {
|
|
return Tomorrow{}, nil, err
|
|
}
|
|
return value, normalized, nil
|
|
}
|
|
|
|
func trimNonEmpty(values []string) []string {
|
|
out := make([]string, 0, len(values))
|
|
for _, value := range values {
|
|
trimmed := strings.TrimSpace(value)
|
|
if trimmed != "" {
|
|
out = append(out, trimmed)
|
|
}
|
|
}
|
|
return out
|
|
}
|