Skip to content

Commit c48797a

Browse files
Added support for OFX back. (#48860)
* OFX provisioning is now done through features. * small cleanup * simplified how parent resources are acessed * cleanup * tests pass * added test for two containers * added support for observable container feature * added support for SB * topic is now a feature * sb is all features * added CloudMachineFeature * all tests pass * all tests pass * added some tests * added connection tests * tests pass * Ofx works * disabled live tests * cleaned up ragmachine app * updated apis * fidex build * recased files
1 parent 796f365 commit c48797a

File tree

71 files changed

+2439
-1116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2439
-1116
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class ChatProcessor
2525
public ChatProcessor(OpenAI.Chat.ChatClient chat) { }
2626
public ChatProcessor(OpenAI.Chat.ChatClient chat, OpenAI.Embeddings.EmbeddingClient? embeddings, Azure.Projects.OpenAI.ChatTools? tools = null) { }
2727
public Azure.Projects.OpenAI.ChatTools? Tools { get { throw null; } set { } }
28-
public Azure.Projects.OpenAI.EmbeddingsVectorbase? VectorDb { get { throw null; } set { } }
28+
public Azure.Projects.OpenAI.EmbeddingsStore? VectorDb { get { throw null; } set { } }
2929
protected virtual OpenAI.Chat.ChatCompletion OnComplete(System.Collections.Generic.List<OpenAI.Chat.ChatMessage> conversation, string prompt) { throw null; }
3030
protected virtual void OnGround(System.Collections.Generic.List<OpenAI.Chat.ChatMessage> conversation, string prompt) { }
3131
protected virtual void OnLength(System.Collections.Generic.List<OpenAI.Chat.ChatMessage> conversation, OpenAI.Chat.ChatCompletion completion) { }
@@ -47,9 +47,9 @@ public void Add(System.Type functions) { }
4747
public static implicit operator OpenAI.Chat.ChatCompletionOptions (Azure.Projects.OpenAI.ChatTools tools) { throw null; }
4848
public OpenAI.Chat.ChatCompletionOptions ToOptions() { throw null; }
4949
}
50-
public partial class EmbeddingsVectorbase
50+
public partial class EmbeddingsStore
5151
{
52-
public EmbeddingsVectorbase(OpenAI.Embeddings.EmbeddingClient client, Azure.Projects.OpenAI.VectorbaseStore? store = null, int factChunkSize = 1000) { }
52+
public EmbeddingsStore(OpenAI.Embeddings.EmbeddingClient client, Azure.Projects.OpenAI.VectorbaseStore? store = null, int factChunkSize = 1000) { }
5353
public void Add(System.BinaryData data) { }
5454
public void Add(string text) { }
5555
public System.Collections.Generic.IEnumerable<Azure.Projects.OpenAI.VectorbaseEntry> Find(string text, Azure.Projects.OpenAI.FindOptions? options = null) { throw null; }
@@ -73,9 +73,9 @@ public partial class OpenAIModelFeature : Azure.Projects.Core.AzureProjectFeatur
7373
public OpenAIModelFeature(string model, string modelVersion, Azure.Projects.OpenAI.AIModelKind kind = Azure.Projects.OpenAI.AIModelKind.Chat) { }
7474
public string Model { get { throw null; } }
7575
public string ModelVersion { get { throw null; } }
76-
protected override void AddImplicitFeatures(Azure.Projects.Core.FeatureCollection features, string cmId) { }
7776
public System.ClientModel.Primitives.ClientConnection CreateConnection(string cmId) { throw null; }
78-
protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.Projects.ProjectInfrastructure cm) { throw null; }
77+
protected override void EmitConstructs(Azure.Projects.ProjectInfrastructure infrastructure) { }
78+
protected override void EmitFeatures(Azure.Projects.ProjectInfrastructure infrastructure) { }
7979
}
8080
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
8181
public readonly partial struct VectorbaseEntry

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class ChatProcessor
2525
public ChatProcessor(OpenAI.Chat.ChatClient chat) { }
2626
public ChatProcessor(OpenAI.Chat.ChatClient chat, OpenAI.Embeddings.EmbeddingClient? embeddings, Azure.Projects.OpenAI.ChatTools? tools = null) { }
2727
public Azure.Projects.OpenAI.ChatTools? Tools { get { throw null; } set { } }
28-
public Azure.Projects.OpenAI.EmbeddingsVectorbase? VectorDb { get { throw null; } set { } }
28+
public Azure.Projects.OpenAI.EmbeddingsStore? VectorDb { get { throw null; } set { } }
2929
protected virtual OpenAI.Chat.ChatCompletion OnComplete(System.Collections.Generic.List<OpenAI.Chat.ChatMessage> conversation, string prompt) { throw null; }
3030
protected virtual void OnGround(System.Collections.Generic.List<OpenAI.Chat.ChatMessage> conversation, string prompt) { }
3131
protected virtual void OnLength(System.Collections.Generic.List<OpenAI.Chat.ChatMessage> conversation, OpenAI.Chat.ChatCompletion completion) { }
@@ -47,9 +47,9 @@ public void Add(System.Type functions) { }
4747
public static implicit operator OpenAI.Chat.ChatCompletionOptions (Azure.Projects.OpenAI.ChatTools tools) { throw null; }
4848
public OpenAI.Chat.ChatCompletionOptions ToOptions() { throw null; }
4949
}
50-
public partial class EmbeddingsVectorbase
50+
public partial class EmbeddingsStore
5151
{
52-
public EmbeddingsVectorbase(OpenAI.Embeddings.EmbeddingClient client, Azure.Projects.OpenAI.VectorbaseStore? store = null, int factChunkSize = 1000) { }
52+
public EmbeddingsStore(OpenAI.Embeddings.EmbeddingClient client, Azure.Projects.OpenAI.VectorbaseStore? store = null, int factChunkSize = 1000) { }
5353
public void Add(System.BinaryData data) { }
5454
public void Add(string text) { }
5555
public System.Collections.Generic.IEnumerable<Azure.Projects.OpenAI.VectorbaseEntry> Find(string text, Azure.Projects.OpenAI.FindOptions? options = null) { throw null; }
@@ -73,9 +73,9 @@ public partial class OpenAIModelFeature : Azure.Projects.Core.AzureProjectFeatur
7373
public OpenAIModelFeature(string model, string modelVersion, Azure.Projects.OpenAI.AIModelKind kind = Azure.Projects.OpenAI.AIModelKind.Chat) { }
7474
public string Model { get { throw null; } }
7575
public string ModelVersion { get { throw null; } }
76-
protected override void AddImplicitFeatures(Azure.Projects.Core.FeatureCollection features, string cmId) { }
7776
public System.ClientModel.Primitives.ClientConnection CreateConnection(string cmId) { throw null; }
78-
protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.Projects.ProjectInfrastructure cm) { throw null; }
77+
protected override void EmitConstructs(Azure.Projects.ProjectInfrastructure infrastructure) { }
78+
protected override void EmitFeatures(Azure.Projects.ProjectInfrastructure infrastructure) { }
7979
}
8080
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
8181
public readonly partial struct VectorbaseEntry

sdk/cloudmachine/Azure.Projects.OpenAI/src/CHatProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ChatProcessor
1717
/// <summary>
1818
/// Vector db.
1919
/// </summary>
20-
public EmbeddingsVectorbase? VectorDb { get; set; }
20+
public EmbeddingsStore? VectorDb { get; set; }
2121

2222
/// <summary>
2323
/// Tools to call.

sdk/cloudmachine/Azure.Projects.OpenAI/src/EmbeddingsVectorbase.cs sdk/cloudmachine/Azure.Projects.OpenAI/src/EmbeddingsStore.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ namespace Azure.Projects.OpenAI;
1010
/// <summary>
1111
/// The vectorbase for storing embeddings.
1212
/// </summary>
13-
public class EmbeddingsVectorbase
13+
public class EmbeddingsStore
1414
{
1515
private readonly EmbeddingClient _client;
1616
private readonly VectorbaseStore _store;
1717
private readonly List<string> _todo = [];
1818
private readonly int _chuckSize;
1919

2020
/// <summary>
21-
/// Initializes a new instance of the <see cref="EmbeddingsVectorbase"/> class.
21+
/// Initializes a new instance of the <see cref="EmbeddingsStore"/> class.
2222
/// </summary>
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 EmbeddingsStore(EmbeddingClient client, VectorbaseStore? store = default, int factChunkSize = 1000)
2727
{
2828
_client = client;
2929
_store = store ?? new MemoryVectorbaseStore();

sdk/cloudmachine/Azure.Projects.OpenAI/src/OpenAIAccountFeature.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
54
using Azure.Projects.Core;
65
using Azure.Provisioning.CognitiveServices;
7-
using Azure.Provisioning.Primitives;
86

97
namespace Azure.Projects.OpenAI;
108

119
internal class OpenAIAccountFeature : AzureProjectFeature
1210
{
13-
protected override ProvisionableResource EmitResources(ProjectInfrastructure infrastructure)
11+
public OpenAIAccountFeature()
12+
{}
13+
14+
protected override void EmitConstructs(ProjectInfrastructure infrastructure)
1415
{
1516
CognitiveServicesAccount cognitiveServices = new("openai")
1617
{
@@ -24,7 +25,7 @@ protected override ProvisionableResource EmitResources(ProjectInfrastructure inf
2425
},
2526
};
2627

27-
infrastructure.AddConstruct(cognitiveServices);
28+
infrastructure.AddConstruct(Id, cognitiveServices);
2829

2930
infrastructure.AddSystemRole(
3031
cognitiveServices,
@@ -33,7 +34,5 @@ protected override ProvisionableResource EmitResources(ProjectInfrastructure inf
3334
);
3435

3536
EmitConnection(infrastructure, "Azure.AI.OpenAI.AzureOpenAIClient", $"https://{infrastructure.ProjectId}.openai.azure.com");
36-
37-
return cognitiveServices;
3837
}
3938
}

sdk/cloudmachine/Azure.Projects.OpenAI/src/OpenAIModelFeature.cs

+29-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.ClientModel.Primitives;
66
using Azure.Projects.Core;
77
using Azure.Provisioning.CognitiveServices;
8-
using Azure.Provisioning.Primitives;
98

109
namespace Azure.Projects.OpenAI;
1110

@@ -20,7 +19,9 @@ public class OpenAIModelFeature : AzureProjectFeature
2019
/// <param name="model"></param>
2120
/// <param name="modelVersion"></param>
2221
/// <param name="kind"></param>
23-
public OpenAIModelFeature(string model, string modelVersion, AIModelKind kind = AIModelKind.Chat) {
22+
public OpenAIModelFeature(string model, string modelVersion, AIModelKind kind = AIModelKind.Chat)
23+
: base($"{typeof(OpenAIModelFeature).FullName}_{model}")
24+
{
2425
Kind = kind;
2526
Model = model;
2627
ModelVersion = modelVersion;
@@ -50,49 +51,51 @@ public ClientConnection CreateConnection(string cmId)
5051
ClientConnection connection = new("Azure.AI.OpenAI.AzureOpenAIClient", $"https://{cmId}.openai.azure.com", ClientAuthenticationMethod.Credential);
5152
return connection;
5253
}
54+
5355
/// <summary>
5456
/// Emit the feature.
5557
/// </summary>
56-
/// <param name="features"></param>
57-
/// <param name="cmId"></param>
58-
protected override void AddImplicitFeatures(FeatureCollection features, string cmId)
58+
protected override void EmitFeatures(ProjectInfrastructure infrastructure)
5959
{
60-
// TODO: is it OK that we return the first one?
61-
60+
FeatureCollection features = infrastructure.Features;
6261
if (!features.TryGet(out OpenAIAccountFeature? openAI))
6362
{
6463
openAI = new OpenAIAccountFeature();
6564
features.Append(openAI);
6665
}
6766

6867
Account = openAI!;
68+
6969
features.Append(this);
7070
}
7171

7272
/// <summary>
7373
/// Emit the resources.
7474
/// </summary>
75-
/// <param name="cm"></param>
76-
/// <returns></returns>
75+
/// <param name="infrastructure"></param>
7776
/// <exception cref="InvalidOperationException"></exception>
7877
/// <exception cref="NotImplementedException"></exception>
79-
protected override ProvisionableResource EmitResources(ProjectInfrastructure cm)
78+
protected override void EmitConstructs(ProjectInfrastructure infrastructure)
8079
{
81-
if (Account == null) throw new InvalidOperationException("Account must be set before emitting");
82-
if (Account.Resource == null) throw new InvalidOperationException("Account must be emitted before emitting");
80+
string suffix = Kind switch
81+
{
82+
AIModelKind.Chat => "chat",
83+
AIModelKind.Embedding => "embedding",
84+
_ => throw new NotImplementedException()
85+
};
8386

84-
string name = Kind switch
87+
string resourceName = Kind switch
8588
{
86-
AIModelKind.Chat => $"{cm.ProjectId}_chat",
87-
AIModelKind.Embedding => $"{cm.ProjectId}_embedding",
89+
AIModelKind.Chat => $"{infrastructure.ProjectId}_{suffix}",
90+
AIModelKind.Embedding => $"{infrastructure.ProjectId}_{suffix}",
8891
_ => throw new NotImplementedException()
8992
};
9093

91-
CognitiveServicesAccount parent = (CognitiveServicesAccount)Account.Resource;
94+
CognitiveServicesAccount parent = infrastructure.GetConstruct<CognitiveServicesAccount>(Account.Id);
9295

93-
CognitiveServicesAccountDeployment deployment = new($"openai_{name}", "2024-06-01-preview") {
96+
CognitiveServicesAccountDeployment deployment = new($"openai_{suffix}", "2024-06-01-preview") {
9497
Parent = parent,
95-
Name = name,
98+
Name = resourceName,
9699
Properties = new CognitiveServicesAccountDeploymentProperties()
97100
{
98101
Model = new CognitiveServicesAccountDeploymentModel()
@@ -111,27 +114,23 @@ protected override ProvisionableResource EmitResources(ProjectInfrastructure cm)
111114
},
112115
};
113116

114-
// deployments need to have dependson set!
115-
OpenAIModelFeature? previous = FindPrevious(cm, this);
117+
// deployments need to have DependsOn property set!
118+
OpenAIModelFeature? previous = FindPrevious(infrastructure, this);
116119
if (previous != null)
117120
{
118-
if (previous.Resource == null) throw new InvalidOperationException("Previous must be emitted");
119-
CognitiveServicesAccountDeployment previousDeployment = (CognitiveServicesAccountDeployment)previous.Resource;
121+
CognitiveServicesAccountDeployment previousDeployment = infrastructure.GetConstruct<CognitiveServicesAccountDeployment>(previous.Id);
120122
deployment.DependsOn.Add(previousDeployment);
121123
}
122124

123-
cm.AddConstruct(deployment);
124-
125-
string key = Kind == AIModelKind.Chat ? "OpenAI.Chat.ChatClient" : "OpenAI.Embeddings.EmbeddingClient";
126-
string locator = Kind == AIModelKind.Chat ? $"{cm.ProjectId}_chat" : $"{cm.ProjectId}_embedding";
127-
EmitConnection(cm, key, locator);
125+
infrastructure.AddConstruct(Id, deployment);
128126

129-
return deployment;
127+
string clientId = Kind == AIModelKind.Chat ? "OpenAI.Chat.ChatClient" : "OpenAI.Embeddings.EmbeddingClient";
128+
EmitConnection(infrastructure, clientId, resourceName);
130129

131-
OpenAIModelFeature? FindPrevious(ProjectInfrastructure cm, OpenAIModelFeature current)
130+
OpenAIModelFeature? FindPrevious(ProjectInfrastructure infrastructure, OpenAIModelFeature current)
132131
{
133132
OpenAIModelFeature? previous = default;
134-
foreach (var feature in cm.Features)
133+
foreach (var feature in infrastructure.Features)
135134
{
136135
if (feature == current)
137136
return previous;

0 commit comments

Comments
 (0)