-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.Net][AutoGen.OpenAI] Allow nullable system message, temperature and…
… max token to support o1-preview model (#3524) * add connect to o1 example * Update Connect_To_OpenAI_o1_preview.cs
- Loading branch information
1 parent
63d3297
commit e76c39e
Showing
2 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
dotnet/sample/AutoGen.OpenAI.Sample/Connect_To_OpenAI_o1_preview.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Connect_To_OpenAI_o1_preview.cs | ||
|
||
using AutoGen.Core; | ||
using OpenAI; | ||
|
||
namespace AutoGen.OpenAI.Sample; | ||
|
||
public class Connect_To_OpenAI_o1_preview | ||
{ | ||
public static async Task RunAsync() | ||
{ | ||
#region create_agent | ||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("Please set environment variable OPENAI_API_KEY"); | ||
var openAIClient = new OpenAIClient(apiKey); | ||
|
||
// until 2024/09/12 | ||
// openai o1-preview doesn't support systemMessage, temperature, maxTokens, streaming output | ||
// so in order to use OpenAIChatAgent with o1-preview, you need to set those parameters to null | ||
var agent = new OpenAIChatAgent( | ||
chatClient: openAIClient.GetChatClient("o1-preview"), | ||
name: "assistant", | ||
systemMessage: null, | ||
temperature: null, | ||
maxTokens: null, | ||
seed: 0) | ||
// by using RegisterMiddleware instead of RegisterStreamingMiddleware | ||
// it turns an IStreamingAgent into an IAgent and disables streaming | ||
.RegisterMiddleware(new OpenAIChatRequestMessageConnector()) | ||
.RegisterPrintMessage(); | ||
#endregion create_agent | ||
|
||
#region send_message | ||
await agent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?"); | ||
#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