Skip to content

Commit a8cf41e

Browse files
cleaned up and ready for PR
1 parent 8d3d26a commit a8cf41e

9 files changed

Lines changed: 117 additions & 92 deletions

File tree

‎java/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<module>semantickernel-bom</module>
8181
<module>semantickernel-api</module>
8282
<module>semantickernel-core</module>
83+
<module>semantickernel-spring-starter</module>
8384
</modules>
8485

8586
<dependencyManagement>

‎java/semantickernel-spring-boot-starter/src/test/java/azureopenai/AzureOpenAIAutoConfigurationTest.java‎

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,78 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
77
<groupId>com.microsoft.semantic-kernel</groupId>
88
<artifactId>semantickernel-parent</artifactId>
99
<version>0.2.10-alpha-SNAPSHOT</version>
10-
<relativePath>../pom.xml</relativePath>
1110
</parent>
12-
<artifactId>semantickernel-spring-boot-starter</artifactId>
13-
<name>Semantic Kernel - Spring Boot Starter</name>
14-
<packaging>jar</packaging>
15-
<description>Semantic Kernel Spring Auto Configuration</description>
1611

17-
<dependencies>
18-
19-
<!-- production dependencies -->
12+
<artifactId>semantickernel-spring-starter</artifactId>
2013

14+
<properties>
15+
<maven.compiler.source>17</maven.compiler.source>
16+
<maven.compiler.target>17</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
<dependencies>
2120
<dependency>
2221
<groupId>org.springframework.boot</groupId>
23-
<artifactId>spring-boot-starter</artifactId>
22+
<artifactId>spring-boot-test</artifactId>
2423
<version>3.2.1</version>
25-
</dependency>
26-
<dependency>
27-
<groupId>com.azure</groupId>
28-
<artifactId>azure-ai-openai</artifactId>
24+
<scope>test</scope>
2925
</dependency>
3026
<dependency>
3127
<groupId>org.junit.jupiter</groupId>
3228
<artifactId>junit-jupiter</artifactId>
3329
</dependency>
3430
<dependency>
35-
<groupId>com.microsoft.semantic-kernel</groupId>
36-
<artifactId>semantickernel-core</artifactId>
31+
<groupId>org.assertj</groupId>
32+
<artifactId>assertj-core</artifactId>
33+
<version>3.25.1</version>
34+
<scope>test</scope>
3735
</dependency>
3836
<dependency>
39-
<groupId>org.mockito</groupId>
40-
<artifactId>mockito-core</artifactId>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-autoconfigure</artifactId>
39+
<version>3.2.1</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot</artifactId>
44+
<version>3.2.1</version>
4145
</dependency>
4246
<dependency>
4347
<groupId>com.azure</groupId>
44-
<artifactId>azure-core</artifactId>
45-
<version>1.45.1</version>
46-
<scope>compile</scope>
48+
<artifactId>azure-ai-openai</artifactId>
49+
<version>1.0.0-beta.6</version>
4750
</dependency>
4851
<dependency>
4952
<groupId>com.microsoft.semantic-kernel</groupId>
5053
<artifactId>semantickernel-api</artifactId>
5154
</dependency>
5255
<dependency>
53-
<groupId>org.springframework.boot</groupId>
54-
<artifactId>spring-boot-starter-test</artifactId>
56+
<groupId>com.microsoft.semantic-kernel</groupId>
57+
<artifactId>semantickernel-core</artifactId>
5558
<scope>test</scope>
56-
<version>3.2.1</version>
5759
</dependency>
5860
<dependency>
59-
<groupId>org.springframework.boot</groupId>
60-
<artifactId>spring-boot-autoconfigure</artifactId>
61-
<version>3.2.1</version>
62-
<scope>compile</scope>
61+
<groupId>com.microsoft.semantic-kernel</groupId>
62+
<artifactId>semantickernel-connectors-ai-openai</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.springframework</groupId>
67+
<artifactId>spring-test</artifactId>
68+
<version>6.1.2</version>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.azure</groupId>
73+
<artifactId>azure-identity</artifactId>
74+
<version>1.9.1</version>
6375
</dependency>
6476
</dependencies>
6577

66-
6778
</project>

java/semantickernel-spring-boot-starter/src/main/java/azureopenai/AzureOpenAiConnectionProperties.java renamed to java/semantickernel-spring-starter/src/main/java/com/microsoft/semantickernel/starter/AzureOpenAIConnectionProperties.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
package azureopenai;
1+
package com.microsoft.semantickernel.starter;
2+
23

34
import org.springframework.boot.context.properties.ConfigurationProperties;
45

5-
@ConfigurationProperties(AzureOpenAiConnectionProperties.CONFIG_PREFIX)
6-
public class AzureOpenAiConnectionProperties {
6+
@ConfigurationProperties(AzureOpenAIConnectionProperties.CONFIG_PREFIX)
7+
public class AzureOpenAIConnectionProperties {
78

89
public static final String CONFIG_PREFIX = "client.azureopenai";
10+
911
/**
1012
* Azure OpenAI API endpoint.From the Azure AI OpenAI at 'Resource Management' select `Keys and
1113
* Endpoint` and find it on the right side.
@@ -46,4 +48,4 @@ public void setDeploymentName(String deploymentName) {
4648
this.deploymentName = deploymentName;
4749
}
4850

49-
}
51+
}

java/semantickernel-spring-boot-starter/src/main/java/azureopenai/AzureOpenAIAutoConfiguration.java renamed to java/semantickernel-spring-starter/src/main/java/com/microsoft/semantickernel/starter/SemanticKernelAutoConfiguration.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
1-
package azureopenai;
1+
package com.microsoft.semantickernel.starter;
2+
23

34
import com.azure.ai.openai.OpenAIAsyncClient;
45
import com.azure.ai.openai.OpenAIClientBuilder;
56
import com.azure.core.credential.AzureKeyCredential;
67
import com.microsoft.semantickernel.Kernel;
78
import com.microsoft.semantickernel.SKBuilders;
89
import org.springframework.boot.autoconfigure.AutoConfiguration;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
911
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
12+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
1013
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1114
import org.springframework.context.annotation.Bean;
1215
import org.springframework.util.Assert;
1316

17+
@SpringBootApplication(scanBasePackages = "com.microsoft.semantickernel.starter")
1418
@AutoConfiguration
15-
@EnableConfigurationProperties(AzureOpenAiConnectionProperties.class)
16-
public class AzureOpenAIAutoConfiguration {
17-
String modelId;
19+
@EnableConfigurationProperties(AzureOpenAIConnectionProperties.class)
20+
public class SemanticKernelAutoConfiguration {
1821

1922
/**
2023
* Creates a {@link OpenAIAsyncClient} with the endpoint and key specified in the
21-
* {@link AzureOpenAiConnectionProperties}.
24+
* {@link AzureOpenAIConnectionProperties}.
2225
*
23-
* @param connectionProperties the {@link AzureOpenAiConnectionProperties} to use
26+
* @param connectionProperties the {@link AzureOpenAIConnectionProperties} to use
2427
* @return the {@link OpenAIAsyncClient}
2528
*/
2629
@Bean
2730
@ConditionalOnClass(OpenAIAsyncClient.class)
28-
public OpenAIAsyncClient openAIAsyncClient(AzureOpenAiConnectionProperties connectionProperties) {
29-
modelId = connectionProperties.getDeploymentName();
31+
@ConditionalOnMissingBean
32+
public OpenAIAsyncClient openAIAsyncClient(AzureOpenAIConnectionProperties connectionProperties) {
3033
Assert.hasText(connectionProperties.getEndpoint(), "Azure OpenAI endpoint must be set");
3134
Assert.hasText(connectionProperties.getKey(), "Azure OpenAI key must be set");
32-
return new OpenAIClientBuilder().endpoint(connectionProperties.getEndpoint())
35+
return new OpenAIClientBuilder()
36+
.endpoint(connectionProperties.getEndpoint())
3337
.credential(new AzureKeyCredential(connectionProperties.getKey()))
3438
.buildAsyncClient();
3539
}
3640

3741
/**
38-
* Creates a {@link Kernel} with a default {@link com.microsoft.semantickernel.services.AIService} that uses the
39-
* {@link com.microsoft.semantickernel.chatcompletion;} with the model id specified in
40-
* the {@link AzureOpenAiConnectionProperties} as DeploymentName.
42+
* Creates a {@link Kernel} with a default {@link com.microsoft.semantickernel.services.AIService}
43+
* that uses the {@link com.microsoft.semantickernel.chatcompletion;} with the model id specified
44+
* in the {@link AzureOpenAIConnectionProperties} as DeploymentName.
4145
*
4246
* @param client the {@link OpenAIAsyncClient} to use
4347
* @return the {@link Kernel}
@@ -46,8 +50,8 @@ public OpenAIAsyncClient openAIAsyncClient(AzureOpenAiConnectionProperties conne
4650
public Kernel semanticKernel(OpenAIAsyncClient client) {
4751
return SKBuilders.kernel()
4852
.withDefaultAIService(
49-
SKBuilders.chatCompletion()
50-
.withModelId(modelId)
53+
SKBuilders.textCompletion()
54+
.withModelId("modelId")
5155
.withOpenAIClient(client)
5256
.build())
5357
.build();

java/semantickernel-spring-boot-starter/src/main/resources/application.properties renamed to java/semantickernel-spring-starter/src/main/resources/application.properties

File renamed without changes.

java/semantickernel-spring-boot-starter/src/test/java/azureopenai/AzureOpenAIConnectionPropertiesTest.java renamed to java/semantickernel-spring-starter/src/test/java/com/microsoft/semantickernel/azureopenai/AzureOpenAIConnectionPropertiesTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
package azureopenai;
1+
package com.microsoft.semantickernel.azureopenai;
22

3-
import azureopenai.AzureOpenAIAutoConfigurationTest.TestConfiguration;
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import com.microsoft.semantickernel.starter.AzureOpenAIConnectionProperties;
6+
import com.microsoft.semantickernel.starter.SemanticKernelAutoConfiguration;
47
import org.junit.jupiter.api.Test;
58
import org.springframework.boot.autoconfigure.AutoConfigurations;
69
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
10+
import org.springframework.test.context.ActiveProfiles;
711

8-
import static org.junit.jupiter.api.Assertions.assertNotNull;
9-
12+
@ActiveProfiles("test")
1013
public class AzureOpenAIConnectionPropertiesTest {
1114

12-
13-
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(
14-
TestConfiguration.class).withPropertyValues(
15+
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withPropertyValues(
1516
// @formatter:off
1617
"client.azureopenai.key=TEST_KEY",
1718
"client.azureopenai.endpoint=TEST_ENDPOINT",
1819
"client.azureopenai.deploymentname=TEST_DEPLOYMENT_NAME"
1920
// @formatter:on
20-
).withConfiguration(AutoConfigurations.of(AzureOpenAIAutoConfiguration.class));
21+
).withConfiguration(AutoConfigurations.of(SemanticKernelAutoConfiguration.class));
2122

2223
@Test
2324
public void ConnectionPropertiesTest() {
2425
contextRunner.run(context -> {
25-
AzureOpenAiConnectionProperties props = context.getBean(AzureOpenAiConnectionProperties.class);
26+
AzureOpenAIConnectionProperties props = context.getBean(
27+
AzureOpenAIConnectionProperties.class);
2628
assertNotNull(props.getEndpoint());
2729
assertNotNull(props.getKey());
2830
assertNotNull(props.getDeploymentName());
2931
});
3032
}
31-
3233
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.microsoft.semantickernel.azureopenai;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import com.microsoft.semantickernel.Kernel;
6+
import com.microsoft.semantickernel.starter.AzureOpenAIConnectionProperties;
7+
import com.microsoft.semantickernel.starter.SemanticKernelAutoConfiguration;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.autoconfigure.AutoConfigurations;
11+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
12+
import org.springframework.boot.test.context.SpringBootTest;
13+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
14+
15+
@EnableConfigurationProperties(AzureOpenAIConnectionProperties.class)
16+
@SpringBootTest(classes = SemanticKernelAutoConfiguration.class)
17+
public class SemanticKernelAutoConfigurationTest {
18+
19+
@Autowired
20+
Kernel kernel;
21+
22+
@Test
23+
public void testSemanticKernelAutoConfig() {
24+
ApplicationContextRunner runner = new ApplicationContextRunner();
25+
runner.withPropertyValues(
26+
// @formatter:off
27+
"client.azureopenai.key=TEST_KEY",
28+
"client.azureopenai.endpoint=TEST_ENDPOINT",
29+
"client.azureopenai.deploymentname=TEST_DEPLOYMENT_NAME"
30+
// @formatter:on
31+
);
32+
runner.withConfiguration(AutoConfigurations.of(SemanticKernelAutoConfiguration.class));
33+
runner.run(context -> {
34+
assertNotNull(kernel);
35+
});
36+
}
37+
38+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
client.azureopenai.key=yourkey
2+
client.azureopenai.endpoint=yourendpoint
3+
client.azureopenai.deploymentname=davinci-002

0 commit comments

Comments
 (0)