Skip to content

Commit 9478115

Browse files
committed
feat(llm): implement getUsedMaxToken method
Implement getUsedMaxToken method to return ModelLimits based on current model configuration. Method prioritizes GitHub Copilot model limits when available, falls back to settings max token length for default and custom models.
1 parent 6548557 commit 9478115

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/settings/model/LLMModelManager.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.settings.model
33
import cc.unitmesh.devti.llm2.GithubCopilotManager
44
import cc.unitmesh.devti.llm2.LLMProvider2
55
import cc.unitmesh.devti.llm2.model.LlmConfig
6+
import cc.unitmesh.devti.llm2.model.ModelLimits
67
import cc.unitmesh.devti.llms.custom.Message
78
import cc.unitmesh.devti.settings.AutoDevSettingsState
89
import cc.unitmesh.devti.settings.dialog.LLMDialog
@@ -73,7 +74,38 @@ class LLMModelManager(
7374

7475
return models
7576
}
76-
77+
78+
fun getUsedMaxToken(): ModelLimits {
79+
val settingsState = AutoDevSettingsState.getInstance()
80+
val modelId = settingsState.defaultModelId
81+
82+
// If no model ID is set, use the default max token length
83+
if (modelId.isEmpty() || modelId == "Default") {
84+
return ModelLimits(
85+
maxContextWindowTokens = settingsState.fetchMaxTokenLength(),
86+
maxPromptTokens = settingsState.fetchMaxTokenLength(),
87+
maxOutputTokens = settingsState.fetchMaxTokenLength()
88+
)
89+
}
90+
91+
// Check if it's a GitHub Copilot model
92+
val manager = service<GithubCopilotManager>()
93+
if (manager.isInitialized()) {
94+
val githubModels = manager.getSupportedModels(forceRefresh = false)
95+
val githubModel = githubModels?.find { it.id == modelId }
96+
if (githubModel != null && githubModel.capabilities.limits != null) {
97+
return githubModel.capabilities.limits
98+
}
99+
}
100+
101+
// For custom models, use the settings max token length
102+
return ModelLimits(
103+
maxContextWindowTokens = settingsState.fetchMaxTokenLength(),
104+
maxPromptTokens = settingsState.fetchMaxTokenLength(),
105+
maxOutputTokens = settingsState.fetchMaxTokenLength()
106+
)
107+
}
108+
77109
/**
78110
* Get provider name from model ID
79111
* Used by AutoDevInputSection when model selection changes

0 commit comments

Comments
 (0)