Skip to content

Commit

Permalink
Large Refactoring to Enable True Extensibility (#47367)
Browse files Browse the repository at this point in the history
* cleanup

* more cleanup

* moved CM provisioning projects to CM folder

* added the ability to provide extension connections

* cleaned up extensible connections

* made connection collection strongly typed

* completly removed hardcoded connections

* made connection collection serializable

* refactored tests

* connection scenario tests

* basic scenarios work and tests pass

* cleaned up tests

* hardened appsettings.json reading code

* added more to getting started

* started to move built-in connections

* organized folders

* all tests pass

* updated APIs

* made tests run sequentially

* made tests run sequentially

* removed duplicated code

* fixed solution file

* fixed misspelling

* PR feedback
  • Loading branch information
KrzysztofCwalina authored Dec 2, 2024
1 parent 60d946f commit 89ebe48
Show file tree
Hide file tree
Showing 79 changed files with 2,844 additions and 1,728 deletions.
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,67 @@
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 static string ReadOrCreateCloudMachineId() { 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 +80,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 +98,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 +124,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 +139,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 +175,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

0 comments on commit 89ebe48

Please sign in to comment.