Skip to content

Commit

Permalink
updated apis (#47007)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofCwalina authored Nov 7, 2024
1 parent 73d1124 commit 313748c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit 313748c

Please sign in to comment.