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

Large Refactoring to Enable True Extensibility #47367

Merged
merged 24 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
846d17f
cleanup
KrzysztofCwalina Nov 25, 2024
1ca450b
more cleanup
KrzysztofCwalina Nov 25, 2024
0f422d9
moved CM provisioning projects to CM folder
KrzysztofCwalina Nov 26, 2024
75eea35
added the ability to provide extension connections
KrzysztofCwalina Nov 26, 2024
7023bec
cleaned up extensible connections
KrzysztofCwalina Nov 26, 2024
c89abee
made connection collection strongly typed
KrzysztofCwalina Nov 26, 2024
41b17f4
completly removed hardcoded connections
KrzysztofCwalina Nov 26, 2024
5ee1a99
made connection collection serializable
KrzysztofCwalina Nov 26, 2024
8fb301c
refactored tests
KrzysztofCwalina Nov 26, 2024
1a3b16d
connection scenario tests
KrzysztofCwalina Nov 26, 2024
5c75814
basic scenarios work and tests pass
KrzysztofCwalina Nov 27, 2024
17cd244
cleaned up tests
KrzysztofCwalina Nov 27, 2024
2b624d9
hardened appsettings.json reading code
KrzysztofCwalina Nov 27, 2024
cef84aa
added more to getting started
KrzysztofCwalina Nov 27, 2024
c9ec840
started to move built-in connections
KrzysztofCwalina Nov 27, 2024
82aacbf
organized folders
KrzysztofCwalina Nov 27, 2024
59b3909
all tests pass
KrzysztofCwalina Nov 28, 2024
25a8544
updated APIs
KrzysztofCwalina Nov 28, 2024
a835511
made tests run sequentially
KrzysztofCwalina Dec 2, 2024
14f58b3
made tests run sequentially
KrzysztofCwalina Dec 2, 2024
9bee34a
removed duplicated code
KrzysztofCwalina Dec 2, 2024
329c88d
fixed solution file
KrzysztofCwalina Dec 2, 2024
6f4131b
fixed misspelling
KrzysztofCwalina Dec 2, 2024
4c0cd03
PR feedback
KrzysztofCwalina Dec 2, 2024
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 @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\provisioning\Azure.Provisioning.CloudMachine\src\Azure.Provisioning.CloudMachine.csproj" />
<ProjectReference Include="..\..\Azure.Provisioning.CloudMachine\src\Azure.Provisioning.CloudMachine.csproj" />
<ProjectReference Include="..\..\Azure.CloudMachine.Web\src\Azure.CloudMachine.Web.csproj" />
<ProjectReference Include="..\..\Azure.CloudMachine\src\Azure.CloudMachine.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static RequestDelegate CreateRequestDelegate<T>(T service, MethodInfo im
ParameterInfo[] parameters = interfaceMethod!.GetParameters();
object[] implementationArguments = new object[parameters.Length];

foreach (var parameter in parameters)
foreach (ParameterInfo parameter in parameters)
{
implementationArguments[0] = await CreateArgumentAsync(parameter, request).ConfigureAwait(false);
}
Expand Down Expand Up @@ -128,13 +128,13 @@ private static async ValueTask<object> CreateArgumentAsync(ParameterInfo paramet

if (parameterType == typeof(byte[]))
{
var bd = await BinaryData.FromStreamAsync(request.Body).ConfigureAwait(false);
BinaryData bd = await BinaryData.FromStreamAsync(request.Body).ConfigureAwait(false);
return bd.ToArray();
}
if (parameterType == typeof(BinaryData))
{
string? contentType = request.ContentType;
var bd = await BinaryData.FromStreamAsync(request.Body, contentType).ConfigureAwait(false);
BinaryData bd = await BinaryData.FromStreamAsync(request.Body, contentType).ConfigureAwait(false);
return bd;
}
if (parameterType == typeof(string))
Expand Down Expand Up @@ -164,10 +164,10 @@ private static async ValueTask<object> CreateArgumentAsync(ParameterInfo paramet
// TODO: this is a hack. We should use MRW
private static object DeserializeModel(Type modelType, Stream stream)
{
var fromJson = modelType.GetMethod("FromJson", BindingFlags.Static);
MethodInfo? fromJson = modelType.GetMethod("FromJson", BindingFlags.Static);
if (fromJson == default)
throw new InvalidOperationException($"{modelType} does not provide FromJson static method");
object? deserialized = fromJson.Invoke(null, new object[] { stream });
object? deserialized = fromJson.Invoke(null, [stream]);
if (deserialized == default)
throw new InvalidOperationException($"Failed to deserialize {modelType}");
return deserialized;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
namespace Azure
{
public partial class RestCallFailedException : System.Exception
{
public RestCallFailedException(string message, System.ClientModel.Primitives.PipelineResponse response) { }
}
public partial class RestClient
{
public RestClient() { }
public RestClient(System.ClientModel.Primitives.PipelinePolicy auth) { }
public static Azure.RestClient Shared { get { throw null; } }
public System.ClientModel.Primitives.PipelineMessage Create(string method, System.Uri uri) { throw null; }
public System.ClientModel.Primitives.PipelineResponse Get(string uri, System.ClientModel.Primitives.RequestOptions options = null) { throw null; }
public System.ClientModel.Primitives.PipelineResponse Patch(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; }
public System.ClientModel.Primitives.PipelineResponse Post(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; }
public System.ClientModel.Primitives.PipelineResponse Put(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; }
public System.ClientModel.Primitives.PipelineResponse Send(System.ClientModel.Primitives.PipelineMessage message, System.ClientModel.Primitives.RequestOptions options = null) { throw null; }
}
public partial class RestClientOptions : System.ClientModel.Primitives.ClientPipelineOptions
{
public RestClientOptions() { }
}
}
namespace Azure.AI.OpenAI
{
public partial class TokenCredentialAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy
{
public TokenCredentialAuthenticationPolicy(Azure.Core.TokenCredential credential, System.Collections.Generic.IEnumerable<string> scopes, System.TimeSpan? refreshOffset = default(System.TimeSpan?)) { }
public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
}
}
namespace Azure.CloudMachine
{
public partial class CloudMachineClient : Azure.CloudMachine.CloudMachineWorkspace
{
protected CloudMachineClient() : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration)) { }
public CloudMachineClient(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null) : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration)) { }
protected CloudMachineClient() : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration), default(System.Collections.Generic.IEnumerable<Azure.Core.ClientConnection>)) { }
public CloudMachineClient(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null, System.Collections.Generic.IEnumerable<Azure.Core.ClientConnection> connections = null) : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration), default(System.Collections.Generic.IEnumerable<Azure.Core.ClientConnection>)) { }
public Azure.CloudMachine.MessagingServices Messaging { get { throw null; } }
public Azure.CloudMachine.StorageServices Storage { get { throw null; } }
}
public partial class CloudMachineWorkspace : Azure.Core.ClientWorkspace
{
public CloudMachineWorkspace(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null) { }
public CloudMachineWorkspace(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null, System.Collections.Generic.IEnumerable<Azure.Core.ClientConnection> connections = null) : base (default(Azure.Core.TokenCredential)) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public Azure.CloudMachine.ConnectionCollection Connections { get { throw null; } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public string Id { get { throw null; } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override Azure.Core.ClientConnectionOptions GetConnectionOptions(System.Type clientType, string instanceId) { throw null; }
public override Azure.Core.ClientConnection GetConnectionOptions(string connectionId) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override string ToString() { throw null; }
}
public partial class ConnectionCollection : System.Collections.ObjectModel.KeyedCollection<string, Azure.Core.ClientConnection>
{
public ConnectionCollection() { }
protected override string GetKeyForItem(Azure.Core.ClientConnection item) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct MessagingServices
{
Expand All @@ -39,6 +78,7 @@ internal StorageFile() { }
public void Delete() { }
public System.Threading.Tasks.Task DeleteAsync() { throw null; }
public System.BinaryData Download() { throw null; }
public System.Threading.Tasks.Task<System.BinaryData> DownloadAsync() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -56,12 +96,14 @@ public void Delete(string path) { }
public System.Threading.Tasks.Task DeleteAsync(string path) { throw null; }
public System.BinaryData Download(string path) { throw null; }
public System.Threading.Tasks.Task<System.BinaryData> DownloadAsync(string path) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public Azure.Storage.Blobs.BlobContainerClient GetContainer(string containerName = null) { throw null; }
public string Upload(System.BinaryData data, string name = null, bool overwrite = false) { throw null; }
public string Upload(System.IO.Stream fileStream, string name = null, string contentType = null, bool overwrite = false) { throw null; }
public System.Threading.Tasks.Task<string> UploadAsync(System.BinaryData data, string name = null, bool overwrite = false) { throw null; }
public System.Threading.Tasks.Task<string> UploadAsync(System.IO.Stream fileStream, string name = null, string contentType = null, bool overwrite = false) { throw null; }
public string UploadJson(object json, string name = null, bool overwrite = false) { throw null; }
public System.Threading.Tasks.Task<string> UploadJsonAsync(object json, string name = null, bool overwrite = false) { throw null; }
public string UploadJson(object serializable, string name = null, bool overwrite = false) { throw null; }
public System.Threading.Tasks.Task<string> UploadJsonAsync(object serializable, string name = null, bool overwrite = false) { throw null; }
public void WhenUploaded(System.Action<Azure.CloudMachine.StorageFile> function) { }
public void WhenUploaded(System.Action<System.BinaryData> function) { }
}
Expand All @@ -80,7 +122,8 @@ 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 string AsText(this OpenAI.Chat.ChatCompletion completion) { throw null; }
public static string AsText(this OpenAI.Chat.ChatMessageContent completion) { throw null; }
public static string AsText(this OpenAI.Chat.ChatMessageContent content) { throw null; }
public static string AsText(this System.ClientModel.ClientResult<OpenAI.Chat.ChatCompletion> completionResult) { throw null; }
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; }
public static void Trim(this System.Collections.Generic.List<OpenAI.Chat.ChatMessage> messages) { }
Expand All @@ -94,11 +137,6 @@ public void Add(System.Type functions) { }
public string Call(OpenAI.Chat.ChatToolCall call) { throw null; }
public string Call(string name, object[] arguments) { throw null; }
public System.Collections.Generic.IEnumerable<OpenAI.Chat.ToolChatMessage> CallAll(System.Collections.Generic.IEnumerable<OpenAI.Chat.ChatToolCall> toolCalls) { throw null; }
protected string ClrToJsonTypeUtf16(System.Type clrType) { throw null; }
protected System.ReadOnlySpan<byte> ClrToJsonTypeUtf8(System.Type clrType) { throw null; }
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 Expand Up @@ -135,36 +173,40 @@ protected VectorbaseStore() { }
}
namespace Azure.Core
{
public enum ClientAuthenticationMethod
{
EntraId = 0,
ApiKey = 1,
Subclient = 2,
}
public partial class ClientCache
{
public ClientCache() { }
public T Get<T>(System.Func<T> value, string id = null) where T : class { throw null; }
}
public enum ClientConnectionKind
{
EntraId = 0,
ApiKey = 1,
OutOfBand = 2,
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct ClientConnectionOptions
public readonly partial struct ClientConnection
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public ClientConnectionOptions(string subclientId) { throw null; }
public ClientConnectionOptions(System.Uri endpoint, Azure.Core.TokenCredential credential) { throw null; }
public ClientConnectionOptions(System.Uri endpoint, string apiKey) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public ClientConnection() { throw null; }
public ClientConnection(string id, string locator, Azure.Core.ClientAuthenticationMethod auth = Azure.Core.ClientAuthenticationMethod.EntraId) { throw null; }
public ClientConnection(string id, string locator, string apiKey) { throw null; }
public string ApiKeyCredential { get { throw null; } }
public Azure.Core.ClientConnectionKind ConnectionKind { get { throw null; } }
public System.Uri Endpoint { get { throw null; } }
public Azure.Core.ClientAuthenticationMethod Authentication { get { throw null; } }
public string Id { get { throw null; } }
public Azure.Core.TokenCredential TokenCredential { get { throw null; } }
public string Locator { get { throw null; } }
public override string ToString() { throw null; }
public System.Uri ToUri() { throw null; }
}
public abstract partial class ClientWorkspace
{
protected ClientWorkspace() { }
protected ClientWorkspace(Azure.Core.TokenCredential credential) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public Azure.Core.TokenCredential Credential { get { throw null; } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public Azure.Core.ClientCache Subclients { get { throw null; } }
public abstract Azure.Core.ClientConnectionOptions GetConnectionOptions(System.Type clientType, string instanceId = null);
public abstract Azure.Core.ClientConnection GetConnectionOptions(string connectionId);
}
}
Loading
Loading