You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Create_Semantic_Kernel_Agent.cs 1.1 kB

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Create_Semantic_Kernel_Agent.cs
  3. using AutoGen.Core;
  4. using AutoGen.SemanticKernel.Extension;
  5. using Microsoft.SemanticKernel;
  6. namespace AutoGen.SemanticKernel.Sample;
  7. public class Create_Semantic_Kernel_Agent
  8. {
  9. public static async Task RunAsync()
  10. {
  11. var openAIKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new Exception("Please set OPENAI_API_KEY environment variable.");
  12. var modelId = "gpt-3.5-turbo";
  13. var kernel = Kernel.CreateBuilder()
  14. .AddOpenAIChatCompletion(modelId: modelId, apiKey: openAIKey)
  15. .Build();
  16. var skAgent = new SemanticKernelAgent(
  17. kernel: kernel,
  18. name: "assistant",
  19. systemMessage: "You are a helpful AI assistant")
  20. .RegisterMessageConnector() // register message connector so it support AutoGen built-in message types like TextMessage.
  21. .RegisterPrintMessage(); // pretty print the message to the console
  22. await skAgent.SendAsync("Hey tell me a long tedious joke");
  23. }
  24. }