### Properties File Example
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Example structure of a properties file for configuring OpenAI or Azure OpenAI client settings.
```properties
# If using openai.com
client.openai.key:"my-key"
client.openai.organizationid:"my-org-id"
# if using Azure Open AI
client.azureopenai.key:"my-key"
client.azureopenai.endpoint:"url of azure openai endpoint"
client.azureopenai.deploymentname:"deployment name"
```
--------------------------------
### Basic Code Block Example
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/rag/example.md
This is a simple code block demonstrating basic syntax. It does not require specific imports or setup.
```plaintext
some code
```
--------------------------------
### Example: OpenAI Connector with Maven
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/PACKAGES.md
Configure your Maven project to use the OpenAI AI services connector along with the core API and BOM.
```xml
com.microsoft.semantic-kernel
semantickernel-bom
${semantickernel.version}
import
pom
com.microsoft.semantic-kernel
semantickernel-api
com.microsoft.semantic-kernel
semantickernel-connectors-ai-openai
```
--------------------------------
### Define Kernel with AI Service
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a Kernel instance using the Kernel builder pattern, configuring it with an AI service. This example shows how to build a Kernel with a pre-configured ChatCompletionService.
```java
ChatCompletionService chatCompletionService = ChatCompletionService.builder()
.withOpenAIAsyncClient(client)
.withModelId("gpt-3.5-turbo-0613")
.withServiceId("fridayChatGeneration")
.build();
return Kernel.builder()
.withAIService(ChatCompletionService.class, chatCompletionService);
```
--------------------------------
### Direct Call to TextPlugin Function
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Example of directly calling a function from a plugin, such as the TextPlugin's uppercase method.
```java
TextPlugin text = new TextPlugin();
return text.uppercase("ciao!");
```
--------------------------------
### Retrieve an AI Service from Kernel
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Get an instance of a specific AI service, such as ChatCompletionService, from the configured Kernel.
```java
ChatCompletionService service = kernel.getService(ChatCompletionService.class);
```
--------------------------------
### Define a KernelPlugin with Native Functions
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a KernelPlugin by defining a class with methods annotated with @DefineKernelFunction. This example defines 'date' and 'time' functions within a 'Time' class.
```java
public static class Time {
@DefineKernelFunction(name = "date")
public String date() {
System.out.println("date is called");
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
return dateFormat.format(now);
}
@DefineKernelFunction(name = "time")
public String time() {
System.out.println("time is called");
Date now = new Date();
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
return timeFormat.format(now);
}
}
KernelPlugin time = KernelPluginFactory.createFromObject(new Time(), "time");
```
--------------------------------
### Add PostChatCompletionHook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Add a hook to process the results after a chat completion. This example prints the completion ID and logs that the hook was triggered.
```java
kernel.getGlobalKernelHooks().addPostChatCompletionHook(event -> {
System.out.println("------- Triggered after ChatCompletion ------- ");
System.out.println("--- Output ChatCompletion and id ----");
System.out.println("Chat completion");
System.out.println("Id: " + event.getChatCompletions().getId());
return event;
});
```
--------------------------------
### Add PreChatCompletionHook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Add a hook to modify chat completion options before the LLM call. This example adds a system message to instruct the LLM to use uppercase text.
```java
kernel.getGlobalKernelHooks().addPreChatCompletionHook(event -> {
ChatCompletionsOptions options = event.getOptions();
List messages = options.getMessages();
messages = new ArrayList<>(messages);
messages.add(new ChatRequestSystemMessage("Use upper case text when responding to the prompt."));
System.out.println("------- Triggered before ChatCompletion ------- ");
System.out.println("---- Added: Use upper case text when responding to the prompt. ----");
for (ChatRequestMessage msg : messages) {
System.out.println(msg);
}
return new PreChatCompletionEvent(
PreChatCompletionHook.cloneOptionsWithMessages(options, messages)
);
});
```
--------------------------------
### Invoke KernelFunction via Kernel.invokeAsync
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Invoke a KernelFunction using the Kernel's invokeAsync method, providing arguments and blocking for the result. This example uses a pre-defined plugin.
```java
Kernel kernel = Kernel.builder().build();
KernelPlugin kernelPlugin = KernelPluginFactory.createFromObject(new StaticTextPlugin(), "text");
KernelFunctionArguments arguments = KernelFunctionArguments.builder()
.withVariable("input", "Today is: ")
.withVariable("day", "Monday")
.build();
return kernel.invokeAsync(kernelPlugin.get("AppendDay"))
.withArguments(arguments)
.block()
.getResult();
```
--------------------------------
### Implement PromptRenderedHook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a hook that triggers after a prompt has been rendered. This handler can modify the final prompt string, for example, by appending instructions.
```java
PromptRenderedHook myRenderedHandler = event -> {
System.out.println(event.getFunction().getName() + " : Triggered PromptRenderedHook");
String prompt = event.getPrompt() + "\nUSE SHORT, CLEAR, COMPLETE SENTENCES.";
return new PromptRenderedEvent(event.getFunction(), event.getArguments(), prompt);
};
```
--------------------------------
### Define a Native Kernel Function
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Implement a native Kernel function within a class, using the @DefineKernelFunction annotation for the function name and description, and @KernelFunctionParameter for parameters. This example defines an 'Uppercase' function.
```java
public class TextPlugin {
@DefineKernelFunction(description = "Change all string chars to uppercase.", name = "Uppercase")
public String uppercase(@KernelFunctionParameter(description = "Text to uppercase", name = "input") String text) {
return text.toUpperCase(Locale.ROOT);
}
}
```
--------------------------------
### Directly Call AI Service for Chat Response
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Invoke the AI service directly to get chat completion results by providing chat history and the kernel instance. Use .block() to wait for the asynchronous operation to complete.
```java
ChatCompletionService service = kernel.getService(ChatCompletionService.class);
var chatHistory = new ChatHistory(systemMessage);
chatHistory.addUserMessage(userMessage);
var answer = service.getChatMessageContentsAsync(chatHistory, kernel, null).block();
```
--------------------------------
### Using Different Prompt Template Formats
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Demonstrates invoking prompts using both 'semantic-kernel' and 'handlebars' template formats. Ensure the correct template factory is provided.
```java
runPrompt(kernel,
"semantic-kernel",
"Hello AI, my name is {{$name}}. What is the origin of my name?",
templateFactory);
runPrompt(kernel,
"handlebars",
"Hello AI, my name is {{name}}. What is the origin of my name?",
templateFactory);
```
--------------------------------
### Full Build with Static Analysis and Tests
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/BUILD.md
Perform a full build that includes static analysis and end-to-end tests. This command may require a valid OpenAI key.
```shell
./mvnw clean install -Prelease,bug-check,with-samples
```
--------------------------------
### Run Sample with OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Execute a Java sample using OpenAI by setting environment variables for client type, key, and organization ID.
```shell
OPENAI_CLIENT_TYPE=OPENAI \
OPEN_AI_KEY="my-key" \
OPEN_AI_ORGANIZATION_ID="organisation id" \
../../mvnw clean package exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Create Prompt Template with PromptTemplateFactory.build
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a PromptTemplate object using PromptTemplateFactory.build for simpler template configurations. Ensure the systemPromptTemplate variable is defined.
```java
String systemPromptTemplate = "...";
PromptTemplate promptTemplate = PromptTemplateFactory.build(
PromptTemplateConfig
.builder()
.withTemplate(systemPromptTemplate)
.build()
);
```
--------------------------------
### Build and Test .NET Projects
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/CONTRIBUTING.md
Use these commands to build and test .NET projects within the Semantic Kernel repository. Ensure your environment is set up for .NET development.
```bash
run build.cmd
```
```bash
bash build.sh
```
--------------------------------
### Run Sample with Azure OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Execute a Java sample using Azure OpenAI by setting environment variables for client type, key, and endpoint.
```shell
OPENAI_CLIENT_TYPE=AZURE_OPEN_AI \
AZURE_OPEN_AI_KEY="my-key" \
AZURE_OPEN_AI_ENDPOINT="endpoint url" \
../../mvnw clean package exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Compile Java Samples
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Compile all Java samples using the Maven wrapper.
```shell
ப்பட்டு../../mvnw clean package
```
--------------------------------
### Build Kernel with Plugins and Services
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Construct a Kernel instance using the builder pattern, adding plugins and AI services. This snippet demonstrates adding a custom plugin and an AI service.
```java
Kernel kernel = Kernel.builder()
.withPlugin(myPlugin)
.withAIService(openAiChatService)
.withServiceSelector()
.build();
```
--------------------------------
### Run Compiled Java Sample
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Execute a specific compiled Java sample using the Maven wrapper and specifying the sample name.
```shell
../../mvnw exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Build Semantic Kernel with Maven Wrapper
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/BUILD.md
Clone the repository and build the project using the Maven Wrapper. This is the standard way to build the project.
```shell
git clone https://github.com/microsoft/semantic-kernel-java
cd semantic-kernel
./mvnw install
```
--------------------------------
### System Properties Configuration for OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Configure OpenAI client settings directly via system properties on the command line.
```shell
# OpenAI
../../mvnw exec:java \
-DOPENAI_CLIENT_TYPE=AZURE_OPEN_AI \
-Dclient.openai.key="my-key" \
-Dclient.openai.organizationid="my-org-id" \
-Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Properties File Configuration
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Configure client settings by specifying a properties file location using the CONF_PROPERTIES environment variable or system property.
```shell
CONF_PROPERTIES=my.properties \
OPENAI_CLIENT_TYPE=OPEN_AI \
../../mvnw exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
OR
../../mvnw exec:java \
-DCONF_PROPERTIES=my.properties \
-DOPENAI_CLIENT_TYPE=AZURE_OPEN_AI \
-Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Build with Bug Check Profile
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/BUILD.md
Clean, package, and run the bug-check profile before submitting a pull request. This profile enforces formatting and detects static analysis issues.
```shell
./mvnw clean package -Pbug-check
```
--------------------------------
### System Properties Configuration for Azure OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Configure Azure OpenAI client settings directly via system properties on the command line.
```shell
# Azure
../../mvnw exec:java \
-DOPENAI_CLIENT_TYPE=AZURE_OPEN_AI \
-Dclient.azureopenai.key="my-key" \
-Dclient.azureopenai.endpoint="url of azure openai endpoint" \
-Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Create KernelFunction from Simple Prompt
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a KernelFunction directly from a simple prompt string. Configure execution settings and specify the template format.
```java
var message = "Translate this date " + date + " to French format";
var fixedFunction = KernelFunction
.createFromPrompt(message)
.withDefaultExecutionSettings(
PromptExecutionSettings.builder()
.withMaxTokens(100)
.build())
.withTemplateFormat(PromptTemplateConfig.SEMANTIC_KERNEL_TEMPLATE_FORMAT)
.withName("translator")
.build();
```
--------------------------------
### Create Prompt Template with KernelPromptTemplateFactory
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Define a prompt template string and create a PromptTemplate object using KernelPromptTemplateFactory. This is useful for complex templates with dynamic variables.
```java
String functionDefinition = """
Today is: {{time.date}}
Current time is: {{time.time}}
Answer the following questions using JSON syntax, including the data used.
Is it morning, afternoon, evening, or night (morning/afternoon/evening/night)?
Is it weekend time (weekend/not weekend)?
""";
PromptTemplate promptTemplate = new KernelPromptTemplateFactory().tryCreate(
PromptTemplateConfig
.builder()
.withTemplate(functionDefinition)
.build()
);
```
--------------------------------
### Create KernelFunction from Prompt Template
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Use KernelFunctionFromPrompt.builder() to create a function from a multi-line prompt template. Configure execution settings like temperature and max tokens.
```java
String promptTemplate = """
Generate a creative reason or excuse for the given event.
Be creative and be funny. Let your imagination run wild.
Event: I am running late.
Excuse: I was being held ransom by giraffe gangsters.
Event: I haven't been to the gym for a year
Excuse: I've been too busy training my pet dragon.
Event: {{$input}}
""".stripIndent();
var excuseFunction = KernelFunctionFromPrompt.builder()
.withTemplate(promptTemplate)
.withDefaultExecutionSettings(
PromptExecutionSettings.builder()
.withTemperature(0.4)
.withTopP(1)
.withMaxTokens(500)
.withUser("bx-h")
.build()
)
.withName("ExcuseGeneratorFunction")
.build();
```
--------------------------------
### Set OpenAI Client Type via Command Line
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Specify the OpenAI client type (OpenAI or Azure OpenAI) directly on the command line when running a sample.
```shell
OPENAI_CLIENT_TYPE=OPEN_AI ../../mvnw exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
OR
../../mvnw exec:java -DOPENAI_CLIENT_TYPE=AZURE_OPEN_AI -Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Run All Tests Locally
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/BUILD.md
Execute all tests, including integration tests that require an OpenAI key. Ensure environment variables for API keys are set if needed.
```shell
./mvnw verify -Prelease,bug-check,with-samples
```
--------------------------------
### Define an AI Service with OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Configure and build a ChatCompletionService using the builder pattern, specifying the OpenAI client, model ID, and a service ID.
```java
ChatCompletionService chatCompletionService = ChatCompletionService.builder()
.withOpenAIAsyncClient(client)
.withModelId("gpt-3.5-turbo-0613")
.withServiceId("fridayChatGeneration")
.build();
```
--------------------------------
### Run Unit Tests Locally
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/BUILD.md
Execute only the unit tests for the Semantic Kernel Java project. This command does not require an OpenAI key.
```shell
./mvnw package
```
--------------------------------
### Environment Variables for OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Set environment variables for OpenAI client type, key, and organization ID to run a sample.
```shell
# OPENAI:
OPENAI_CLIENT_TYPE=OPEN_AI \
OPEN_AI_KEY="my-key" \
OPEN_AI_ORGANIZATION_ID="organisation id" \
../../mvnw clean package exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Build and Test TypeScript Projects
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/CONTRIBUTING.md
Execute these commands to build and test TypeScript components of the Semantic Kernel. This is essential for ensuring code integrity.
```bash
yarn build
```
--------------------------------
### Define KernelFunctionArguments with Input
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create KernelFunctionArguments using the builder pattern, setting the primary input value.
```java
KernelFunctionArguments.builder().withInput("Jupiter").build();
```
--------------------------------
### Implement PromptRenderingHook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a hook that triggers when a prompt is about to be rendered. This handler can modify arguments, such as adding a 'style' context variable.
```java
PromptRenderingHook myRenderingHandler = event -> {
System.out.println(event.getFunction().getName() + " : Triggered PromptRenderingHook");
event.getArguments().put("style", ContextVariable.of("Seinfeld"));
return event;
};
```
--------------------------------
### Lint and Format .NET Code
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/CONTRIBUTING.md
Automatically format and lint .NET code to ensure consistency and adherence to project standards. This command helps in maintaining code quality.
```bash
dotnet format
```
--------------------------------
### Environment Variables for Azure OpenAI
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/semantickernel-syntax-examples/README.md
Set environment variables for Azure OpenAI client type, key, and endpoint to run a sample.
```shell
# AZURE:
OPENAI_CLIENT_TYPE=AZURE_OPEN_AI \
AZURE_OPEN_AI_KEY="my-key" \
AZURE_OPEN_AI_ENDPOINT="endpoint url" \
../../mvnw clean package exec:java -Dsample=Example04_CombineLLMPromptsAndNativeCode
```
--------------------------------
### Import Semantic Kernel BOM for Version Management
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/PACKAGES.md
Use the semantickernel-bom in your Maven project's dependencyManagement to define versions for all Semantic Kernel packages.
```xml
com.microsoft.semantic-kernel
semantickernel-bom
${semantickernel.version}
import
pom
```
--------------------------------
### Define KernelFunction from JSON Configuration
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a KernelFunction by parsing a JSON configuration payload. This allows defining function schema, name, description, and completion settings.
```java
var prompt = "Hello AI, what can you do for me?";
String configPayload = """
{
"schema": 1,
"name": "HelloAI",
"description": "Say hello to an AI",
"type": "completion",
"completion": {
"max_tokens": 256,
"temperature": 0.5,
"top_p": 0.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0
}
}
""".stripIndent();
PromptTemplateConfig promptConfig = PromptTemplateConfig
.parseFromJson(configPayload)
.copy()
.withTemplate(prompt)
.build();
var func = KernelFunction
.createFromPrompt(promptConfig)
.build();
```
--------------------------------
### Define KernelFunctionArguments with Variable
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create KernelFunctionArguments using the builder pattern, specifying variables by name.
```java
KernelFunctionArguments.builder().withVariable("input", "Jupiter").build();
```
--------------------------------
### Render Prompt Without LLM Query
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Render a prompt template asynchronously without sending it to an LLM. This is useful for debugging or pre-processing prompts. The result is printed to the console.
```java
var renderedPrompt = promptTemplate.renderAsync(kernel, KernelFunctionArguments, InvocationContext).block();
System.out.println(renderedPrompt);
```
--------------------------------
### Implement FunctionInvokingHook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a hook that triggers before a function is called. This handler logs the function name and can be used for pre-execution logic.
```java
FunctionInvokingHook preHook = event -> {
System.out.println(event.getFunction().getName() + " : Pre Execution Handler - Triggered");
return event;
};
kernel.getGlobalKernelHooks().addHook("", preHook);
```
--------------------------------
### Invoke KernelFunction with Specific Arguments
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Invoke a KernelFunction (excuseFunction) using Kernel.invokeAsync, providing arguments via the builder and blocking for the result.
```java
var result = kernel
.invokeAsync(excuseFunction)
.withArguments(
KernelFunctionArguments.builder()
.withInput("I missed the F1 final race")
.build()
)
.block();
```
--------------------------------
### Register Global Kernel Hook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Register a hook to be executed globally across all kernel operations. Use this for cross-cutting concerns that should always be applied.
```java
kernel.getGlobalKernelHooks().addHook("hookName", KernelHook);
```
--------------------------------
### Add Semantic Kernel API Dependency
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/PACKAGES.md
Include the semantickernel-api package in your Maven project to access the core public API.
```xml
com.microsoft.semantic-kernel
semantickernel-api
```
--------------------------------
### Register Kernel Hook for Single Invocation
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Register hooks that are effective only for a specific kernel invocation. This allows for fine-grained control over behavior for individual function calls.
```java
KernelHooks kernelHooks = new KernelHooks();
kernelHooks.addPreChatCompletionHook(...);
var result = kernel.invokeAsync(writerFunction)
.withArguments(KernelFunctionArguments.builder().build())
.addKernelHooks(kernelHooks)
.block();
```
--------------------------------
### Implement FunctionInvokedHook
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/samples/semantickernel-concepts/README.md
Create a hook that triggers after a function has been called. This handler modifies the result by replacing vowels and numbers with asterisks.
```java
FunctionInvokedHook hook = event -> {
String result = (String) event.getResult().getResult();
System.out.println(event.getFunction().getName() + " : Modified result via FunctionInvokedHook: " + result);
result = result.replaceAll("[aeiouAEIOU0-9]", "*");
return new FunctionInvokedEvent(
event.getFunction(),
event.getArguments(),
new FunctionResult<>(ContextVariable.of(result), event.getResult().getMetadata(), result)
);
};
kernel.getGlobalKernelHooks().addHook(hook);
```
--------------------------------
### Lint and Fix TypeScript Code
Source: https://github.com/microsoft/semantic-kernel-java/blob/main/CONTRIBUTING.md
Apply automatic fixes to linting issues in TypeScript code. This command helps maintain code style and quality across the project.
```bash
yarn lint:fix
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.