Skip to content

Commit b74843e

Browse files
make Deployment Name optional and set modelid with default as requested in review
1 parent f7f1664 commit b74843e

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

‎java/samples/semantickernel-spring-starter/src/main/java/com/microsoft/semantickernel/starter/SemanticKernelAutoConfiguration.java‎

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.azure.core.credential.AzureKeyCredential;
66
import com.microsoft.semantickernel.Kernel;
77
import com.microsoft.semantickernel.SKBuilders;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
810
import org.springframework.boot.autoconfigure.AutoConfiguration;
911
import org.springframework.boot.autoconfigure.SpringBootApplication;
1012
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -18,11 +20,11 @@
1820
@EnableConfigurationProperties(AzureOpenAIConnectionProperties.class)
1921
public class SemanticKernelAutoConfiguration {
2022

21-
String modelId;
23+
private static final Logger LOGGER = LoggerFactory.getLogger(SemanticKernelAutoConfiguration.class);
2224

2325
/**
24-
* Creates a {@link OpenAIAsyncClient} with the endpoint and key specified in the {@link
25-
* AzureOpenAIConnectionProperties}.
26+
* Creates a {@link OpenAIAsyncClient} with the endpoint and key specified in the
27+
* {@link AzureOpenAIConnectionProperties}.
2628
*
2729
* @param connectionProperties the {@link AzureOpenAIConnectionProperties} to use
2830
* @return the {@link OpenAIAsyncClient}
@@ -31,35 +33,46 @@ public class SemanticKernelAutoConfiguration {
3133
@ConditionalOnClass(OpenAIAsyncClient.class)
3234
@ConditionalOnMissingBean
3335
public OpenAIAsyncClient openAIAsyncClient(
34-
AzureOpenAIConnectionProperties connectionProperties) {
36+
AzureOpenAIConnectionProperties connectionProperties) {
3537
Assert.hasText(connectionProperties.getEndpoint(), "Azure OpenAI endpoint must be set");
3638
Assert.hasText(connectionProperties.getKey(), "Azure OpenAI key must be set");
37-
38-
modelId = connectionProperties.getDeploymentName();
39-
4039
return new OpenAIClientBuilder()
41-
.endpoint(connectionProperties.getEndpoint())
42-
.credential(new AzureKeyCredential(connectionProperties.getKey()))
43-
.buildAsyncClient();
40+
.endpoint(connectionProperties.getEndpoint())
41+
.credential(new AzureKeyCredential(connectionProperties.getKey()))
42+
.buildAsyncClient();
4443
}
4544

4645
/**
47-
* Creates a {@link Kernel} with a default {@link
48-
* com.microsoft.semantickernel.services.AIService} that uses the {@link
49-
* com.microsoft.semantickernel.chatcompletion;} with the model id specified in the {@link
50-
* AzureOpenAIConnectionProperties} as DeploymentName.
46+
* Creates a {@link Kernel} with a default
47+
* {@link com.microsoft.semantickernel.services.AIService} that uses the
48+
* {@link com.microsoft.semantickernel.chatcompletion;} with the model id specified in the
49+
* {@link AzureOpenAIConnectionProperties} as DeploymentName.
5150
*
5251
* @param client the {@link OpenAIAsyncClient} to use
5352
* @return the {@link Kernel}
5453
*/
5554
@Bean
56-
public Kernel semanticKernel(OpenAIAsyncClient client) {
55+
public Kernel semanticKernel(OpenAIAsyncClient client,
56+
AzureOpenAIConnectionProperties connectionProperties) {
5757
return SKBuilders.kernel()
58-
.withDefaultAIService(
59-
SKBuilders.textCompletion()
60-
.withModelId(modelId)
61-
.withOpenAIClient(client)
62-
.build())
63-
.build();
58+
.withDefaultAIService(
59+
SKBuilders.textCompletion()
60+
.withModelId(setModelID(connectionProperties))
61+
.withOpenAIClient(client)
62+
.build())
63+
.build();
64+
}
65+
66+
private static String setModelID(AzureOpenAIConnectionProperties connectionProperties) {
67+
String modelId;
68+
if (connectionProperties.getDeploymentName() == null) {
69+
modelId = "text-davinci-003";
70+
LOGGER.warn(
71+
"No deployment name specified, using default model id: " + modelId);
72+
} else {
73+
modelId = connectionProperties.getDeploymentName();
74+
LOGGER.info("Using model id: " + modelId);
75+
}
76+
return modelId;
6477
}
6578
}

0 commit comments

Comments
 (0)