Skip to content
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

Added some OpenAI helper APIs #47007

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace Azure.CloudMachine.OpenAI
{
public static partial class AzureOpenAIExtensions
{
public static void Add(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages, OpenAI.Chat.ChatCompletion completion) { }
public static void Add(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages, System.Collections.Generic.IEnumerable<Azure.CloudMachine.OpenAI.VectorbaseEntry> entries) { }
public static OpenAI.Chat.ChatClient GetOpenAIChatClient(this Azure.Core.ClientWorkspace workspace) { throw null; }
public static OpenAI.Embeddings.EmbeddingClient GetOpenAIEmbeddingsClient(this Azure.Core.ClientWorkspace workspace) { throw null; }
Expand All @@ -96,6 +97,7 @@ public void Add(System.Type functions) { }
protected virtual string GetMethodInfoToDescription(System.Reflection.MethodInfo function) { throw null; }
protected virtual string GetMethodInfoToName(System.Reflection.MethodInfo function) { throw null; }
protected virtual string GetParameterInfoToDescription(System.Reflection.ParameterInfo parameter) { throw null; }
public static implicit operator OpenAI.Chat.ChatCompletionOptions (Azure.CloudMachine.OpenAI.ChatTools tools) { throw null; }
}
public partial class EmbeddingsVectorbase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ public static void Add(this List<ChatMessage> messages, IEnumerable<VectorbaseEn
messages.Add(ChatMessage.CreateSystemMessage(entry.Data.ToString()));
}
}

/// <summary>
/// Adds a chat completion as an AssistantChatMessage to the list of chat messages.
/// </summary>
/// <param name="messages"></param>
/// <param name="completion"></param>
public static void Add(this List<ChatMessage> messages, ChatCompletion completion)
=> messages.Add(ChatMessage.CreateAssistantMessage(completion));
}
15 changes: 15 additions & 0 deletions sdk/cloudmachine/Azure.CloudMachine/src/extensions/ChatTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Text;
using System.Text.Json;
using Azure.Messaging.EventGrid.SystemEvents;
using OpenAI.Chat;

namespace Azure.CloudMachine.OpenAI;
Expand Down Expand Up @@ -35,6 +36,20 @@ public ChatTools(params Type[] tools)
/// </summary>
public IList<ChatTool> Definitions => _definitions;

/// <summary>
/// Implicitly converts a <see cref="ChatTools"/> to <see cref="ChatCompletionOptions"/>.
/// </summary>
/// <param name="tools"></param>
public static implicit operator ChatCompletionOptions(ChatTools tools)
{
ChatCompletionOptions options = new();
foreach (var tool in tools.Definitions)
{
options.Tools.Add(tool);
}
return options;
}

/// <summary>
/// Adds a set of functions to the chat functions.
/// </summary>
Expand Down