mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-09 22:38:10 -05:00
chore: simplify error formatting and clean up model assignment logic
### CHANGES - Remove redundant fmt.Sprintf calls from error formatting logic - Simplify model assignment to always use normalized model names - Remove unused variadic parameter from the VendorsManager Clear method
This commit is contained in:
@@ -283,30 +283,30 @@ func assignWithConversion(targetField, sourceField reflect.Value) error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("cannot_convert_string"), str, targetField.Kind()))
|
||||
return fmt.Errorf(i18n.T("cannot_convert_string"), str, targetField.Kind())
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("unsupported_conversion"), sourceField.Kind(), targetField.Kind()))
|
||||
return fmt.Errorf(i18n.T("unsupported_conversion"), sourceField.Kind(), targetField.Kind())
|
||||
}
|
||||
|
||||
func loadYAMLConfig(configPath string) (*Flags, error) {
|
||||
absPath, err := util.GetAbsolutePath(configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s", fmt.Sprintf(i18n.T("invalid_config_path"), err))
|
||||
return nil, fmt.Errorf(i18n.T("invalid_config_path"), err)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(absPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("%s", fmt.Sprintf(i18n.T("config_file_not_found"), absPath))
|
||||
return nil, fmt.Errorf(i18n.T("config_file_not_found"), absPath)
|
||||
}
|
||||
return nil, fmt.Errorf("%s", fmt.Sprintf(i18n.T("error_reading_config_file"), err))
|
||||
return nil, fmt.Errorf(i18n.T("error_reading_config_file"), err)
|
||||
}
|
||||
|
||||
// Use the existing Flags struct for YAML unmarshal
|
||||
config := &Flags{}
|
||||
if err := yaml.Unmarshal(data, config); err != nil {
|
||||
return nil, fmt.Errorf("%s", fmt.Sprintf(i18n.T("error_parsing_config_file"), err))
|
||||
return nil, fmt.Errorf(i18n.T("error_parsing_config_file"), err)
|
||||
}
|
||||
|
||||
debuglog.Debug(debuglog.Detailed, "Config: %v\n", config)
|
||||
@@ -324,7 +324,7 @@ func readStdin() (ret string, err error) {
|
||||
sb.WriteString(line)
|
||||
break
|
||||
}
|
||||
err = fmt.Errorf("%s", fmt.Sprintf(i18n.T("error_reading_piped_message"), readErr))
|
||||
err = fmt.Errorf(i18n.T("error_reading_piped_message"), readErr)
|
||||
return
|
||||
} else {
|
||||
sb.WriteString(line)
|
||||
@@ -342,7 +342,7 @@ func validateImageFile(imagePath string) error {
|
||||
|
||||
// Check if file already exists
|
||||
if _, err := os.Stat(imagePath); err == nil {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("image_file_already_exists"), imagePath))
|
||||
return fmt.Errorf(i18n.T("image_file_already_exists"), imagePath)
|
||||
}
|
||||
|
||||
// Check file extension
|
||||
@@ -353,7 +353,7 @@ func validateImageFile(imagePath string) error {
|
||||
return nil // Valid extension found
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("invalid_image_file_extension"), ext))
|
||||
return fmt.Errorf(i18n.T("invalid_image_file_extension"), ext)
|
||||
}
|
||||
|
||||
// validateImageParameters validates image generation parameters
|
||||
@@ -371,7 +371,7 @@ func validateImageParameters(imagePath, size, quality, background string, compre
|
||||
validSizes := []string{"1024x1024", "1536x1024", "1024x1536", "auto"}
|
||||
valid := slices.Contains(validSizes, size)
|
||||
if !valid {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("invalid_image_size"), size))
|
||||
return fmt.Errorf(i18n.T("invalid_image_size"), size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ func validateImageParameters(imagePath, size, quality, background string, compre
|
||||
validQualities := []string{"low", "medium", "high", "auto"}
|
||||
valid := slices.Contains(validQualities, quality)
|
||||
if !valid {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("invalid_image_quality"), quality))
|
||||
return fmt.Errorf(i18n.T("invalid_image_quality"), quality)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ func validateImageParameters(imagePath, size, quality, background string, compre
|
||||
validBackgrounds := []string{"opaque", "transparent"}
|
||||
valid := slices.Contains(validBackgrounds, background)
|
||||
if !valid {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("invalid_image_background"), background))
|
||||
return fmt.Errorf(i18n.T("invalid_image_background"), background)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,17 +399,17 @@ func validateImageParameters(imagePath, size, quality, background string, compre
|
||||
// Validate compression (only for jpeg/webp)
|
||||
if compression != 0 { // 0 means not set
|
||||
if ext != ".jpg" && ext != ".jpeg" && ext != ".webp" {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("image_compression_jpeg_webp_only"), ext))
|
||||
return fmt.Errorf(i18n.T("image_compression_jpeg_webp_only"), ext)
|
||||
}
|
||||
if compression < 0 || compression > 100 {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("image_compression_range_error"), compression))
|
||||
return fmt.Errorf(i18n.T("image_compression_range_error"), compression)
|
||||
}
|
||||
}
|
||||
|
||||
// Validate background transparency (only for png/webp)
|
||||
if background == "transparent" {
|
||||
if ext != ".png" && ext != ".webp" {
|
||||
return fmt.Errorf("%s", fmt.Sprintf(i18n.T("transparent_background_png_webp_only"), ext))
|
||||
return fmt.Errorf(i18n.T("transparent_background_png_webp_only"), ext)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,13 +53,9 @@ func (o *Chatter) Send(request *domain.ChatRequest, opts *domain.ChatOptions) (s
|
||||
return
|
||||
}
|
||||
|
||||
if opts.Model == "" {
|
||||
opts.Model = o.model
|
||||
} else {
|
||||
// Ensure opts.Model uses the normalized name from o.model if they refer to the same model
|
||||
// This handles cases where user provides "GPT-5" but we've normalized it to "gpt-5"
|
||||
opts.Model = o.model
|
||||
}
|
||||
// Always use the normalized model name from the Chatter
|
||||
// This handles cases where user provides "GPT-5" but we've normalized it to "gpt-5"
|
||||
opts.Model = o.model
|
||||
|
||||
if opts.ModelContextLength == 0 {
|
||||
opts.ModelContextLength = o.modelContextLength
|
||||
|
||||
@@ -35,7 +35,7 @@ func (o *VendorsManager) AddVendors(vendors ...Vendor) {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *VendorsManager) Clear(vendors ...Vendor) {
|
||||
func (o *VendorsManager) Clear() {
|
||||
o.VendorsByName = map[string]Vendor{}
|
||||
o.Vendors = []Vendor{}
|
||||
o.Models = nil
|
||||
|
||||
Reference in New Issue
Block a user