forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.Net] Update website for AutoGen.SemanticKernel and AutoGen.Ollama (m…
…icrosoft#2814) * update sk documents * add ollama doc
- Loading branch information
1 parent
f9d3fda
commit 7f635b4
Showing
15 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
dotnet/sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Create_Semantic_Kernel_Chat_Agent.cs | ||
|
||
#region Using | ||
using AutoGen.Core; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Agents; | ||
|
||
#endregion Using | ||
namespace AutoGen.SemanticKernel.Sample; | ||
|
||
public class Create_Semantic_Kernel_Chat_Agent | ||
{ | ||
public static async Task RunAsync() | ||
{ | ||
#region Create_Kernel | ||
var openAIKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new Exception("Please set OPENAI_API_KEY environment variable."); | ||
var modelId = "gpt-3.5-turbo"; | ||
var kernel = Kernel.CreateBuilder() | ||
.AddOpenAIChatCompletion(modelId: modelId, apiKey: openAIKey) | ||
.Build(); | ||
#endregion Create_Kernel | ||
|
||
#region Create_ChatCompletionAgent | ||
// The built-in ChatCompletionAgent from semantic kernel. | ||
var chatAgent = new ChatCompletionAgent() | ||
{ | ||
Kernel = kernel, | ||
Name = "assistant", | ||
Description = "You are a helpful AI assistant", | ||
}; | ||
#endregion Create_ChatCompletionAgent | ||
|
||
#region Create_SemanticKernelChatCompletionAgent | ||
var messageConnector = new SemanticKernelChatMessageContentConnector(); | ||
var skAgent = new SemanticKernelChatCompletionAgent(chatAgent) | ||
.RegisterMiddleware(messageConnector) // register message connector so it support AutoGen built-in message types like TextMessage. | ||
.RegisterPrintMessage(); // pretty print the message to the console | ||
#endregion Create_SemanticKernelChatCompletionAgent | ||
|
||
#region Send_Message | ||
await skAgent.SendAsync("Hey tell me a long tedious joke"); | ||
#endregion Send_Message | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
This example shows how to use @AutoGen.Ollama.OllamaAgent to connect to Ollama server and chat with LLaVA model. | ||
|
||
To run this example, you need to have an Ollama server running aside and have `llama3:latest` model installed. For how to setup an Ollama server, please refer to [Ollama](https://ollama.com/). | ||
|
||
> [!NOTE] | ||
> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.Ollama.Sample/Chat_With_LLaMA.cs) | ||
### Step 1: Install AutoGen.Ollama | ||
|
||
First, install the AutoGen.Ollama package using the following command: | ||
|
||
```bash | ||
dotnet add package AutoGen.Ollama | ||
``` | ||
|
||
For how to install from nightly build, please refer to [Installation](../Installation.md). | ||
|
||
### Step 2: Add using statement | ||
|
||
[!code-csharp[](../../../sample/AutoGen.Ollama.Sample/Chat_With_LLaMA.cs?name=Using)] | ||
|
||
### Step 3: Create and chat @AutoGen.Ollama.OllamaAgent | ||
|
||
In this step, we create an @AutoGen.Ollama.OllamaAgent and connect it to the Ollama server. | ||
|
||
[!code-csharp[](../../../sample/AutoGen.Ollama.Sample/Chat_With_LLaMA.cs?name=Create_Ollama_Agent)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
This sample shows how to use @AutoGen.Ollama.OllamaAgent to chat with LLaVA model. | ||
|
||
To run this example, you need to have an Ollama server running aside and have `llava:latest` model installed. For how to setup an Ollama server, please refer to [Ollama](https://ollama.com/). | ||
|
||
> [!NOTE] | ||
> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.Ollama.Sample/Chat_With_LLaVA.cs) | ||
### Step 1: Install AutoGen.Ollama | ||
|
||
First, install the AutoGen.Ollama package using the following command: | ||
|
||
```bash | ||
dotnet add package AutoGen.Ollama | ||
``` | ||
|
||
For how to install from nightly build, please refer to [Installation](../Installation.md). | ||
|
||
### Step 2: Add using statement | ||
|
||
[!code-csharp[](../../../sample/AutoGen.Ollama.Sample/Chat_With_LLaVA.cs?name=Using)] | ||
|
||
### Step 3: Create @AutoGen.Ollama.OllamaAgent | ||
|
||
[!code-csharp[](../../../sample/AutoGen.Ollama.Sample/Chat_With_LLaVA.cs?name=Create_Ollama_Agent)] | ||
|
||
### Step 4: Start MultiModal Chat | ||
LLaVA is a multimodal model that supports both text and image inputs. In this step, we create an image message along with a question about the image. | ||
|
||
[!code-csharp[](../../../sample/AutoGen.Ollama.Sample/Chat_With_LLaVA.cs?name=Send_Message)] |
6 changes: 4 additions & 2 deletions
6
...ticles/AutoGen-SemanticKernel-Overview.md → ...Kernel/AutoGen-SemanticKernel-Overview.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../website/articles/AutoGen.SemanticKernel/SemanticKernelChatAgent-simple-chat.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
`AutoGen.SemanticKernel` provides built-in support for `ChatCompletionAgent` via @AutoGen.SemanticKernel.SemanticKernelChatCompletionAgent. By default the @AutoGen.SemanticKernel.SemanticKernelChatCompletionAgent only supports the original `ChatMessageContent` type via `IMessage<ChatMessageContent>`. To support more AutoGen built-in message types like @AutoGen.Core.TextMessage, @AutoGen.Core.ImageMessage, @AutoGen.Core.MultiModalMessage, you can register the agent with @AutoGen.SemanticKernel.SemanticKernelChatMessageContentConnector. The @AutoGen.SemanticKernel.SemanticKernelChatMessageContentConnector will convert the message from AutoGen built-in message types to `ChatMessageContent` and vice versa. | ||
|
||
The following step-by-step example shows how to create an @AutoGen.SemanticKernel.SemanticKernelChatCompletionAgent and chat with it: | ||
|
||
> [!NOTE] | ||
> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs). | ||
### Step 1: add using statement | ||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs?name=Using)] | ||
|
||
### Step 2: create kernel | ||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs?name=Create_Kernel)] | ||
|
||
### Step 3: create ChatCompletionAgent | ||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs?name=Create_ChatCompletionAgent)] | ||
|
||
### Step 4: create @AutoGen.SemanticKernel.SemanticKernelChatCompletionAgent | ||
In this step, we create an @AutoGen.SemanticKernel.SemanticKernelChatCompletionAgent and register it with @AutoGen.SemanticKernel.SemanticKernelChatMessageContentConnector. The @AutoGen.SemanticKernel.SemanticKernelChatMessageContentConnector will convert the message from AutoGen built-in message types to `ChatMessageContent` and vice versa. | ||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs?name=Create_SemanticKernelChatCompletionAgent)] | ||
|
||
### Step 5: chat with @AutoGen.SemanticKernel.SemanticKernelChatCompletionAgent | ||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Create_Semantic_Kernel_Chat_Agent.cs?name=Send_Message)] |
27 changes: 27 additions & 0 deletions
27
...et/website/articles/AutoGen.SemanticKernel/Use-kernel-plugin-in-other-agents.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
In semantic kernel, a kernel plugin is a collection of kernel functions that can be invoked during LLM calls. Semantic kernel provides a list of built-in plugins, like [core plugins](https://github.com/microsoft/semantic-kernel/tree/main/dotnet/src/Plugins/Plugins.Core), [web search plugin](https://github.com/microsoft/semantic-kernel/tree/main/dotnet/src/Plugins/Plugins.Web) and many more. You can also create your own plugins and use them in semantic kernel. Kernel plugins greatly extend the capabilities of semantic kernel and can be used to perform various tasks like web search, image search, text summarization, etc. | ||
|
||
`AutoGen.SemanticKernel` provides a middleware called @AutoGen.SemanticKernel.KernelPluginMiddleware that allows you to use semantic kernel plugins in other AutoGen agents like @AutoGen.OpenAI.OpenAIChatAgent. The following example shows how to define a simple plugin with a single `GetWeather` function and use it in @AutoGen.OpenAI.OpenAIChatAgent. | ||
|
||
> [!NOTE] | ||
> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.SemanticKernel.Sample/Use_Kernel_Functions_With_Other_Agent.cs) | ||
### Step 1: add using statement | ||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Use_Kernel_Functions_With_Other_Agent.cs?name=Using)] | ||
|
||
### Step 2: create plugin | ||
|
||
In this step, we create a simple plugin with a single `GetWeather` function that takes a location as input and returns the weather information for that location. | ||
|
||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Use_Kernel_Functions_With_Other_Agent.cs?name=Create_plugin)] | ||
|
||
### Step 3: create OpenAIChatAgent and use the plugin | ||
|
||
In this step, we firstly create a @AutoGen.SemanticKernel.KernelPluginMiddleware and register the previous plugin with it. The `KernelPluginMiddleware` will load the plugin and make the functions available for use in other agents. Followed by creating an @AutoGen.OpenAI.OpenAIChatAgent and register it with the `KernelPluginMiddleware`. | ||
|
||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Use_Kernel_Functions_With_Other_Agent.cs?name=Use_plugin)] | ||
|
||
### Step 4: chat with OpenAIChatAgent | ||
|
||
In this final step, we start the chat with the @AutoGen.OpenAI.OpenAIChatAgent by asking the weather in Seattle. The `OpenAIChatAgent` will use the `GetWeather` function from the plugin to get the weather information for Seattle. | ||
|
||
[!code-csharp[](../../../sample/AutoGen.SemanticKernel.Sample/Use_Kernel_Functions_With_Other_Agent.cs?name=Send_message)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.