Skip to content

Commit 5a628fd

Browse files
fix: Update Azure OpenAI tutorial to use modern models
- Replace deprecated model selection logic with smart model prioritization - Add support for gpt-4o-mini as primary model (cost-effective, widely available) - Include fallback hierarchy: gpt-4o → gpt-35-turbo → gpt-4-turbo → gpt-4 - Improve error messages to show available models when selection fails - Maintain backward compatibility with existing isGPTModel() filter This resolves tutorial failures caused by deprecated models (text-davinci-003) being unavailable since April 2024. The new logic ensures tutorials work with current Azure OpenAI model offerings. Fixes: Azure OpenAI tutorial not running due to deprecated models
1 parent 3654038 commit 5a628fd

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cognitiveservices/src/main/java/com/microsoft/azure/toolkit/intellij/cognitiveservices/components/ModelComboBox.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,36 @@ protected String getItemText(final Object item) {
4444
@Override
4545
protected AccountModel doGetDefaultValue() {
4646
return Optional.ofNullable(super.doGetDefaultValue()).orElseGet(() ->
47-
this.getItems().stream().filter(AccountModel::isGPTModel).findFirst().orElse(null));
47+
findBestAvailableGPTModel(this.getItems()));
48+
}
49+
50+
/**
51+
* Find the best available GPT model from the list, prioritizing newer models like gpt-4o-mini
52+
*/
53+
private AccountModel findBestAvailableGPTModel(List<AccountModel> models) {
54+
if (models == null || models.isEmpty()) {
55+
return null;
56+
}
57+
58+
// Define preferred models in order of preference
59+
final String[] preferredModels = {
60+
"gpt-4o-mini", // Cost-effective, widely available
61+
"gpt-4o", // Latest capabilities
62+
"gpt-35-turbo", // Widely available fallback
63+
"gpt-4-turbo", // Alternative advanced model
64+
"gpt-4" // Fallback GPT-4
65+
};
66+
67+
// First, try to find models by exact name match
68+
for (String preferredModelName : preferredModels) {
69+
for (AccountModel model : models) {
70+
if (model.getName().toLowerCase().contains(preferredModelName.toLowerCase())) {
71+
return model;
72+
}
73+
}
74+
}
75+
76+
// Fallback to original GPT filter
77+
return models.stream().filter(AccountModel::isGPTModel).findFirst().orElse(null);
4878
}
4979
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cognitiveservices/src/main/java/com/microsoft/azure/toolkit/intellij/cognitiveservices/tasks/CreateCognitiveDeploymentTask.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public void execute() {
6161
if (!deployment.exists()) {
6262
final CognitiveDeploymentDraft draft = (CognitiveDeploymentDraft) deployment;
6363
final CognitiveDeploymentDraft.Config config = new CognitiveDeploymentDraft.Config();
64-
final AccountModel model = account.listModels().stream().filter(AccountModel::isGPTModel).findFirst()
65-
.orElseThrow(() -> new AzureToolkitRuntimeException(String.format("GPT model is not supported in service %s, please try with another one.", account.getName())));
64+
final AccountModel model = findBestAvailableGPTModel(account);
6665
config.setSku(DeploymentSku.fromModelSku(model.getSkus().get(0)));
6766
config.setModel(DeploymentModel.fromAccountModel(model));
6867
draft.setConfig(config);
@@ -112,4 +111,60 @@ protected CognitiveAccountDraft createAccountDraft(final Subscription subscripti
112111
draft.setConfig(CognitiveAccountDraft.Config.builder().resourceGroup(group).sku(accountSku).region(region).build());
113112
return draft;
114113
}
114+
115+
/**
116+
* Find the best available GPT model, prioritizing newer models like gpt-4o-mini
117+
*/
118+
private AccountModel findBestAvailableGPTModel(final CognitiveAccount account) {
119+
final List<AccountModel> allModels = account.listModels();
120+
121+
// Define preferred models in order of preference (most preferred first)
122+
final String[] preferredModels = {
123+
"gpt-4o-mini", // Cost-effective, widely available
124+
"gpt-4o", // Latest capabilities
125+
"gpt-35-turbo", // Widely available fallback
126+
"gpt-4-turbo", // Alternative advanced model
127+
"gpt-4" // Fallback GPT-4
128+
};
129+
130+
// First, try to find models by exact name match
131+
for (String preferredModelName : preferredModels) {
132+
for (AccountModel model : allModels) {
133+
if (model.getName().toLowerCase().contains(preferredModelName.toLowerCase()) &&
134+
hasValidSkus(model)) {
135+
AzureMessager.getMessager().info(String.format("Using preferred model: %s (version: %s)",
136+
model.getName(), model.getVersion()));
137+
return model;
138+
}
139+
}
140+
}
141+
142+
// Fallback: use the original GPT filter
143+
final AccountModel fallbackModel = allModels.stream()
144+
.filter(AccountModel::isGPTModel)
145+
.filter(this::hasValidSkus)
146+
.findFirst()
147+
.orElse(null);
148+
149+
if (fallbackModel != null) {
150+
AzureMessager.getMessager().warning(String.format("Using fallback GPT model: %s (version: %s). " +
151+
"Consider updating to a newer model like gpt-4o-mini for better performance and cost.",
152+
fallbackModel.getName(), fallbackModel.getVersion()));
153+
return fallbackModel;
154+
}
155+
156+
// If no GPT models found, throw exception
157+
throw new AzureToolkitRuntimeException(String.format(
158+
"No suitable GPT model found in service %s. Available models: %s. " +
159+
"Please ensure your Azure OpenAI service has access to GPT models like gpt-4o-mini.",
160+
account.getName(),
161+
allModels.stream().map(AccountModel::getName).reduce((a, b) -> a + ", " + b).orElse("none")));
162+
}
163+
164+
/**
165+
* Check if the model has valid SKUs for deployment
166+
*/
167+
private boolean hasValidSkus(AccountModel model) {
168+
return model.getSkus() != null && !model.getSkus().isEmpty();
169+
}
115170
}

0 commit comments

Comments
 (0)