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.

Connect_To_OpenAI_o1_preview.cs 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Connect_To_OpenAI_o1_preview.cs
  3. using AutoGen.Core;
  4. using OpenAI;
  5. namespace AutoGen.OpenAI.Sample;
  6. public class Connect_To_OpenAI_o1_preview
  7. {
  8. public static async Task RunAsync()
  9. {
  10. #region create_agent
  11. var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("Please set environment variable OPENAI_API_KEY");
  12. var openAIClient = new OpenAIClient(apiKey);
  13. // until 2024/09/12
  14. // openai o1-preview doesn't support systemMessage, temperature, maxTokens, streaming output
  15. // so in order to use OpenAIChatAgent with o1-preview, you need to set those parameters to null
  16. var agent = new OpenAIChatAgent(
  17. chatClient: openAIClient.GetChatClient("o1-preview"),
  18. name: "assistant",
  19. systemMessage: null,
  20. temperature: null,
  21. maxTokens: null,
  22. seed: 0)
  23. // by using RegisterMiddleware instead of RegisterStreamingMiddleware
  24. // it turns an IStreamingAgent into an IAgent and disables streaming
  25. .RegisterMiddleware(new OpenAIChatRequestMessageConnector())
  26. .RegisterPrintMessage();
  27. #endregion create_agent
  28. #region send_message
  29. await agent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?");
  30. #endregion send_message
  31. }
  32. }