-
Notifications
You must be signed in to change notification settings - Fork 841
Expose additional chat model conversion helpers #6629
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIAssistantsExtensions.cs
This file contains hidden or 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,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace OpenAI.Assistants; | ||
|
|
||
| /// <summary>Provides extension methods for working with content associated with OpenAI.Assistants.</summary> | ||
| public static class MicrosoftExtensionsAIAssistantsExtensions | ||
| { | ||
| /// <summary>Creates an OpenAI <see cref="FunctionToolDefinition"/> from an <see cref="AIFunction"/>.</summary> | ||
| /// <param name="function">The function to convert.</param> | ||
| /// <returns>An OpenAI <see cref="FunctionToolDefinition"/> representing <paramref name="function"/>.</returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="function"/> is <see langword="null"/>.</exception> | ||
| public static FunctionToolDefinition AsOpenAIAssistantsFunctionToolDefinition(this AIFunction function) => | ||
| OpenAIAssistantsChatClient.ToOpenAIAssistantsFunctionToolDefinition(Throw.IfNull(function)); | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIChatExtensions.cs
This file contains hidden or 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,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace OpenAI.Chat; | ||
|
|
||
| /// <summary>Provides extension methods for working with content associated with OpenAI.Chat.</summary> | ||
| public static class MicrosoftExtensionsAIChatExtensions | ||
| { | ||
| /// <summary>Creates an OpenAI <see cref="ChatTool"/> from an <see cref="AIFunction"/>.</summary> | ||
| /// <param name="function">The function to convert.</param> | ||
| /// <returns>An OpenAI <see cref="ChatTool"/> representing <paramref name="function"/>.</returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="function"/> is <see langword="null"/>.</exception> | ||
| public static ChatTool AsOpenAIChatTool(this AIFunction function) => | ||
| OpenAIChatClient.ToOpenAIChatTool(Throw.IfNull(function)); | ||
|
|
||
| /// <summary>Creates a sequence of OpenAI <see cref="ChatMessage"/> instances from the specified input messages.</summary> | ||
| /// <param name="messages">The input messages to convert.</param> | ||
| /// <returns>A sequence of OpenAI chat messages.</returns> | ||
| public static IEnumerable<ChatMessage> AsOpenAIChatMessages(this IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages) => | ||
| OpenAIChatClient.ToOpenAIChatMessages(Throw.IfNull(messages), chatOptions: null); | ||
|
|
||
| /// <summary>Creates a Microsoft.Extensions.AI <see cref="ChatResponse"/> from a <see cref="ChatCompletion"/>.</summary> | ||
| /// <param name="chatCompletion">The <see cref="ChatCompletion"/> to convert to a <see cref="ChatResponse"/>.</param> | ||
| /// <param name="options">The options employed in the creation of the response.</param> | ||
| /// <returns>A converted <see cref="ChatResponse"/>.</returns> | ||
| public static ChatResponse AsChatResponse(this ChatCompletion chatCompletion, ChatCompletionOptions? options = null) => | ||
| OpenAIChatClient.FromOpenAIChatCompletion(Throw.IfNull(chatCompletion), options); | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIRealtimeExtensions.cs
This file contains hidden or 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,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace OpenAI.Realtime; | ||
|
|
||
| /// <summary>Provides extension methods for working with content associated with OpenAI.Realtime.</summary> | ||
| public static class MicrosoftExtensionsAIRealtimeExtensions | ||
| { | ||
| /// <summary>Creates an OpenAI <see cref="ConversationFunctionTool"/> from an <see cref="AIFunction"/>.</summary> | ||
| /// <param name="function">The function to convert.</param> | ||
| /// <returns>An OpenAI <see cref="ConversationFunctionTool"/> representing <paramref name="function"/>.</returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="function"/> is <see langword="null"/>.</exception> | ||
| public static ConversationFunctionTool AsOpenAIConversationFunctionTool(this AIFunction function) => | ||
| OpenAIRealtimeConversationClient.ToOpenAIConversationFunctionTool(Throw.IfNull(function)); | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/Libraries/Microsoft.Extensions.AI.OpenAI/MicrosoftExtensionsAIResponsesExtensions.cs
This file contains hidden or 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,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace OpenAI.Responses; | ||
|
|
||
| /// <summary>Provides extension methods for working with content associated with OpenAI.Responses.</summary> | ||
| public static class MicrosoftExtensionsAIResponsesExtensions | ||
| { | ||
| /// <summary>Creates an OpenAI <see cref="ResponseTool"/> from an <see cref="AIFunction"/>.</summary> | ||
| /// <param name="function">The function to convert.</param> | ||
| /// <returns>An OpenAI <see cref="ResponseTool"/> representing <paramref name="function"/>.</returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="function"/> is <see langword="null"/>.</exception> | ||
| public static ResponseTool AsOpenAIResponseTool(this AIFunction function) => | ||
| OpenAIResponsesChatClient.ToResponseTool(Throw.IfNull(function)); | ||
|
|
||
| /// <summary>Creates a sequence of OpenAI <see cref="ResponseItem"/> instances from the specified input messages.</summary> | ||
| /// <param name="messages">The input messages to convert.</param> | ||
| /// <returns>A sequence of OpenAI response items.</returns> | ||
| public static IEnumerable<ResponseItem> AsOpenAIResponseItems(this IEnumerable<ChatMessage> messages) => | ||
| OpenAIResponsesChatClient.ToOpenAIResponseItems(Throw.IfNull(messages)); | ||
|
|
||
| /// <summary>Creates a Microsoft.Extensions.AI <see cref="ChatResponse"/> from an <see cref="OpenAIResponse"/>.</summary> | ||
| /// <param name="response">The <see cref="OpenAIResponse"/> to convert to a <see cref="ChatResponse"/>.</param> | ||
| /// <param name="options">The options employed in the creation of the response.</param> | ||
| /// <returns>A converted <see cref="ChatResponse"/>.</returns> | ||
| public static ChatResponse AsChatResponse(this OpenAIResponse response, ResponseCreationOptions? options = null) => | ||
| OpenAIResponsesChatClient.FromOpenAIResponse(Throw.IfNull(response), options); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.