Skip to content

Commit 54e9026

Browse files
moved OpenAI extensions completly to the OpenAI extensions package (Azure#47498)
1 parent b439fb8 commit 54e9026

16 files changed

+103
-62
lines changed

eng/Packages.Data.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@
194194
<PackageReference Update="NUnit" Version="3.13.2" />
195195
</ItemGroup>
196196

197-
<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.Provisioning.CloudMachine'))">
198-
<PackageReference Update="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
197+
<ItemGroup Condition="$(MSBuildProjectName.Contains('CloudMachine'))">
198+
<PackageReference Update="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
199+
<PackageReference Update="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0"/>
199200
</ItemGroup>
200201

201202
<!--

sdk/cloudmachine/Azure.CloudMachine.OpenAI/api/Azure.CloudMachine.OpenAI.net8.0.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
namespace Azure.CloudMachine.OpenAI
22
{
3+
public enum AIModelKind
4+
{
5+
Chat = 0,
6+
Embedding = 1,
7+
}
38
public static partial class AzureOpenAIExtensions
49
{
510
public static void Add(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages, OpenAI.Chat.ChatCompletion completion) { }
@@ -24,17 +29,26 @@ public void Add(System.Type functions) { }
2429
}
2530
public partial class EmbeddingsVectorbase
2631
{
27-
public EmbeddingsVectorbase(OpenAI.Embeddings.EmbeddingClient client, Azure.CloudMachine.OpenAI.VectorbaseStore store = null, int factChunkSize = 1000) { }
32+
public EmbeddingsVectorbase(OpenAI.Embeddings.EmbeddingClient client, Azure.CloudMachine.OpenAI.VectorbaseStore? store = null, int factChunkSize = 1000) { }
2833
public void Add(System.BinaryData data) { }
2934
public void Add(string text) { }
30-
public System.Collections.Generic.IEnumerable<Azure.CloudMachine.OpenAI.VectorbaseEntry> Find(string text, Azure.CloudMachine.OpenAI.FindOptions options = null) { throw null; }
35+
public System.Collections.Generic.IEnumerable<Azure.CloudMachine.OpenAI.VectorbaseEntry> Find(string text, Azure.CloudMachine.OpenAI.FindOptions? options = null) { throw null; }
3136
}
3237
public partial class FindOptions
3338
{
3439
public FindOptions() { }
3540
public int MaxEntries { get { throw null; } set { } }
3641
public float Threshold { get { throw null; } set { } }
3742
}
43+
public partial class OpenAIModelFeature : Azure.CloudMachine.Core.CloudMachineFeature
44+
{
45+
public OpenAIModelFeature(string model, string modelVersion, Azure.CloudMachine.OpenAI.AIModelKind kind = Azure.CloudMachine.OpenAI.AIModelKind.Chat) { }
46+
public string Model { get { throw null; } }
47+
public string ModelVersion { get { throw null; } }
48+
protected override void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { }
49+
protected override void EmitFeatures(Azure.CloudMachine.Core.FeatureCollection features, string cmId) { }
50+
protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm) { throw null; }
51+
}
3852
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
3953
public readonly partial struct VectorbaseEntry
4054
{

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
namespace Azure.CloudMachine.OpenAI
22
{
3+
public enum AIModelKind
4+
{
5+
Chat = 0,
6+
Embedding = 1,
7+
}
38
public static partial class AzureOpenAIExtensions
49
{
510
public static void Add(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages, OpenAI.Chat.ChatCompletion completion) { }
@@ -24,17 +29,26 @@ public void Add(System.Type functions) { }
2429
}
2530
public partial class EmbeddingsVectorbase
2631
{
27-
public EmbeddingsVectorbase(OpenAI.Embeddings.EmbeddingClient client, Azure.CloudMachine.OpenAI.VectorbaseStore store = null, int factChunkSize = 1000) { }
32+
public EmbeddingsVectorbase(OpenAI.Embeddings.EmbeddingClient client, Azure.CloudMachine.OpenAI.VectorbaseStore? store = null, int factChunkSize = 1000) { }
2833
public void Add(System.BinaryData data) { }
2934
public void Add(string text) { }
30-
public System.Collections.Generic.IEnumerable<Azure.CloudMachine.OpenAI.VectorbaseEntry> Find(string text, Azure.CloudMachine.OpenAI.FindOptions options = null) { throw null; }
35+
public System.Collections.Generic.IEnumerable<Azure.CloudMachine.OpenAI.VectorbaseEntry> Find(string text, Azure.CloudMachine.OpenAI.FindOptions? options = null) { throw null; }
3136
}
3237
public partial class FindOptions
3338
{
3439
public FindOptions() { }
3540
public int MaxEntries { get { throw null; } set { } }
3641
public float Threshold { get { throw null; } set { } }
3742
}
43+
public partial class OpenAIModelFeature : Azure.CloudMachine.Core.CloudMachineFeature
44+
{
45+
public OpenAIModelFeature(string model, string modelVersion, Azure.CloudMachine.OpenAI.AIModelKind kind = Azure.CloudMachine.OpenAI.AIModelKind.Chat) { }
46+
public string Model { get { throw null; } }
47+
public string ModelVersion { get { throw null; } }
48+
protected override void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { }
49+
protected override void EmitFeatures(Azure.CloudMachine.Core.FeatureCollection features, string cmId) { }
50+
protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm) { throw null; }
51+
}
3852
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
3953
public readonly partial struct VectorbaseEntry
4054
{

sdk/cloudmachine/Azure.CloudMachine.OpenAI/src/Azure.CloudMachine.OpenAI.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>AI extensions for Azure.CloudMachine</Description>
55
<Version>1.0.0-beta.1</Version>
66
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
77
<LangVersion>12</LangVersion>
8+
<Nullable>enable</Nullable>
89

910
<!-- Disable warning CS1591: Missing XML comment for publicly visible type or member -->
1011
<NoWarn>CS1591</NoWarn>
@@ -13,8 +14,10 @@
1314

1415
<ItemGroup>
1516
<ProjectReference Include="..\..\Azure.CloudMachine\src\Azure.CloudMachine.csproj" />
17+
<ProjectReference Include="..\..\Azure.Provisioning.CloudMachine\src\Azure.Provisioning.CloudMachine.csproj" />
1618
<PackageReference Include="Azure.AI.OpenAI" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" VersionOverride="8.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
1821
<PackageReference Include="Microsoft.Bcl.Numerics" />
1922
<PackageReference Include="System.Memory.Data" VersionOverride="8.0.0"/>
2023
</ItemGroup>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public void Add(MethodInfo function)
8282
public string Call(string name, object[] arguments)
8383
{
8484
MethodInfo method = _methods[name];
85-
object result = method.Invoke(null, arguments);
86-
return result.ToString();
85+
object? result = method.Invoke(null, arguments);
86+
return result!.ToString()!;
8787
}
8888

8989
/// <summary>
@@ -146,18 +146,18 @@ public IEnumerable<ToolChatMessage> CallAll(IEnumerable<ChatToolCall> toolCalls)
146146
private static string MethodInfoToDescription(MethodInfo function)
147147
{
148148
var description = function.Name;
149-
DescriptionAttribute attribute = function.GetCustomAttribute<DescriptionAttribute>();
149+
DescriptionAttribute? attribute = function.GetCustomAttribute<DescriptionAttribute>();
150150
if (attribute != null)
151151
{
152152
description = attribute.Description;
153153
}
154154
return description;
155155
}
156156

157-
private static string ParameterInfoToDescription(ParameterInfo parameter)
157+
private static string? ParameterInfoToDescription(ParameterInfo parameter)
158158
{
159-
var description = parameter.Name;
160-
DescriptionAttribute attribute = parameter.GetCustomAttribute<DescriptionAttribute>();
159+
string? description = parameter.Name;
160+
DescriptionAttribute? attribute = parameter.GetCustomAttribute<DescriptionAttribute>();
161161
if (attribute != null)
162162
{
163163
description = attribute.Description;

sdk/cloudmachine/Azure.CloudMachine.OpenAI/src/EmbeddingsVectorbase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class EmbeddingsVectorbase
2323
/// <param name="client"></param>
2424
/// <param name="store"></param>
2525
/// <param name="factChunkSize"></param>
26-
public EmbeddingsVectorbase(EmbeddingClient client, VectorbaseStore store = default, int factChunkSize = 1000)
26+
public EmbeddingsVectorbase(EmbeddingClient client, VectorbaseStore? store = default, int factChunkSize = 1000)
2727
{
2828
_client = client;
2929
_store = store ?? new MemoryVectorbaseStore();
@@ -59,7 +59,7 @@ public void Add(BinaryData data)
5959
/// <param name="text"></param>
6060
/// <param name="options"></param>
6161
/// <returns></returns>
62-
public IEnumerable<VectorbaseEntry> Find(string text, FindOptions options = default)
62+
public IEnumerable<VectorbaseEntry> Find(string text, FindOptions? options = default)
6363
{
6464
options ??= new FindOptions();
6565
if (_todo.Count > 0)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override ProvisionableResource EmitResources(CloudMachineInfrastructur
2323
return cognitiveServices;
2424
}
2525

26-
protected internal override void EmitConnections(ConnectionCollection connections, string cmId)
26+
protected override void EmitConnections(ConnectionCollection connections, string cmId)
2727
{
2828
ClientConnection connection = new("Azure.AI.OpenAI.AzureOpenAIClient", $"https://{cmId}.openai.azure.com");
2929

@@ -32,6 +32,8 @@ protected internal override void EmitConnections(ConnectionCollection connection
3232
connections.Add(connection);
3333
}
3434
}
35+
internal void EmitConnectionsInternal(ConnectionCollection connections, string cmId)
36+
=> EmitConnections(connections, cmId);
3537

3638
internal static CognitiveServicesAccount CreateOpenAIAccount(CloudMachineInfrastructure cm)
3739
{
Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,42 @@
1010

1111
namespace Azure.CloudMachine.OpenAI;
1212

13+
/// <summary>
14+
/// CloudMachine feature for OpenAI models.
15+
/// </summary>
1316
public class OpenAIModelFeature : CloudMachineFeature
1417
{
18+
/// <summary>
19+
/// Create a new OpenAI model feature.
20+
/// </summary>
21+
/// <param name="model"></param>
22+
/// <param name="modelVersion"></param>
23+
/// <param name="kind"></param>
1524
public OpenAIModelFeature(string model, string modelVersion, AIModelKind kind = AIModelKind.Chat) {
1625
Kind = kind;
1726
Model = model;
1827
ModelVersion = modelVersion;
1928
}
2029

30+
/// <summary>
31+
/// The model name.
32+
/// </summary>
2133
public string Model { get; }
34+
35+
/// <summary>
36+
/// The model version.
37+
/// </summary>
2238
public string ModelVersion { get; }
2339
private AIModelKind Kind { get; }
2440

2541
internal OpenAIFeature Account { get; set; } = default!;
2642

27-
protected internal override void EmitFeatures(FeatureCollection features, string cmId)
43+
/// <summary>
44+
/// Emit the feature.
45+
/// </summary>
46+
/// <param name="features"></param>
47+
/// <param name="cmId"></param>
48+
protected override void EmitFeatures(FeatureCollection features, string cmId)
2849
{
2950
// TODO: is it OK that we return the first one?
3051
OpenAIFeature? openAI = features.FindAll<OpenAIFeature>().FirstOrDefault();
@@ -37,9 +58,15 @@ protected internal override void EmitFeatures(FeatureCollection features, string
3758
features.Add(this);
3859
}
3960

40-
protected internal override void EmitConnections(ConnectionCollection connections, string cmId)
61+
/// <summary>
62+
/// Emit the connections.
63+
/// </summary>
64+
/// <param name="connections"></param>
65+
/// <param name="cmId"></param>
66+
/// <exception cref="NotImplementedException"></exception>
67+
protected override void EmitConnections(ConnectionCollection connections, string cmId)
4168
{
42-
Account.EmitConnections(connections, cmId);
69+
Account.EmitConnectionsInternal(connections, cmId);
4370
// add connections
4471
switch (Kind)
4572
{
@@ -54,6 +81,13 @@ protected internal override void EmitConnections(ConnectionCollection connection
5481
}
5582
}
5683

84+
/// <summary>
85+
/// Emit the resources.
86+
/// </summary>
87+
/// <param name="cm"></param>
88+
/// <returns></returns>
89+
/// <exception cref="InvalidOperationException"></exception>
90+
/// <exception cref="NotImplementedException"></exception>
5791
protected override ProvisionableResource EmitResources(CloudMachineInfrastructure cm)
5892
{
5993
if (Account == null) throw new InvalidOperationException("Account must be set before emitting");
@@ -116,8 +150,17 @@ protected override ProvisionableResource EmitResources(CloudMachineInfrastructur
116150
}
117151
}
118152

153+
/// <summary>
154+
/// The kind of OpenAI model.
155+
/// </summary>
119156
public enum AIModelKind
120157
{
158+
/// <summary>
159+
/// Chat model.
160+
/// </summary>
121161
Chat,
162+
/// <summary>
163+
/// Embedding model.
164+
/// </summary>
122165
Embedding,
123166
}

sdk/cloudmachine/Azure.CloudMachine.OpenAI/tests/Azure.CloudMachine.OpenAI.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Microsoft.Extensions.Configuration"/>
7+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
78
<PackageReference Include="NUnit" />
89
<PackageReference Include="NUnit3TestAdapter" />
910
<PackageReference Include="Microsoft.NET.Test.Sdk" />

sdk/cloudmachine/Azure.CloudMachine/src/Azure.CloudMachine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PackageReference Include="Azure.Messaging.EventGrid" />
1919
<PackageReference Include="Azure.Storage.Blobs" />
2020
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
21-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" VersionOverride="8.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions"/>
2222
<PackageReference Include="System.Memory.Data" VersionOverride="8.0.0"/>
2323
</ItemGroup>
2424

0 commit comments

Comments
 (0)