mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
Java: Move samples to new package; Add jbang support (#2026)
- Fixes the template of `conf.properties` to not have quotes; - Moves samples to a sub package to avoid conflict when running `jbang` - Adds `jbang` support to execute the samples from command line
This commit is contained in:
+1
-1
@@ -44,7 +44,7 @@ public class AbstractKernelTest {
|
||||
}
|
||||
|
||||
public static OpenAIAsyncClient getOpenAIClient() throws IOException {
|
||||
return com.microsoft.semantickernel.Config.getClient();
|
||||
return com.microsoft.semantickernel.samples.Config.getClient();
|
||||
}
|
||||
|
||||
public static String getOpenAIModel() throws IOException {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
client.openai.key: "OPEN_AI_KEY"
|
||||
client.openai.organizationid: "OPEN_AI_ORGANIZATION_ID"
|
||||
client.openai.key=OPEN_AI_KEY
|
||||
client.openai.organizationid=OPEN_AI_ORGANIZATION_ID
|
||||
|
||||
client.azureopenai.key: "AZURE_OPEN_AI_KEY"
|
||||
client.azureopenai.endpoint: "AZURE_OPEN_AI_ENDPOINT"
|
||||
client.azureopenai.deploymentname: "AZURE_OPEN_AI_DEPLOYMENT_NAME"
|
||||
client.azureopenai.key=AZURE_OPEN_AI_KEY
|
||||
client.azureopenai.endpoint=AZURE_OPEN_AI_ENDPOINT
|
||||
client.azureopenai.deploymentname=AZURE_OPEN_AI_DEPLOYMENT_NAME
|
||||
|
||||
Regular → Executable
+7
-2
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel;
|
||||
package com.microsoft.semantickernel.samples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.azure.ai.openai.OpenAIClientBuilder;
|
||||
@@ -11,6 +11,7 @@ import com.microsoft.semantickernel.connectors.ai.openai.util.ClientSettings;
|
||||
import com.microsoft.semantickernel.connectors.ai.openai.util.OpenAISettings;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -25,7 +26,7 @@ public class Config {
|
||||
|
||||
private static final List<String> DEFAULT_PROPERTIES_LOCATIONS = Arrays.asList(
|
||||
"java/samples/conf.properties",
|
||||
System.getProperty("user.home") + "/.sk/conf.properties"
|
||||
System.getProperty("user.home") + File.separator + ".sk" + File.separator + "conf.properties"
|
||||
);
|
||||
|
||||
public static final String CONF_PROPERTIES = getEnvOrProperty("CONF_PROPERTIES", "java/samples/conf.properties");
|
||||
@@ -65,8 +66,10 @@ public class Config {
|
||||
|
||||
private static Supplier<ClientSettings<?>> getOpenAIClientFromDefaultPropertiesLocations(ClientType type) {
|
||||
return () -> {
|
||||
LOGGER.debug("Create supplier for settings of " + type);
|
||||
try {
|
||||
for (String location : DEFAULT_PROPERTIES_LOCATIONS) {
|
||||
LOGGER.debug("Attempting config file at "+location);
|
||||
if (Files.isRegularFile(Path.of(location))) {
|
||||
return switch (type) {
|
||||
case OPEN_AI -> AIProviderSettings.getOpenAISettingsFromFile(location);
|
||||
@@ -89,6 +92,7 @@ public class Config {
|
||||
public OpenAIAsyncClient getClient() throws IOException {
|
||||
return buildClient(
|
||||
() -> {
|
||||
LOGGER.debug("Loading AI provider settings from "+CONF_PROPERTIES);
|
||||
try {
|
||||
return AIProviderSettings.getOpenAISettingsFromFile(CONF_PROPERTIES);
|
||||
} catch (IOException e) {
|
||||
@@ -127,6 +131,7 @@ public class Config {
|
||||
public OpenAIAsyncClient getClient() throws IOException {
|
||||
return buildClient(
|
||||
() -> {
|
||||
LOGGER.debug("Loading AI provider settings from "+CONF_PROPERTIES);
|
||||
try {
|
||||
return AIProviderSettings.getAzureOpenAISettingsFromFile(CONF_PROPERTIES);
|
||||
} catch (IOException e) {
|
||||
+10
-2
@@ -1,12 +1,20 @@
|
||||
package com.microsoft.semantickernel;
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core-skills:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel.connectors:semantickernel-connectors:0.2.6-alpha
|
||||
//DEPS org.slf4j:slf4j-jdk14:2.0.7
|
||||
//SOURCES syntaxexamples/SampleSkillsUtil.java,Config.java
|
||||
package com.microsoft.semantickernel.samples;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.orchestration.SKContext;
|
||||
import com.microsoft.semantickernel.skilldefinition.ReadOnlyFunctionCollection;
|
||||
import com.microsoft.semantickernel.syntaxexamples.SampleSkillsUtil;
|
||||
import com.microsoft.semantickernel.samples.syntaxexamples.SampleSkillsUtil;
|
||||
import com.microsoft.semantickernel.textcompletion.CompletionSKFunction;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
+10
-2
@@ -1,8 +1,16 @@
|
||||
package com.microsoft.semantickernel;
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core-skills:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel.connectors:semantickernel-connectors:0.2.6-alpha
|
||||
//DEPS org.slf4j:slf4j-jdk14:2.0.7
|
||||
//SOURCES syntaxexamples/SampleSkillsUtil.java,Config.java,Example00_GettingStarted.java
|
||||
package com.microsoft.semantickernel.samples;
|
||||
|
||||
import com.microsoft.semantickernel.skilldefinition.ReadOnlyFunctionCollection;
|
||||
import com.microsoft.semantickernel.syntaxexamples.SampleSkillsUtil;
|
||||
import com.microsoft.semantickernel.textcompletion.CompletionSKFunction;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.samples.syntaxexamples.SampleSkillsUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
+9
-1
@@ -1,5 +1,13 @@
|
||||
package com.microsoft.semantickernel;
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core-skills:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel.connectors:semantickernel-connectors:0.2.6-alpha
|
||||
//DEPS org.slf4j:slf4j-jdk14:2.0.7
|
||||
//SOURCES syntaxexamples/SampleSkillsUtil.java,Config.java,Example00_GettingStarted.java
|
||||
package com.microsoft.semantickernel.samples;
|
||||
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.orchestration.SKContext;
|
||||
import com.microsoft.semantickernel.orchestration.SKFunction;
|
||||
import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig;
|
||||
+9
-1
@@ -1,5 +1,13 @@
|
||||
package com.microsoft.semantickernel;
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core-skills:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel.connectors:semantickernel-connectors:0.2.6-alpha
|
||||
//DEPS org.slf4j:slf4j-jdk14:2.0.7
|
||||
//SOURCES syntaxexamples/SampleSkillsUtil.java,Config.java,Example00_GettingStarted.java
|
||||
package com.microsoft.semantickernel.samples;
|
||||
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.orchestration.SKContext;
|
||||
import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig;
|
||||
+10
-2
@@ -1,7 +1,15 @@
|
||||
package com.microsoft.semantickernel;
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel:semantickernel-core-skills:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel.connectors:semantickernel-connectors:0.2.6-alpha
|
||||
//DEPS com.microsoft.semantic-kernel.extensions:semantickernel-sequentialplanner-extension:0.2.6-alpha
|
||||
//DEPS org.slf4j:slf4j-jdk14:2.0.7
|
||||
//SOURCES syntaxexamples/SampleSkillsUtil.java,Config.java,Example00_GettingStarted.java
|
||||
package com.microsoft.semantickernel.samples;
|
||||
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.planner.sequentialplanner.SequentialPlanner;
|
||||
import com.microsoft.semantickernel.syntaxexamples.SampleSkillsUtil;
|
||||
import com.microsoft.semantickernel.samples.syntaxexamples.SampleSkillsUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.microsoft.semantickernel.coreskills.TextSkill;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig;
|
||||
import com.microsoft.semantickernel.textcompletion.TextCompletion;
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.azure.ai.openai.OpenAIClientBuilder;
|
||||
@@ -19,7 +19,7 @@ import com.microsoft.semantickernel.connectors.ai.openai.util.AzureOpenAISetting
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.microsoft.semantickernel.Config.CONF_PROPERTIES;
|
||||
import static com.microsoft.semantickernel.samples.Config.CONF_PROPERTIES;
|
||||
|
||||
public class Example08_RetryHandler {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
package com.microsoft.semantickernel.syntaxexamples;// Copyright (c) Microsoft. All rights reserved.
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.coreskills.TextSkill;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.KernelConfig;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.connectors.memory.azurecognitivesearch.AzureCognitiveSearchMemory;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.Kernel;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.chatcompletion.ChatCompletion;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.azure.ai.openai.OpenAIAsyncClient;
|
||||
import com.microsoft.semantickernel.Config;
|
||||
import com.microsoft.semantickernel.samples.Config;
|
||||
import com.microsoft.semantickernel.builders.SKBuilders;
|
||||
import com.microsoft.semantickernel.coreskills.TextSkill;
|
||||
import com.microsoft.semantickernel.planner.actionplanner.ActionPlanner;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import com.microsoft.semantickernel.GPT3Tokenizer;
|
||||
public class Example29_Tokenizer {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.microsoft.semantickernel.syntaxexamples;
|
||||
package com.microsoft.semantickernel.samples.syntaxexamples;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
Reference in New Issue
Block a user