Merge branch 'java-v1' of github.com:microsoft/semantic-kernel into dsgrieve/v1-javadoc

This commit is contained in:
David Grieve
2024-02-14 13:02:51 -05:00
39 changed files with 216 additions and 230 deletions
+12 -5
View File
@@ -7,12 +7,12 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>aiservices-openai</artifactId>
<name>OpenAI Services</name>
<artifactId>semantickernel-aiservices-openai</artifactId>
<name>Semantic Kernel OpenAI Services</name>
<description>OpenAI services for Semantic Kernel</description>
<dependencies>
@@ -39,10 +39,17 @@
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
@@ -0,0 +1,50 @@
package com.microsoft.semantickernel.aiservices.openai;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.rest.RequestOptions;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
public final class OpenAIRequestSettings {
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(
OpenAIRequestSettings.class);
private static final String SEMANTIC_KERNEL_VERSION_PROPERTY_NAME = "semantic-kernel.version";
private static final String SEMANTIC_KERNEL_VERSION_PROPERTIES_FILE = "semantic-kernel-version.properties";
private static final String version;
static {
version = loadVersion();
}
private static String loadVersion() {
String version = "Java/unknown";
try (InputStream settingsFile = OpenAIRequestSettings.class.getResourceAsStream(
SEMANTIC_KERNEL_VERSION_PROPERTIES_FILE)) {
Properties props = new Properties();
props.load(settingsFile);
if (props.containsKey(SEMANTIC_KERNEL_VERSION_PROPERTY_NAME)) {
String skVersion = props.getProperty(SEMANTIC_KERNEL_VERSION_PROPERTY_NAME);
if (skVersion != null && !skVersion.isEmpty()) {
return "Java/" + skVersion;
}
}
} catch (IOException e) {
//Ignore
LOGGER.trace("Failed to load Semantic Kernel version from properties file", e);
}
return version;
}
public static RequestOptions getRequestOptions() {
return new RequestOptions()
.setHeader(HttpHeaderName.fromString("Semantic-Kernel-Version"), version);
}
}
@@ -21,12 +21,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.semantickernel.Kernel;
import com.microsoft.semantickernel.aiservices.openai.OpenAIRequestSettings;
import com.microsoft.semantickernel.chatcompletion.AuthorRole;
import com.microsoft.semantickernel.chatcompletion.ChatCompletionService;
import com.microsoft.semantickernel.chatcompletion.ChatHistory;
import com.microsoft.semantickernel.chatcompletion.ChatMessageContent;
import com.microsoft.semantickernel.chatcompletion.StreamingChatMessageContent;
import com.microsoft.semantickernel.exceptions.AIException;
import com.microsoft.semantickernel.exceptions.AIException.ErrorCodes;
import com.microsoft.semantickernel.exceptions.SKException;
import com.microsoft.semantickernel.hooks.KernelHooks;
import com.microsoft.semantickernel.hooks.PreChatCompletionEvent;
@@ -165,7 +167,15 @@ public class OpenAIChatCompletion implements ChatCompletionService {
.getOptions();
return client
.getChatCompletions(getModelId(), options)
.getChatCompletionsWithResponse(getModelId(), options,
OpenAIRequestSettings.getRequestOptions())
.flatMap(completionsResult -> {
if (completionsResult.getStatusCode() >= 400) {
return Mono.error(new AIException(ErrorCodes.SERVICE_ERROR,
"Request failed: " + completionsResult.getStatusCode()));
}
return Mono.just(completionsResult.getValue());
})
.filter(choices -> choices.getChoices() != null && !choices.getChoices().isEmpty())
.map(this::accumulateResponses)
.map(responses ->
@@ -438,7 +448,7 @@ public class OpenAIChatCompletion implements ChatCompletionService {
}
private static FunctionDefinition toFunctionDefinition(KernelFunction function) {
String name = String.format("%s-%s", function.getSkillName(), function.getName());
String name = String.format("%s-%s", function.getPluginName(), function.getName());
FunctionDefinition functionDefinition = new FunctionDefinition(name);
functionDefinition.setDescription(function.getDescription());
// Example JSON Schema:
@@ -4,7 +4,9 @@ import com.azure.ai.openai.OpenAIAsyncClient;
import com.azure.ai.openai.models.CompletionsOptions;
import com.azure.ai.openai.models.CompletionsUsage;
import com.microsoft.semantickernel.Kernel;
import com.microsoft.semantickernel.aiservices.openai.OpenAIRequestSettings;
import com.microsoft.semantickernel.exceptions.AIException;
import com.microsoft.semantickernel.exceptions.AIException.ErrorCodes;
import com.microsoft.semantickernel.orchestration.FunctionResultMetadata;
import com.microsoft.semantickernel.orchestration.PromptExecutionSettings;
import com.microsoft.semantickernel.orchestration.contextvariables.ContextVariable;
@@ -90,9 +92,16 @@ public class OpenAITextGenerationService implements TextGenerationService {
CompletionsOptions completionsOptions = getCompletionsOptions(text, requestSettings);
return client
.getCompletions(getModelId(), completionsOptions)
.getCompletionsWithResponse(getModelId(), completionsOptions,
OpenAIRequestSettings.getRequestOptions())
.flatMap(completionsResult -> {
if (completionsResult.getStatusCode() >= 400) {
return Mono.error(new AIException(ErrorCodes.SERVICE_ERROR,
"Request failed: " + completionsResult.getStatusCode()));
}
return Mono.just(completionsResult.getValue());
})
.map(completions -> {
FunctionResultMetadata metadata = FunctionResultMetadata.build(
completions.getId(),
completions.getUsage(),
@@ -0,0 +1 @@
semantic-kernel.version=${project.version}
+3 -7
View File
@@ -7,17 +7,18 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>api-test</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Semantic Kernel Integration Tests</name>
<artifactId>integration-tests</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sample-code</artifactId>
<artifactId>semantickernel-sample-code</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
@@ -56,11 +57,6 @@
<artifactId>semantickernel-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sample-code</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
@@ -10,7 +10,7 @@ public class Example01NativeFunctionsTest {
@Test
public void run() {
// Load native skill
// Load native plugin
TextPlugin text = new TextPlugin();
// Use function without kernel
@@ -20,7 +20,7 @@ public class Example03_ArgumentsTest {
public void main() {
Kernel kernel = Kernel.builder().build();
// Load native skill
// Load native plugin
KernelPlugin functionCollection =
KernelPluginFactory.createFromObject(new StaticTextPlugin(), "text");
+9 -1
View File
@@ -7,10 +7,11 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>Semantic Kernel Api Tests</name>
<artifactId>api-test</artifactId>
<packaging>pom</packaging>
@@ -50,6 +51,13 @@
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
@@ -19,13 +20,8 @@
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>compile</scope>
@@ -34,7 +30,7 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>compile</scope>
</dependency>
</dependency>
</dependencies>
</project>
@@ -6,7 +6,7 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
@@ -6,7 +6,7 @@ import com.microsoft.semantickernel.plugin.annotations.KernelFunctionParameter;
import java.util.Locale;
/**
* TextSkill provides a set of functions to manipulate strings.
* TextPlugin provides a set of functions to manipulate strings.
*/
public class TextPlugin {
+5 -40
View File
@@ -7,8 +7,9 @@
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<packaging>pom</packaging>
<url>https://www.github.com/microsoft/semantic-kernel</url>
<name>Semantic Kernel Parent</name>
<description>Parent pom for the Semantic Kernel Project</description>
@@ -65,25 +66,14 @@
</properties>
<modules>
<module>semantickernel-bom</module>
<module>connectors/semantickernel-connectors-web-bing</module>
<!-- <module>connectors/semantickernel-connectors-ai-openai</module>-->
<!-- <module>connectors/semantickernel-connectors-memory-sqlite</module>-->
<!-- <module>connectors/semantickernel-connectors-memory-azurecognitivesearch</module>-->
<!-- <module>connectors/semantickernel-connectors-memory-jdbc</module>-->
<!-- <module>connectors/semantickernel-connectors-memory-postgresql</module>-->
<!-- <module>connectors/semantickernel-connectors-memory-mysql</module>-->
<!-- <module>aiservices/huggingface</module>-->
<!-- <module>aiservices/ollama</module>-->
<module>aiservices/openai</module>
<!-- <module>misc/semantickernel-gpt3-tokenizer</module>-->
<!-- <module>misc/semantickernel-settings-loader</module>-->
<!-- <module>plugins/semantickernel-planners</module>-->
<module>plugins/semantickernel-plugin-core</module>
<module>semantickernel-bom</module>
<module>semantickernel-api</module>
</modules>
@@ -403,17 +393,6 @@
</execution>
</executions>
<configuration>
<!--
LATEST: Android API level 32 (Android 12)
See https://developer.android.com/studio/releases/platforms
-->
<!--
<signature>
<groupId>net.sf.androidscents.signature</groupId>
<artifactId>android-api-level-32</artifactId>
<version>12_r1</version>
</signature>
-->
<!--
COMPATIBLE: Android API level 26 (Android 8.0)
See https://developer.android.com/studio/releases/platforms
@@ -425,17 +404,6 @@
<artifactId>android-api-level-26</artifactId>
<version>8.0.0_r2</version>
</signature>
<!--
Android API level 21 (Android 5.0)
See https://developer.android.com/studio/releases/platforms
-->
<!--
<signature>
<groupId>net.sf.androidscents.signature</groupId>
<artifactId>android-api-level-21</artifactId>
<version>5.0.1_r2</version>
</signature>
-->
</configuration>
</plugin>
</plugins>
@@ -619,9 +587,6 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<!-- <modules>
<module>samples</module>
</modules> -->
</profile>
<profile>
<id>bug-check</id>
@@ -819,6 +784,6 @@
<url>https://github.com/microsoft/semantic-kernel</url>
<connection>scm:git:https://github.com/microsoft/semantic-kernel.git</connection>
<developerConnection>scm:git:https://github.com/microsoft/semantic-kernel.git</developerConnection>
<tag>java-0.2.11-alpha</tag>
<tag>HEAD</tag>
</scm>
</project>
+10 -5
View File
@@ -5,19 +5,17 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<artifactId>semantickernel-samples-parent</artifactId>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Semantic Kernel Samples Parent</name>
<description>Parent pom for sample code for using the Semantic Kernel project</description>
<modules>
<!-- <module>semantickernel-samples-guice</module> -->
<module>sk-v1</module>
<module>sample-code</module>
</modules>
@@ -104,6 +102,13 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
+4 -4
View File
@@ -4,12 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<artifactId>semantickernel-samples-parent</artifactId>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sample-code</artifactId>
<artifactId>semantickernel-sample-code</artifactId>
<name>Semantic Kernel Samples</name>
<description>Sample code for using the Semantic Kernel project</description>
<packaging>jar</packaging>
@@ -71,7 +71,7 @@
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-openai</artifactId>
<artifactId>semantickernel-aiservices-openai</artifactId>
</dependency>
</dependencies>
@@ -11,49 +11,6 @@ import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;
/**
* Description: TimeSkill provides a set of functions to get the current time and date.
*
* <p>Usage: kernel.importSkill(new TimeSkill(), "time");
*
* <p>Examples:
*
* <p>{{time.date}} => Sunday, 12 January, 2031
*
* <p>{{time.today}} => Sunday, 12 January, 2031
*
* <p>{{time.now}} => Sunday, January 12, 2031 9:15 PM
*
* <p>{{time.utcNow}} => Sunday, January 13, 2031 5:15 AM
*
* <p>{{time.time}} => 09:15:07 PM
*
* <p>{{time.year}} => 2031
*
* <p>{{time.month}} => January
*
* <p>{{time.monthNumber}} => 01
*
* <p>{{time.day}} => 12
*
* <p>{{time.dayOfWeek}} => Sunday
*
* <p>{{time.hour}} => 9 PM
*
* <p>{{time.hourNumber}} => 21
*
* <p>{{time.days_ago $days}} => Sunday, 7 May, 2023
*
* <p>{{time.last_matching_day $dayName}} => Sunday, 7 May, 2023
*
* <p>{{time.minute}} => 15
*
* <p>{{time.second}} => 7
*
* <p>{{time.timeZoneOffset}} => -08:00
*
* <p>{{time.timeZoneName}} => Pacific Time
*/
public class TimePlugin {
public static final String DAY_MONTH_DAY_YEAR = "EEEE, MMMM d, yyyy";
@@ -3,7 +3,7 @@ package com.microsoft.semantickernel.samples.syntaxexamples;
import com.microsoft.semantickernel.plugins.text.TextPlugin;
/**
* Demonstrates a native function from the {@code com.microsoft.semantickernel.coreskills} package.
* Demonstrates a native function.
*/
public class Example01_NativeFunctions {
@@ -48,7 +48,7 @@ public class Example03_Arguments {
public static void main(String[] args) {
Kernel kernel = Kernel.builder().build();
// Load native skill
// Load native plugin
KernelPlugin functionCollection =
KernelPluginFactory.createFromObject(new StaticTextPlugin(), "text");
@@ -19,7 +19,7 @@ import com.sun.jna.StringArray;
import reactor.core.publisher.Mono;
/**
* Demonstrate the {@code com.microsoft.semantickernel.coreskills.ConversationSummarySkill}
* Demonstrate the {@see com.microsoft.semantickernel.samples.plugins.ConversationSummaryPlugin} plugin.
* <p>
* Refer to the <a href=
* "https://github.com/microsoft/semantic-kernel/blob/experimental-java/java/samples/sample-code/README.md">
+2 -2
View File
@@ -6,8 +6,8 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<artifactId>semantickernel-v1-samples</artifactId>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
+2 -2
View File
@@ -7,8 +7,8 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<artifactId>semantickernel-v1-samples</artifactId>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
+2 -2
View File
@@ -7,8 +7,8 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<artifactId>semantickernel-v1-samples</artifactId>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<artifactId>semantickernel-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
+3 -3
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<artifactId>semantickernel-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-openai</artifactId>
<artifactId>semantickernel-aiservices-openai</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
@@ -30,7 +30,7 @@
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-openai</artifactId>
<artifactId>semantickernel-aiservices-openai</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<artifactId>semantickernel-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
+10 -5
View File
@@ -3,9 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>sk-v1-samples</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-samples-parent</artifactId>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>semantickernel-v1-samples</artifactId>
<name>Semantic Kernel version 1 Samples</name>
<description>Sample code for using the Semantic Kernel version 1 API</description>
@@ -47,7 +52,7 @@
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-openai</artifactId>
<artifactId>semantickernel-aiservices-openai</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
@@ -59,7 +64,7 @@
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-openai</artifactId>
<artifactId>semantickernel-aiservices-openai</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
+7 -6
View File
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -50,6 +51,10 @@
<artifactId>jackson-dataformat-yaml</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -66,9 +71,5 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
</dependency>
</dependencies>
</project>
@@ -109,7 +109,7 @@ public class DefaultKernel implements Kernel {
@Override
public CompletionKernelFunction registerSemanticFunction(
String skillName, String functionName, SemanticFunctionConfig functionConfig) {
String pluginName, String functionName, SemanticFunctionConfig functionConfig) {
// Future-proofing the name not to contain special chars
// Verify.ValidSkillName(skillName);
// Verify.ValidFunctionName(functionName);
@@ -117,7 +117,7 @@ public class DefaultKernel implements Kernel {
return SKBuilders.completionFunctions()
.withSemanticFunctionConfig(functionConfig)
.withFunctionName(functionName)
.withSkillName(skillName)
.withPluginName(pluginName)
.withKernel(this)
.build();
}
@@ -13,7 +13,19 @@ import java.util.function.Predicate;
* in a particular event, and a {@code Function} that can be used to modify the event. The
* @param <T> The type of the event that the hook is interested in
*/
public interface KernelHook<T extends KernelHookEvent> extends Predicate<KernelHookEvent>, Function<T, T> {
public interface KernelHook<T extends KernelHookEvent> extends Predicate<KernelHookEvent>,
Function<T, T> {
/**
* The priority of the hook. The default priority is 50. The priority is used to determine the
* order in which hooks that accept the same event type are executed, lower priorities are executed first. No ordering is
* guaranteed for hooks with the same priority.
*
* @return the priority of the hook
*/
default int getPriority() {
return 50;
}
/**
* A hook that accepts {@link FunctionInvokingEvent}
@@ -7,8 +7,11 @@ import com.microsoft.semantickernel.hooks.KernelHook.PromptRenderedHook;
import com.microsoft.semantickernel.hooks.KernelHook.PromptRenderingHook;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID;
import java.util.function.Function;
@@ -124,7 +127,11 @@ public class KernelHooks {
*/
@SuppressWarnings("unchecked")
public <T extends KernelHookEvent> T executeHooks(T event) {
for (KernelHook<?> hook : hooks.values()) {
SortedSet<KernelHook<?>> hooks = new TreeSet<>(Comparator.comparingInt(KernelHook::getPriority));
hooks.addAll(this.hooks.values());
for (KernelHook<?> hook : hooks) {
if (hook.test(event)) {
// unchecked cast
event = ((KernelHook<T>) hook).apply(event);
@@ -188,33 +195,38 @@ public class KernelHooks {
* A wrapper for KernelHooks that disables mutating methods.
*/
public static class UnmodifiableKernelHooks extends KernelHooks {
private UnmodifiableKernelHooks(KernelHooks kernelHooks) {
super(kernelHooks);
}
@Override
public String addFunctionInvokingHook(Function<FunctionInvokingEvent<?>, FunctionInvokingEvent<?>> function) {
public String addFunctionInvokingHook(
Function<FunctionInvokingEvent<?>, FunctionInvokingEvent<?>> function) {
throw new UnsupportedOperationException("unmodifiable instance of KernelHooks");
}
@Override
public String addFunctionInvokedHook(Function<FunctionInvokedEvent<?>, FunctionInvokedEvent<?>> function) {
public String addFunctionInvokedHook(
Function<FunctionInvokedEvent<?>, FunctionInvokedEvent<?>> function) {
throw new UnsupportedOperationException("unmodifiable instance of KernelHooks");
}
@Override
public String addPreChatCompletionHook(Function<PreChatCompletionEvent, PreChatCompletionEvent> function) {
public String addPreChatCompletionHook(
Function<PreChatCompletionEvent, PreChatCompletionEvent> function) {
throw new UnsupportedOperationException("unmodifiable instance of KernelHooks");
}
@Override
public String addPromptRenderedHook(Function<PromptRenderedEvent, PromptRenderedEvent> function) {
public String addPromptRenderedHook(
Function<PromptRenderedEvent, PromptRenderedEvent> function) {
throw new UnsupportedOperationException("unmodifiable instance of KernelHooks");
}
@Override
public String addPromptRenderingHook(Function<PromptRenderingEvent, PromptRenderingEvent> function) {
public String addPromptRenderingHook(
Function<PromptRenderingEvent, PromptRenderingEvent> function) {
throw new UnsupportedOperationException("unmodifiable instance of KernelHooks");
}
@@ -17,6 +17,7 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import reactor.core.CoreSubscriber;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SynchronousSink;
@@ -50,6 +51,7 @@ public class FunctionInvocation<T> extends Mono<FunctionResult<T>> {
* @param kernel The kernel to invoke the function on.
* @param function The function to invoke.
*/
@SuppressFBWarnings("EI_EXPOSE_REP2")
public FunctionInvocation(
Kernel kernel,
KernelFunction<T> function) {
@@ -65,6 +67,7 @@ public class FunctionInvocation<T> extends Mono<FunctionResult<T>> {
* @param function The function to invoke.
* @param resultType The type of the result of the function invocation.
*/
@SuppressFBWarnings("EI_EXPOSE_REP2")
public FunctionInvocation(
Kernel kernel,
KernelFunction<?> function,
@@ -238,7 +241,7 @@ public class FunctionInvocation<T> extends Mono<FunctionResult<T>> {
if (variableType == null) {
LOGGER.debug(
"No variable type explicitly specified by calling 'withResultType' for function invocation: "
+ function.getSkillName() + "." + function.getName() + "."
+ function.getPluginName() + "." + function.getName() + "."
+ " This may cause a runtime error (probably a ClassCastException) if the result type is not compatible with the expected type.");
}
@@ -58,9 +58,9 @@ public abstract class KernelFunction<T> implements Buildable {
}
/**
* @return The name of the skill that this function is within
* @return The name of the plugin that this function is within
*/
public String getSkillName() {
public String getPluginName() {
return metadata.getName();
}
@@ -29,7 +29,7 @@ public class ToolCallBehavior {
}
static String getKey(KernelFunction<?> function) {
return getKey(function.getSkillName(), function.getName());
return getKey(function.getPluginName(), function.getName());
}
static String getKey(String skillName, String functionName) {
@@ -187,7 +187,7 @@ public class ToolCallBehavior {
*/
public boolean functionRequired(KernelFunction<?> function) {
if (function != null) {
return functionRequired(function.getSkillName(), function.getName());
return functionRequired(function.getPluginName(), function.getName());
}
return false;
}
@@ -214,7 +214,7 @@ public class ToolCallBehavior {
public boolean functionEnabled(KernelFunction<?> function) {
if (function != null) {
return functionEnabled(function.getSkillName(), function.getName());
return functionEnabled(function.getPluginName(), function.getName());
}
return functionSettings.isEmpty();
}
@@ -320,7 +320,7 @@ public class KernelPluginFactory {
} catch (IOException e) {
LOGGER.error("Failed to read file " + promptFileName, e);
throw new SKException("No Skills found in directory " + promptFileName);
throw new SKException("No plugins found in directory " + promptFileName);
}
}
@@ -244,7 +244,7 @@ public class KernelFunctionFromMethod<T> extends KernelFunction<T> {
if (!variableType.getClazz().isAssignableFrom(it.getClass())) {
throw new SKException(String.format(
"Return parameter type from %s.%s does not match the expected type %s",
function.getSkillName(), function.getName(),
function.getPluginName(), function.getName(),
it.getClass().getName()));
}
return new FunctionResult<>(
@@ -276,7 +276,7 @@ public class KernelFunctionFromMethod<T> extends KernelFunction<T> {
// If we get here, then either the returnParameterType doesn't match T
throw new SKException(String.format(
"Return parameter type from %s.%s does not match the expected type %s",
function.getSkillName(), function.getName(), it.getClass().getName()));
function.getPluginName(), function.getName(), it.getClass().getName()));
})
.map(it -> {
@@ -302,7 +302,7 @@ public class KernelFunctionFromPrompt<T> extends KernelFunction<T> {
"Something went wrong while rendering the semantic"
+ " function or while executing the text"
+ " completion. Function: {}.{}. Error: {}",
getSkillName(),
getPluginName(),
getName(),
ex.getMessage());
@@ -16,7 +16,7 @@ import com.microsoft.semantickernel.plugin.KernelParameterMetadata;
import com.microsoft.semantickernel.plugin.KernelPlugin;
import com.microsoft.semantickernel.semanticfunctions.PromptTemplate;
import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -27,11 +27,8 @@ import java.util.Locale;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import reactor.core.publisher.Mono;
/**
@@ -109,7 +106,7 @@ public class HandlebarsPromptTemplate implements PromptTemplate {
if (context instanceof KernelFunction) {
KernelFunction<?> function = (KernelFunction<?>) context;
if ("pluginname".equalsIgnoreCase(name)) {
return function.getSkillName();
return function.getPluginName();
} else if ("name".equalsIgnoreCase(name)) {
return function.getName();
}
@@ -192,7 +189,7 @@ public class HandlebarsPromptTemplate implements PromptTemplate {
private static Handlebars.SafeString handleFunction(KernelFunction<?> context) {
KernelFunction<?> function = context;
String pluginName = function.getSkillName();
String pluginName = function.getPluginName();
String functionName = function.getName();
String description = function.getDescription();
StringBuilder sb = new StringBuilder(
@@ -24,7 +24,7 @@ public final class FunctionIdBlock extends Block implements TextRendering {
String[] functionNameParts = this.getContent().split("\\.", -1);
if (functionNameParts.length > 2) {
throw new RuntimeException(
"A function name can contain at most one dot separating the skill name from the"
"A function name can contain at most one dot separating the plugin name from the"
+ " function name");
}
+9 -57
View File
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-bom</artifactId>
<version>1.0.0-alpha.1-SNAPSHOT</version>
<version>1.0.0-alpha.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Semantic Kernel Java BOM</name>
@@ -48,19 +49,6 @@
<artifactId>semantickernel-api</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-connectors-ai-openai</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-planners</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-gpt3-tokenizer</artifactId>
@@ -76,28 +64,6 @@
<artifactId>semantickernel-connectors-web-bing</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-connectors-memory-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-connectors-memory-sqlite</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-connectors-memory-postgresql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-connectors-memory-azurecognitivesearch</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-azureopenai</artifactId>
@@ -115,7 +81,7 @@
</dependency>
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>aiservices-openai</artifactId>
<artifactId>semantickernel-aiservices-openai</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -134,13 +100,6 @@
<artifactId>azure-identity</artifactId>
<version>1.11.2</version>
</dependency>
<!-- dependency for semantickernel-connectors-memory-azurecognitivesearch
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-search-documents</artifactId>
<version>11.6.0-beta.9</version>
</dependency>
-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
@@ -190,20 +149,13 @@
<version>3.0.2</version>
</dependency>
<!-- dependencies for memory connectors
<!-- Required for Android -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.42.0.0</version>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
-->
</dependencies>
</dependencyManagement>