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

Repo sync for protected branch #102

Merged
merged 69 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
2c344ca
[BULK] - DocuTune - Remove expired ms.custom value
alexbuckgit Feb 1, 2024
6d1b95c
Update index.yml
alexbuckgit Feb 22, 2024
4d5deb2
Update index.yml
alexbuckgit Feb 22, 2024
25914c9
Update index.yml
alexbuckgit Feb 22, 2024
8428cf0
Update vector-db.md
wmwxwa Mar 8, 2024
024aaea
Merge pull request #212 from wmwxwa/patch-3
evchaki Mar 8, 2024
41e9393
Merge branch 'main' into repo_sync_working_branch
matthewbolanos Mar 11, 2024
2c8bb27
Merge pull request #205 from MicrosoftDocs/repo_sync_working_branch
matthewbolanos Mar 11, 2024
dc8fc21
Merge pull request #213 from MicrosoftDocs/main
matthewbolanos Mar 11, 2024
d7bb86b
Update vector-db.md
wmwxwa Mar 11, 2024
496e3c0
Update vector-db.md
wmwxwa Mar 11, 2024
fcc7537
Merge pull request #214 from wmwxwa/patch-3
evchaki Mar 11, 2024
176b26a
Merge pull request #215 from MicrosoftDocs/main
matthewbolanos Mar 11, 2024
d317cd4
Add milvus C# connector
luisquintanilla Mar 18, 2024
14e87c1
Merge pull request #216 from luisquintanilla/add-csharp-milvus-connector
matthewbolanos Mar 18, 2024
3e5e6b0
Merge pull request #217 from MicrosoftDocs/main
matthewbolanos Mar 18, 2024
b642de9
updating docs for java-v1
dsgrieve Mar 20, 2024
b34a1d9
fix links
dsgrieve Mar 20, 2024
68c963c
Update quick-start-guide and templatizing-prompts for Java
johnoliver Mar 20, 2024
109c216
Update .openpublishing.publish.config.json
johnoliver Mar 21, 2024
2125443
Update .openpublishing.publish.config.json
johnoliver Mar 21, 2024
f5e3124
Update templatizing-prompts.md
johnoliver Mar 21, 2024
3c47dc6
Fix path
johnoliver Mar 21, 2024
8645bc7
Fix link
johnoliver Mar 21, 2024
fe83e3e
Update agents/kernel/index.md for java
johnoliver Mar 21, 2024
17ea33f
Merge pull request #3 from johnoliver/samples-2
milderhc Mar 22, 2024
e418edd
Add Java documentation
milderhc Mar 22, 2024
21105c8
Test render
milderhc Mar 22, 2024
065c236
Update
milderhc Mar 22, 2024
96c47a8
use id instead of range in markdown
dsgrieve Mar 22, 2024
5b791a8
Merge branch 'java-v1' into dsgrieve/java-v1
milderhc Mar 22, 2024
4684e81
Add table end
milderhc Mar 22, 2024
603b397
Add empty tabs where needed
milderhc Mar 23, 2024
5ade8ba
Fix ids
milderhc Mar 23, 2024
310c3cd
Fix links
milderhc Mar 23, 2024
636f8b0
Fix table
milderhc Mar 23, 2024
91efdcd
Add Java to overview
milderhc Mar 23, 2024
2a3467b
Update highlight line
milderhc Mar 23, 2024
569a4ab
Update function invocation explanation
milderhc Mar 23, 2024
fe5a019
Merge branch 'dsgrieve/java-v1' of github.com:milderhc/semantic-kerne…
dsgrieve Mar 26, 2024
9d3aadf
address issues from upstream pr
dsgrieve Mar 26, 2024
e362c18
fix references to java samples
dsgrieve Mar 26, 2024
4280008
point java samples to upstream
dsgrieve Mar 27, 2024
f41337f
more publishing validation fixes
dsgrieve Mar 27, 2024
5a8257c
more publishing validation fixes
dsgrieve Mar 27, 2024
938ee2d
Update vector-db.md
wmwxwa Apr 2, 2024
7cb20be
Merge pull request #221 from wmwxwa/patch-3
evchaki Apr 2, 2024
8158ca6
Update vector-db.md
wmwxwa Apr 4, 2024
f5da909
Merge pull request #222 from wmwxwa/patch-3
evchaki Apr 4, 2024
7b834ce
Merge pull request #223 from MicrosoftDocs/main
matthewbolanos Apr 10, 2024
3a1656c
Update vector-db.md
wmwxwa Apr 16, 2024
8aba39f
Add files via upload
wmwxwa Apr 16, 2024
34244e7
Merge pull request #226 from wmwxwa/patch-5
matthewbolanos Apr 16, 2024
846afbc
Merge pull request #220 from johnoliver/java-learn
matthewbolanos Apr 16, 2024
88b3dc5
Merge pull request #206 from alexbuckgit/alexbuckgit/docutune-autopr-…
matthewbolanos Apr 16, 2024
8737923
Fix code reference
matthewbolanos Apr 16, 2024
4a5442e
Fix broken python links
matthewbolanos Apr 16, 2024
ddf0d13
Lowercase `handlebars`
matthewbolanos Apr 16, 2024
ff6c939
Remove empty sample block
matthewbolanos Apr 16, 2024
af80424
Fix python code samples
matthewbolanos Apr 16, 2024
e19a11f
fix core_plugin link for python
matthewbolanos Apr 16, 2024
4cd0372
Add java "not available"
matthewbolanos Apr 16, 2024
57f44cc
Fix FAQ
matthewbolanos Apr 16, 2024
8857ab7
Merge pull request #228 from MicrosoftDocs/fixes
matthewbolanos Apr 16, 2024
37ca4ae
Merge pull request #227 from MicrosoftDocs/main
matthewbolanos Apr 16, 2024
986c9e6
Update index.md - Update to table/ links
sophialagerkranspandey Apr 18, 2024
2a4ec4c
Update index.md
sophialagerkranspandey Apr 18, 2024
12c1fa5
Merge pull request #230 from MicrosoftDocs/sophialagerkranspandey-pat…
sophialagerkranspandey Apr 18, 2024
e0446b5
Merge pull request #231 from MicrosoftDocs/main
sophialagerkranspandey Apr 18, 2024
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
Prev Previous commit
Next Next commit
Add Java documentation
  • Loading branch information
milderhc committed Mar 22, 2024
commit e418eddbacd652acc22e6af21c7a1e0617f85691
12 changes: 12 additions & 0 deletions semantic-kernel/agents/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ def add(
return float(number1) + float(number2)
```

# [Java](#tab/Java)
The following code is an excerpt from the `MathPlugin` plugin, which can be found in the [examples](https://github.com/microsoft/semantic-kernel/blob/java-v1/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/MathPlugin.java) folder in the GitHub repository. It demonstrates how you can use the `kernel_function` and `Annotated` decorators to describe the function's input and output to planner.

```java
@DefineKernelFunction(name = "add", description = "Add two numbers")
public static double add(
@KernelFunctionParameter(name = "number1", description = "The first number to add", type = double.class) double number1,
@KernelFunctionParameter(name = "number2", description = "The second number to add", type = double.class) double number2) {
return number1 + number2;
}
```

---

You can learn more about creating native functions in the [Creating native functions](./using-the-KernelFunction-decorator.md) section. In this article you'll learn the best practices for the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ If you want to see the final solution to this article, you can check out the fol
| --- | --- | --- |
| C# | [Open example in GitHub](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/DocumentationExamples/SerializingPrompts.cs) | [Open solution in GitHub](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/DocumentationExamples/CreatingFunctons.cs) |
| Python | [Open solution in GitHub](https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main/samples/python/07-Serializing-Prompts) | [Open solution in GitHub](https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main/samples/python/08-Creating-Functions-For-AI) |
| Java | - | [Open example in GitHub](https://github.com/microsoft/semantic-kernel/blob/java-v1/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/Prompts.java) |

## Why should you create functions for your AI?
Large language models are great at generating text, but there are several tasks they cannot perform on their own. These include, but are not limited to:
Expand Down Expand Up @@ -49,7 +50,7 @@ To solve this problem, we'll demonstrate how to create native functions that can

We recommend that you create a new folder for your plugins at the root of your project. We recommend putting this folder at the root of your project and calling it _Plugins_.

Since we're giving our kernel the ability to perform math, we'll create a new plugin called `MathPlugin`. To do this, we'll create a _MathPlugin_ folder along with a file to store all its native functions. Depending on the language you're using, you'll create either a C# or Python file.
Since we're giving our kernel the ability to perform math, we'll create a new plugin called `MathPlugin`. To do this, we'll create a _MathPlugin_ folder along with a file to store all its native functions. Depending on the language you're using, you'll create either a C#, Python or Java file.

# [C#](#tab/Csharp)

Expand All @@ -66,13 +67,21 @@ Plugins
└─── Math.py
```

# [Java](#tab/Java)

```directory
Plugins
└─── MathPlugin.java
```
---

## Creating your native functions
Open up the _MathPlugin.cs_ or _Math.py_ file you created earlier and follow the instructions below to create the `Sqrt` function. This function will take a single number as an input and return the square root of that number.
Open up the _MathPlugin.cs_, _Math.py_ or _MathPlugin.java_ file you created earlier and follow the instructions below to create the `Sqrt` function. This function will take a single number as an input and return the square root of that number.

### Defining the class for your plugin
All native functions must be defined as public methods of a class that represents your plugin. To begin, create a class called `Math` in your _MathPlugin.cs_ or _Math.py_ file.
All native functions must be defined as public methods of a class that represents your plugin. To begin, create a class called `Math` in your math plugin file.

# [C#](#tab/Csharp)

Expand All @@ -82,6 +91,10 @@ All native functions must be defined as public methods of a class that represent

:::code language="python" source="~/../semantic-kernel-samples/python/samples/documentation_examples/plugins/MathPlugin/native_function.py" range="1-12":::

# [Java](#tab/Java)

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/MathPlugin.java" id="KernelPlugin":::

---

### Use the KernelFunction decorator to define a native function
Expand All @@ -102,6 +115,10 @@ Notice that the input and and return types are strings. This is because the kern

Also notice how we've added a description to each function with the `Description` attribute. This description will be used in the future by the [planner](../planners/index.md) to automatically create a plan using these functions. In our case, we're telling planner that this function can `Take the square root of a number`.

# [Java](#tab/Java)

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/MathPlugin.java" id="KernelFunction":::

---

### Creating the remaining math functions
Expand All @@ -116,6 +133,10 @@ Now that you've created the `Sqrt` function, you can create the remaining math f

:::code language="python" source="~/../semantic-kernel-samples/python/samples/documentation_examples/plugins/MathPlugin/native_function.py":::

# [Java](#tab/Java)

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/MathPlugin.java":::

---

## Running your native function
Expand All @@ -129,17 +150,32 @@ Now that you've created your first native function, you can import it and run it

:::code language="python" source="~/../semantic-kernel-samples/python/samples/documentation_examples/creating_functions.py" highlight="24-28":::

# [Java](#tab/Java)

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/CreatingFunctions.java" id="RunNativeFunction":::

---

The code should output `3.4641016151377544` since it's the square root of `12`.

### Allow the AI to automatically call your function
Now that you've created your first native function, you can now allow the AI to automatically call it within the C# version of the SDK. To do this, let's go ahead and create a chat loop that will allow us to talk back-and-forth with our agent.
Now that you've created your first native function, you can now allow the AI to automatically call it within the C# or Java version of the SDK. To do this, let's go ahead and create a chat loop that will allow us to talk back-and-forth with our agent.

While in the chat loop, we'll configure the OpenAI connection to automatically call any functions that are registered with the kernel. To do this, we'll set the `ToolCallBehavior` property to `ToolCallBehavior.AutoInvokeKernelFunctions` on the `OpenAIPromptExecutionSettings` object.

# [C#](#tab/Csharp)

:::code language="csharp" source="~/../semantic-kernel-samples/dotnet/samples/DocumentationExamples/CreatingFunctions.cs" range="50-51,57-97" highlight="14":::

# [Java](#tab/Java)

While in the chat loop, we'll configure the OpenAI connection to automatically call any functions that are registered with the kernel. To do this, we'll call `withToolCallBehavior` in the `InvocationContext` builder with `ToolCallBehavior.allowAllKernelFunctions(true)`, `true` meaning the function auto-invocation is on for all kernel functions.

---

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/CreatingFunctions.java" id="Conversation" highlight="7-12":::


When you run this code, you'll be able to ask the AI to perform math for you. For example, you can ask the AI to `Take the square root of 12` and it will return back the correct answer.

## Take the next step
Expand Down
37 changes: 34 additions & 3 deletions semantic-kernel/prompts/saving-prompts-as-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ If you want to see the final solution, you can check out the following samples i
| --- | --- |
| C# | [Open example in GitHub](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/DocumentationExamples/FunctionsWithinPrompts.cs) | [Open solution in GitHub](Open example in GitHub](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/DocumentationExamples/SerializingPrompts.cs) |
| Python | [Open solution in GitHub](https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main/samples/python/05-Nested-Functions-In-Prompts) | [Open solution in GitHub](https://github.com/MicrosoftDocs/semantic-kernel-docs/tree/main/samples/python/07-Serializing-Prompts) |
| Python | - | [Open solution in GitHub](https://github.com/microsoft/semantic-kernel/blob/java-v1/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/SerializingPrompts.java) |


## Creating a home for your prompts
Expand Down Expand Up @@ -71,11 +72,15 @@ For the `chat` function, we can use the same configuration [as before](./configu

:::code language="json" source="~/../samples/python/07-Serializing-Prompts/prompts/chat/config.json":::

# [Java](#tab/Java)

:::code language="json" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/Prompts/chat/config.json":::

---


### Testing your prompt
At this point, you can import and test your function with the kernel by updating your _Program.cs_ or _main.py_ file to the following.
At this point, you can import and test your function with the kernel by updating your _Program.cs_, _main.py_ or _Main.java_ file to the following.

# [C#](#tab/Csharp)
:::code language="csharp" source="~/../semantic-kernel-samples/dotnet/samples/DocumentationExamples/SerializingPrompts.cs" range="8-10,38-46,74-81,99-129":::
Expand All @@ -84,12 +89,20 @@ At this point, you can import and test your function with the kernel by updating

:::code language="python" source="~/../samples/python/07-Serializing-Prompts/main.py" range="2-3,5-10,12-41":::

# [Java](#tab/Java)

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/SerializingPrompts.java" id="InvokeSerializedPrompts":::

---

## Using YAML to serialize your prompt
In addition to the _skprompt.txt_ and _config.json_ files, you can also serialize your prompt using a single YAML file while using the C# SDK. This is useful if you want to use a single file to define your prompt. Additionally, this is the same format that is used by Azure AI Studio, making it easier to share prompts between the two platforms.
In addition to the _skprompt.txt_ and _config.json_ files, you can also serialize your prompt using a single YAML file while using the C# or Java SDK. This is useful if you want to use a single file to define your prompt. Additionally, this is the same format that is used by Azure AI Studio, making it easier to share prompts between the two platforms.

Let's try creating a YAML serialization file for the `getIntent` prompt. To get started, you first need to install the necessary packages.
Let's try creating a YAML serialization file for the `getIntent` prompt.

# [C#](#tab/Csharp)

To get started, you first need to install the necessary packages.

```console
dotnet add package Microsoft.SemanticKernel.Yaml --prerelease
Expand Down Expand Up @@ -123,6 +136,24 @@ To call the prompt, you can use the following code:

:::code language="csharp" source="~/../semantic-kernel-samples/dotnet/samples/DocumentationExamples/SerializingPrompts.cs" range="82-92":::

# [Java](#tab/Java)

Create a new file called _getIntent.prompt.yaml_ in the _Prompts_ folder and copy the following YAML into the file.

:::code language="yaml" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/resources/Plugins/getIntent.prompt.yaml":::

As a best practice, we recommend adding your prompts as an embedded resource.

Finally, you can import your prompt in the Java file.

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/SerializingPrompts.java" id="LoadPromptFromYaml":::

To call the prompt, you can use the following code:

:::code language="java" source="~/../semantic-kernel-samples/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/documentationexamples/SerializingPrompts.java" id="InvokePromptFromYaml":::

---



## Take the next step
Expand Down
Loading