Skip to content

Commit 313748c

Browse files
updated apis (Azure#47007)
1 parent 73d1124 commit 313748c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.netstandard2.0.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ namespace Azure.CloudMachine.OpenAI
7777
{
7878
public static partial class AzureOpenAIExtensions
7979
{
80+
public static void Add(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages, OpenAI.Chat.ChatCompletion completion) { }
8081
public static void Add(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages, System.Collections.Generic.IEnumerable<Azure.CloudMachine.OpenAI.VectorbaseEntry> entries) { }
8182
public static OpenAI.Chat.ChatClient GetOpenAIChatClient(this Azure.Core.ClientWorkspace workspace) { throw null; }
8283
public static OpenAI.Embeddings.EmbeddingClient GetOpenAIEmbeddingsClient(this Azure.Core.ClientWorkspace workspace) { throw null; }
@@ -96,6 +97,7 @@ public void Add(System.Type functions) { }
9697
protected virtual string GetMethodInfoToDescription(System.Reflection.MethodInfo function) { throw null; }
9798
protected virtual string GetMethodInfoToName(System.Reflection.MethodInfo function) { throw null; }
9899
protected virtual string GetParameterInfoToDescription(System.Reflection.ParameterInfo parameter) { throw null; }
100+
public static implicit operator OpenAI.Chat.ChatCompletionOptions (Azure.CloudMachine.OpenAI.ChatTools tools) { throw null; }
99101
}
100102
public partial class EmbeddingsVectorbase
101103
{

sdk/cloudmachine/Azure.CloudMachine/src/extensions/AzureOpenAIExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ public static void Add(this List<ChatMessage> messages, IEnumerable<VectorbaseEn
9595
messages.Add(ChatMessage.CreateSystemMessage(entry.Data.ToString()));
9696
}
9797
}
98+
99+
/// <summary>
100+
/// Adds a chat completion as an AssistantChatMessage to the list of chat messages.
101+
/// </summary>
102+
/// <param name="messages"></param>
103+
/// <param name="completion"></param>
104+
public static void Add(this List<ChatMessage> messages, ChatCompletion completion)
105+
=> messages.Add(ChatMessage.CreateAssistantMessage(completion));
98106
}

sdk/cloudmachine/Azure.CloudMachine/src/extensions/ChatTools.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reflection;
99
using System.Text;
1010
using System.Text.Json;
11+
using Azure.Messaging.EventGrid.SystemEvents;
1112
using OpenAI.Chat;
1213

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

39+
/// <summary>
40+
/// Implicitly converts a <see cref="ChatTools"/> to <see cref="ChatCompletionOptions"/>.
41+
/// </summary>
42+
/// <param name="tools"></param>
43+
public static implicit operator ChatCompletionOptions(ChatTools tools)
44+
{
45+
ChatCompletionOptions options = new();
46+
foreach (var tool in tools.Definitions)
47+
{
48+
options.Tools.Add(tool);
49+
}
50+
return options;
51+
}
52+
3853
/// <summary>
3954
/// Adds a set of functions to the chat functions.
4055
/// </summary>

0 commit comments

Comments
 (0)