Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Example14_SemanticMemory #1355

Merged
merged 23 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
034aee8
progress on VolatileMemoryStoreTests
dsgrieve May 26, 2023
31e4aab
Complete port of VolatileMemoryStoreTests
dsgrieve May 30, 2023
868342c
codestyle formatting
dsgrieve May 30, 2023
e727cad
add connectors/memory/azurecognitivesearch - compiles, not tested
dsgrieve Jun 1, 2023
f4b0f6f
Java Semantic Kernel CI (#1193)
Luigi96 Jun 2, 2023
676df77
Java - Add module to allow dependency injection via guice (#1199)
johnoliver Jun 2, 2023
1fb4009
Java: VolatileMemoryStoreTests (#1246)
dsgrieve Jun 2, 2023
842184f
Java Format (#1304)
Luigi96 Jun 2, 2023
e86c1b4
Progress on Example14_SemanticMemory
dsgrieve Jun 2, 2023
61c89cd
Merge branch 'experimental-java' of github.com:dsgrieve/semantic-kern…
dsgrieve Jun 2, 2023
4b6abba
Basically working AzureCognitiveSearchMemory and Example14_SemanticMe…
dsgrieve Jun 6, 2023
cea08a0
spotbugs
dsgrieve Jun 6, 2023
6e9c45d
Merge remote-tracking branch 'refs/remotes/origin/experimental-java' …
dsgrieve Jun 7, 2023
93c7ce5
Merge branch 'experimental-java' of github.com:dsgrieve/semantic-kern…
dsgrieve Jun 7, 2023
b1c3312
Example14_SemanticMemory
dsgrieve Jun 15, 2023
32ef833
Merge branch 'experimental-java' into dsgrieve/memory-samples
dsgrieve Jun 20, 2023
1a69004
Address comments in PR 1355
dsgrieve Jun 20, 2023
0ec3d8a
Merge branch 'dsgrieve/memory-samples' of github.com:dsgrieve/semanti…
dsgrieve Jun 20, 2023
aacc736
Merge branch 'experimental-java' into dsgrieve/memory-samples
dsgrieve Jun 21, 2023
9d2e93f
Address minor difference between java and c# implementation
dsgrieve Jun 21, 2023
470686a
Merge branch 'dsgrieve/memory-samples' of github.com:dsgrieve/semanti…
dsgrieve Jun 21, 2023
77ba08e
add mention of azure-sdk issue 35584 which prevents us from using Fie…
dsgrieve Jun 22, 2023
251b332
Javadoc public API in AzureCognitiveSearchMemory.java
dsgrieve Jun 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.e2e;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.junit.jupiter.api.condition.EnabledIf;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.NonAzureOpenAIKeyCredential;
Expand All @@ -18,6 +11,12 @@
import com.microsoft.semantickernel.connectors.ai.openai.textcompletion.OpenAITextCompletion;
import com.microsoft.semantickernel.memory.VolatileMemoryStore;
import com.microsoft.semantickernel.textcompletion.TextCompletion;
import org.junit.jupiter.api.condition.EnabledIf;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

@EnabledIf("isAzureTestEnabled")
public class AbstractKernelTest {
Expand All @@ -27,10 +26,14 @@ public class AbstractKernelTest {

public static Kernel buildTextCompletionKernel() throws IOException {
String model = "text-davinci-003";
TextCompletion textCompletion = new OpenAITextCompletion(getAzureOpenAIClient(), model);
final OpenAIAsyncClient openAIClient = getAzureOpenAIClient();
TextCompletion textCompletion = new OpenAITextCompletion(openAIClient, model);

KernelConfig kernelConfig = SKBuilders.kernelConfig()
.addTextCompletionService(model, kernel -> textCompletion)
.addTextEmbeddingsGenerationService(
model,
kernel -> SKBuilders.textEmbeddingGenerationService().build(openAIClient, model))
.build();

return SKBuilders.kernel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public void testEmbeddingGeneration() throws IOException {
LOGGER.info(String.valueOf(embeddingGeneration.generateEmbeddingsAsync(data).block()));
}

@Test
@EnabledIf("isAzureTestEnabled")
public void testMemory() throws IOException {
@Test
@EnabledIf("isAzureTestEnabled")
public void testMemory() throws IOException {

Kernel kernel = buildTextCompletionKernel();
kernel.importSkill(new TextMemorySkill(), "aboutMe");
Expand Down Expand Up @@ -96,8 +96,8 @@ public void testMemory() throws IOException {
kernel.getSkills());

context.getSemanticMemory()
.saveInformationAsync("aboutMe", "My name is Andrea", "fact1", null, null)
.block();
.saveInformationAsync("aboutMe", "My name is Andrea", "fact1", null, null)
.block();

context.getSemanticMemory()
.saveInformationAsync(
Expand Down
107 changes: 2 additions & 105 deletions java/samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
<log4j2.version>2.20.0</log4j2.version>
<maven.compiler-plugin.version>3.11.0</maven.compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
Expand All @@ -34,108 +35,4 @@
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.release}</source>
<target>${maven.compiler.release}</target>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.microsoft.semantickernel</groupId>
<artifactId>semantickernel-api</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.semantickernel.connectors</groupId>
<artifactId>semantickernel-connectors</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.semantickernel</groupId>
<artifactId>semantickernel-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.microsoft.semantickernel</groupId>
<artifactId>semantickernel-core-skills</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.semantickernel.extensions</groupId>
<artifactId>sequentialplanner-extensions</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>bug-check</id>

<activation>
<activeByDefault>false</activeByDefault>
</activation>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.release}</source>
<target>${maven.compiler.release}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>

<!-- Remove exclusions when more project is stable -->
<arg>-Xplugin:ErrorProne
-XepOpt:NullAway:AnnotatedPackages=com.microsoft.semantickernel
-Xep:AlmostJavadoc:OFF -Xep:MissingSummary:OFF
-Xep:UnusedVariable:OFF -Xep:EmptyBlockTag:OFF
</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${google.errorprone.core.version}</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${com.uber.nullaway.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
15 changes: 14 additions & 1 deletion java/samples/sample-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<dependency>
<groupId>com.microsoft.semantickernel</groupId>
<artifactId>semantickernel-core</artifactId>
<scope>runtime</scope>
<!-- TODO: scope should be runtime, but VolatileMemoryStore is an issue -->
<!-- <scope>runtime</scope> -->
</dependency>
<dependency>
<groupId>com.microsoft.semantickernel</groupId>
Expand Down Expand Up @@ -54,5 +55,17 @@
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel;

import java.io.IOException;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.NonAzureOpenAIKeyCredential;
Expand All @@ -11,16 +9,18 @@
import com.microsoft.semantickernel.util.AzureOpenAISettings;
import com.microsoft.semantickernel.util.OpenAISettings;

import java.io.IOException;

public class Config {

public static final String CONF_PROPERTIES = "java/samples/conf.properties";
public static final String CONF_PROPERTIES =
System.getProperty("CONF_PROPERTIES", "java/samples/conf.properties");

public enum ClientType {
OPEN_AI {
@Override
public OpenAIAsyncClient getClient() throws IOException {
OpenAISettings settings = AIProviderSettings.getOpenAISettingsFromFile(CONF_PROPERTIES);

return new OpenAIClientBuilder()
.credential(new NonAzureOpenAIKeyCredential(settings.getKey()))
.buildAsyncClient();
Expand All @@ -32,16 +32,13 @@ public OpenAIAsyncClient getClient()
throws IOException {
AzureOpenAISettings settings = AIProviderSettings.getAzureOpenAISettingsFromFile(CONF_PROPERTIES);

return new OpenAIClientBuilder().endpoint(settings.getEndpoint())
.credential(new AzureKeyCredential(settings.getKey())).buildAsyncClient();
return new OpenAIClientBuilder()
.endpoint(settings.getEndpoint())
.credential(new AzureKeyCredential(settings.getKey()))
.buildAsyncClient();
}
};

/**
* Returns the client that will handle AzureOpenAI or OpenAI requests.
*
* @return client to be used by the kernel.
*/
public abstract OpenAIAsyncClient getClient() throws IOException;
}
}
Loading