-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: add some translate #12904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add some translate #12904
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "strings" | ||
|
|
||
| "github.com/1Panel-dev/1Panel/agent/utils/common" | ||
| ) | ||
|
|
||
| const ( | ||
| vllmAppKeyForUpgrade = "vllm" | ||
| vllmImageEnvKey = "IMAGE" | ||
| vllmImageTypeNvidia = "nvidia" | ||
| vllmImageTypeIntel = "intel" | ||
| ) | ||
|
|
||
| func resolveVllmVersionFamily(version, image string) string { | ||
| normalizedVersion := strings.ToLower(strings.TrimSpace(version)) | ||
| if strings.HasPrefix(normalizedVersion, vllmImageTypeIntel+"-") { | ||
| return vllmImageTypeIntel | ||
| } | ||
| if strings.HasPrefix(normalizedVersion, vllmImageTypeNvidia+"-") { | ||
| return vllmImageTypeNvidia | ||
| } | ||
| normalizedImage := strings.ToLower(strings.TrimSpace(image)) | ||
| if strings.Contains(normalizedImage, "intel/") || strings.Contains(normalizedImage, "llm-scaler-vllm") { | ||
| return vllmImageTypeIntel | ||
| } | ||
| return vllmImageTypeNvidia | ||
| } | ||
|
|
||
| func trimVllmVersionFamily(version string) string { | ||
| trimmed := strings.TrimSpace(version) | ||
| normalized := strings.ToLower(trimmed) | ||
| for _, family := range []string{vllmImageTypeNvidia, vllmImageTypeIntel} { | ||
| prefix := family + "-" | ||
| if strings.HasPrefix(normalized, prefix) { | ||
| return strings.TrimSpace(trimmed[len(prefix):]) | ||
| } | ||
| } | ||
| return trimmed | ||
| } | ||
|
|
||
| func buildDefaultVllmImageByVersion(version string) string { | ||
| tag := trimVllmVersionFamily(version) | ||
| if resolveVllmVersionFamily(version, "") == vllmImageTypeIntel { | ||
| return "intel/llm-scaler-vllm:" + tag | ||
| } | ||
| if tag != "" && !strings.HasPrefix(strings.ToLower(tag), "v") { | ||
| tag = "v" + tag | ||
| } | ||
| return "vllm/vllm-openai:" + tag | ||
| } | ||
|
|
||
| func isVllmUpgradeVersionAllowed(currentVersion, targetVersion, currentImage string) bool { | ||
| currentFamily := resolveVllmVersionFamily(currentVersion, currentImage) | ||
| targetFamily := resolveVllmVersionFamily(targetVersion, "") | ||
| return currentFamily == targetFamily | ||
| } | ||
|
|
||
| func hasVllmVersionFamilyPrefix(version string) bool { | ||
| normalized := strings.ToLower(strings.TrimSpace(version)) | ||
| return strings.HasPrefix(normalized, vllmImageTypeNvidia+"-") || strings.HasPrefix(normalized, vllmImageTypeIntel+"-") | ||
| } | ||
|
|
||
| func isVllmUpgradeCandidate(currentVersion, targetVersion, currentImage string) bool { | ||
| if strings.TrimSpace(currentVersion) == strings.TrimSpace(targetVersion) { | ||
| return false | ||
| } | ||
| if !isVllmUpgradeVersionAllowed(currentVersion, targetVersion, currentImage) { | ||
| return false | ||
| } | ||
| if common.CompareVersion(targetVersion, currentVersion) { | ||
| return true | ||
| } | ||
| return !hasVllmVersionFamilyPrefix(currentVersion) && | ||
| resolveVllmVersionFamily(targetVersion, "") == vllmImageTypeNvidia && | ||
| trimVllmVersionFamily(currentVersion) == trimVllmVersionFamily(targetVersion) | ||
| } | ||
|
|
||
| func buildVllmUpgradeImage(currentImage, currentVersion, targetVersion string) string { | ||
| trimmedImage := strings.TrimSpace(currentImage) | ||
| if trimmedImage == "" || trimmedImage == buildDefaultVllmImageByVersion(currentVersion) { | ||
| return buildDefaultVllmImageByVersion(targetVersion) | ||
| } | ||
| return trimmedImage | ||
| } | ||
|
|
||
| func loadVllmImageFromEnv(raw string) string { | ||
| envs := make(map[string]interface{}) | ||
| if strings.TrimSpace(raw) == "" { | ||
| return "" | ||
| } | ||
| if err := json.Unmarshal([]byte(raw), &envs); err != nil { | ||
| return "" | ||
| } | ||
| if image, ok := envs[vllmImageEnvKey].(string); ok { | ||
| return strings.TrimSpace(image) | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func setVllmImageInEnvContent(content []byte, image string) []byte { | ||
| normalizedImage := strings.TrimSpace(image) | ||
| if normalizedImage == "" { | ||
| return content | ||
| } | ||
| lines := strings.Split(string(content), "\n") | ||
| replaced := false | ||
| for index, line := range lines { | ||
| if strings.HasPrefix(line, vllmImageEnvKey+"=") { | ||
| lines[index] = vllmImageEnvKey + "=" + normalizedImage | ||
| replaced = true | ||
| break | ||
| } | ||
| } | ||
| if !replaced { | ||
| if len(lines) > 0 && lines[len(lines)-1] == "" { | ||
| lines[len(lines)-1] = vllmImageEnvKey + "=" + normalizedImage | ||
| lines = append(lines, "") | ||
| } else { | ||
| lines = append(lines, vllmImageEnvKey+"="+normalizedImage) | ||
| } | ||
| } | ||
| return []byte(strings.Join(lines, "\n")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This embedded
app.yamlis read byviper.Initwhen there is no external/opt/1panel/conf/app.yaml, andglobal.CONF.Base.IsEnterprisecontrols migrations, login settings, CLI behavior, and resource URLs. With this default set totrue, ordinary/community installs can boot as Enterprise, skip normal admin credential initialization, and use Enterprise-only paths; the same flip inagent/cmd/server/conf/app.yamlalso changes agent resource selection. Unless every build from this tree is Enterprise-only, keep the defaultfalseand enable Enterprise through the intended packaging/config path.Useful? React with 👍 / 👎.