mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-03 22:30:31 +08:00
Go: refactor model API to accept model id (#15999)
### What problem does this PR solve? Not not only model_name@instance_name@provider_name is acceptable, but also model_id is acceptable. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -16,7 +16,11 @@
|
||||
|
||||
package common
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PtrString formats a pointer value as a string for debug/log output.
|
||||
// Returns "<nil>" for nil pointers.
|
||||
@@ -26,3 +30,45 @@ func PtrString[T any](p *T) string {
|
||||
}
|
||||
return fmt.Sprintf("%v", *p)
|
||||
}
|
||||
|
||||
// composite model name format: model_name@instance_name@provider_name
|
||||
func IsCompositeModelName(modelName string) bool {
|
||||
parts := strings.Split(modelName, "@")
|
||||
if len(parts) != 3 {
|
||||
return false
|
||||
}
|
||||
for _, p := range parts {
|
||||
if p == "" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsUUID(uuid string) bool {
|
||||
// only lower case letters and numbers, length is 32
|
||||
if len(uuid) != 32 {
|
||||
return false
|
||||
}
|
||||
uuidRegex := regexp.MustCompile(`^[a-z0-9]+$`)
|
||||
if uuidRegex.MatchString(uuid) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ExtractCompositeName splits a composite model name into three parts.
|
||||
// Returns (modelName, instanceName, providerName, true) on success,
|
||||
// or ("", "", "", false) if the name is not a valid composite name.
|
||||
func ExtractCompositeName(modelName string) (string, string, string, error) {
|
||||
parts := strings.Split(modelName, "@")
|
||||
if len(parts) != 3 {
|
||||
return "", "", "", fmt.Errorf("invalid model name format")
|
||||
}
|
||||
for _, p := range parts {
|
||||
if p == "" {
|
||||
return "", "", "", fmt.Errorf("invalid model name format")
|
||||
}
|
||||
}
|
||||
return parts[0], parts[1], parts[2], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user