Skip to content

Commit f76c7b6

Browse files
committed
Reorganize java integration tests
1 parent 3b4abc1 commit f76c7b6

37 files changed

Lines changed: 622 additions & 456 deletions

File tree

‎.github/workflows/java-build.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ jobs:
1919
java-version: '11'
2020
distribution: 'temurin'
2121
cache: maven
22+
2223
- name: Build with Maven
2324
run: cd java && ./mvnw -B -Pbug-check clean install --file pom.xml
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run Java Integration Tests and Samples
2+
3+
on:
4+
push:
5+
branches: [ "experimental-java", "java-dev" ]
6+
pull_request:
7+
branches: [ "experimental-java", "java-dev" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
cache: maven
22+
23+
- name: Build with Maven
24+
run: cd java && ./mvnw -B -DskipTests -Pbug-check clean install --file pom.xml
25+
26+
- name: Run Tests
27+
run: cd java/api-test && ../mvnw -B -Pbug-check clean install --file pom.xml
28+
29+
- name: Build samples
30+
run: cd samples/java/semantickernel-samples && ../../../java/mvnw -B clean install --file pom.xml

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,5 @@ data/chatstore*
466466

467467
# Java build
468468
java/**/target
469-
java/.mvn/wrapper/maven-wrapper.jar
469+
samples/java/**/target
470+
java/.mvn/wrapper/maven-wrapper.jar

‎java/.mvn/jvm.config‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.microsoft.semantickernel.test</groupId>
9+
<artifactId>api-test</artifactId>
10+
<version>1.0.0-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>api-usage-example</artifactId>
15+
<version>1.0.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.microsoft.semantickernel</groupId>
21+
<artifactId>semantickernel-core</artifactId>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.apache.logging.log4j</groupId>
26+
<artifactId>log4j-api</artifactId>
27+
<version>2.20.0</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.apache.logging.log4j</groupId>
31+
<artifactId>log4j-core</artifactId>
32+
<version>2.20.0</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.apache.logging.log4j</groupId>
36+
<artifactId>log4j-slf4j2-impl</artifactId>
37+
<version>2.20.0</version>
38+
</dependency>
39+
</dependencies>
40+
</project>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
import com.azure.ai.openai.OpenAIClientBuilder;
3+
import com.azure.core.credential.AzureKeyCredential;
4+
import com.microsoft.openai.AzureOpenAiClient;
5+
import com.microsoft.openai.OpenAIAsyncClient;
6+
import com.microsoft.semantickernel.Kernel;
7+
import com.microsoft.semantickernel.KernelConfig;
8+
import com.microsoft.semantickernel.builders.SKBuilders;
9+
import com.microsoft.semantickernel.textcompletion.CompletionFunctionDefinition;
10+
import com.microsoft.semantickernel.textcompletion.CompletionSKContext;
11+
import com.microsoft.semantickernel.textcompletion.CompletionSKFunction;
12+
import com.microsoft.semantickernel.textcompletion.TextCompletion;
13+
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
17+
import java.io.File;
18+
import java.io.FileInputStream;
19+
import java.io.IOException;
20+
import java.util.ArrayList;
21+
import java.util.Properties;
22+
23+
public class InlineFunctionTest {
24+
public static final String AZURE_CONF_PROPERTIES = "conf.properties";
25+
26+
private static final Logger LOGGER = LoggerFactory.getLogger(InlineFunctionTest.class);
27+
28+
private static final String MODEL = "text-davinci-003";
29+
30+
public static String getToken(String configName) throws IOException {
31+
return getConfigValue(configName, "token");
32+
}
33+
34+
public static String getEndpoint(String configName) throws IOException {
35+
return getConfigValue(configName, "endpoint");
36+
}
37+
38+
private static String getConfigValue(String configName, String propertyName)
39+
throws IOException {
40+
String home = new File(System.getProperty("user.home")).getAbsolutePath();
41+
42+
try (FileInputStream fis = new FileInputStream(home + "/.oai/" + configName)) {
43+
Properties props = new Properties();
44+
props.load(fis);
45+
String apiKey = props.getProperty(propertyName);
46+
if (apiKey == null) {
47+
System.err.println("NO PROPERTY " + propertyName);
48+
return "";
49+
}
50+
return apiKey;
51+
}
52+
}
53+
54+
public static void main(String[] args) throws IOException {
55+
String apiKey = getToken(AZURE_CONF_PROPERTIES);
56+
57+
OpenAIAsyncClient client =
58+
new AzureOpenAiClient(
59+
new OpenAIClientBuilder()
60+
.endpoint(getEndpoint(AZURE_CONF_PROPERTIES))
61+
.credential(new AzureKeyCredential(apiKey))
62+
.buildAsyncClient());
63+
64+
TextCompletion textCompletion = SKBuilders.textCompletionService().build(client, MODEL);
65+
66+
KernelConfig kernelConfig =
67+
new KernelConfig.Builder()
68+
.addTextCompletionService(MODEL, kernel -> textCompletion)
69+
.build();
70+
71+
Kernel kernel = SKBuilders.kernel().setKernelConfig(kernelConfig).build();
72+
73+
String prompt = "{{$input}}\n" + "Summarize the content above.";
74+
75+
CompletionFunctionDefinition summarizeDefinition =
76+
SKBuilders.completionFunctions()
77+
.createFunction(
78+
prompt,
79+
"summarize",
80+
null,
81+
null,
82+
2000,
83+
0.2,
84+
0.5,
85+
0,
86+
0,
87+
new ArrayList<>());
88+
89+
CompletionSKFunction summarize = kernel.registerSemanticFunction(summarizeDefinition);
90+
91+
String text =
92+
"Demo (ancient Greek poet)\n"
93+
+ "From Wikipedia, the free encyclopedia\n"
94+
+ "Demo or Damo (Greek: Δεμώ, Δαμώ; fl. c. AD 200) was a Greek woman of the"
95+
+ " Roman period, known for a single epigram, engraved upon the Colossus of"
96+
+ " Memnon, which bears her name. She speaks of herself therein as a lyric"
97+
+ " poetess dedicated to the Muses, but nothing is known of her life.[1]\n"
98+
+ "Identity\n"
99+
+ "Demo was evidently Greek, as her name, a traditional epithet of Demeter,"
100+
+ " signifies. The name was relatively common in the Hellenistic world, in"
101+
+ " Egypt and elsewhere, and she cannot be further identified. The date of her"
102+
+ " visit to the Colossus of Memnon cannot be established with certainty, but"
103+
+ " internal evidence on the left leg suggests her poem was inscribed there at"
104+
+ " some point in or after AD 196.[2]\n"
105+
+ "Epigram\n"
106+
+ "There are a number of graffiti inscriptions on the Colossus of Memnon."
107+
+ " Following three epigrams by Julia Balbilla, a fourth epigram, in elegiac"
108+
+ " couplets, entitled and presumably authored by \"Demo\" or \"Damo\" (the"
109+
+ " Greek inscription is difficult to read), is a dedication to the Muses.[2]"
110+
+ " The poem is traditionally published with the works of Balbilla, though the"
111+
+ " internal evidence suggests a different author.[1]\n"
112+
+ "In the poem, Demo explains that Memnon has shown her special respect. In"
113+
+ " return, Demo offers the gift for poetry, as a gift to the hero. At the end"
114+
+ " of this epigram, she addresses Memnon, highlighting his divine status by"
115+
+ " recalling his strength and holiness.[2]\n"
116+
+ "Demo, like Julia Balbilla, writes in the artificial and poetic Aeolic"
117+
+ " dialect. The language indicates she was knowledgeable in Homeric"
118+
+ " poetry—'bearing a pleasant gift', for example, alludes to the use of that"
119+
+ " phrase throughout the Iliad and Odyssey.[a][2]\n";
120+
121+
CompletionSKContext context = summarize.invokeAsync(text).block();
122+
123+
if (context != null) {
124+
LOGGER.info("Result: " + context.getResult());
125+
} else {
126+
LOGGER.error("Null result");
127+
}
128+
}
129+
}

java/external-api-test/src/main/java/InlineFunctionWithPreBuiltSkillTest.java renamed to java/api-test/api-usage-example/src/main/java/InlineFunctionWithPreBuiltSkillTest.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright (c) Microsoft. All rights reserved.
2-
32
import com.azure.ai.openai.OpenAIClientBuilder;
43
import com.azure.core.credential.AzureKeyCredential;
54
import com.microsoft.openai.AzureOpenAiClient;
@@ -11,20 +10,22 @@
1110
import com.microsoft.semantickernel.textcompletion.CompletionSKContext;
1211
import com.microsoft.semantickernel.textcompletion.CompletionSKFunction;
1312
import com.microsoft.semantickernel.textcompletion.TextCompletion;
13+
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
16-
import reactor.core.publisher.Mono;
1716

1817
import java.io.File;
1918
import java.io.FileInputStream;
2019
import java.io.IOException;
20+
import java.rmi.RemoteException;
2121
import java.util.ArrayList;
2222
import java.util.Properties;
2323

2424
public class InlineFunctionWithPreBuiltSkillTest {
2525
public static final String AZURE_CONF_PROPERTIES = "conf.properties";
2626

27-
private static final Logger LOGGER = LoggerFactory.getLogger(InlineFunctionWithPreBuiltSkillTest.class);
27+
private static final Logger LOGGER =
28+
LoggerFactory.getLogger(InlineFunctionWithPreBuiltSkillTest.class);
2829

2930
private static final String MODEL = "text-davinci-003";
3031

@@ -85,42 +86,51 @@ private static String getConfigValue(String configName, String propertyName)
8586
public static void main(String[] args) throws IOException {
8687
String apiKey = getToken(AZURE_CONF_PROPERTIES);
8788

88-
OpenAIAsyncClient client = new AzureOpenAiClient(new OpenAIClientBuilder()
89-
.endpoint(getEndpoint(AZURE_CONF_PROPERTIES))
90-
.credential(new AzureKeyCredential(apiKey))
91-
.buildAsyncClient());
89+
OpenAIAsyncClient client =
90+
new AzureOpenAiClient(
91+
new OpenAIClientBuilder()
92+
.endpoint(getEndpoint(AZURE_CONF_PROPERTIES))
93+
.credential(new AzureKeyCredential(apiKey))
94+
.buildAsyncClient());
9295

93-
TextCompletion textCompletion = SKBuilders.textCompletionService()
94-
.build(client, MODEL);
96+
TextCompletion textCompletion = SKBuilders.textCompletionService().build(client, MODEL);
9597

9698
String prompt = "{{$input}}\nSummarize the content above.";
97-
CompletionFunctionDefinition summarizeDefinition = SKBuilders.completionFunctions()
98-
.createFunction(
99-
prompt,
100-
"summarize",
101-
null,
102-
null,
103-
2000,
104-
0.2,
105-
0.5,
106-
0,
107-
0,
108-
new ArrayList<>());
99+
CompletionFunctionDefinition summarizeDefinition =
100+
SKBuilders.completionFunctions()
101+
.createFunction(
102+
prompt,
103+
"summarize",
104+
null,
105+
null,
106+
2000,
107+
0.2,
108+
0.5,
109+
0,
110+
0,
111+
new ArrayList<>());
109112

110113
KernelConfig kernelConfig =
111114
new KernelConfig.Builder()
112115
.addTextCompletionService(MODEL, kernel -> textCompletion)
113116
.addSkill(summarizeDefinition)
114117
.build();
115118

116-
Kernel kernel = SKBuilders.kernel()
117-
.setKernelConfig(kernelConfig)
118-
.build();
119+
Kernel kernel = SKBuilders.kernel().setKernelConfig(kernelConfig).build();
119120

120-
CompletionSKFunction summarize = kernel.getSkillCollection().getFunction("summarize", CompletionSKFunction.class);
121+
CompletionSKFunction summarize =
122+
kernel.getSkillCollection().getFunction("summarize", CompletionSKFunction.class);
121123

122-
Mono<CompletionSKContext> result = summarize.invokeAsync(TEXT_TO_SUMMARIZE);
124+
if (summarize == null) {
125+
throw new RemoteException("No function");
126+
}
123127

124-
LOGGER.info("Result: " + result.block().getResult());
128+
CompletionSKContext context = summarize.invokeAsync(TEXT_TO_SUMMARIZE).block();
129+
130+
if (context != null) {
131+
LOGGER.info("Result: " + context.getResult());
132+
} else {
133+
LOGGER.error("Null result");
134+
}
125135
}
126136
}

java/external-api-test/src/main/resources/log4j2.xml renamed to java/api-test/api-usage-example/src/main/resources/log4j2.xml

File renamed without changes.

0 commit comments

Comments
 (0)