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

Investigation: Azure and unbranded clients #7

Draft
wants to merge 32 commits into
base: azoai-generate-clean
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df95c53
Add Azure client
annelo-msft Apr 8, 2024
60575d9
updates
annelo-msft Apr 8, 2024
45b680a
updates
annelo-msft Apr 8, 2024
51e2eec
beginning work on extension methods
annelo-msft Apr 8, 2024
0ac5efe
WIP
annelo-msft Apr 9, 2024
8ca386f
Initial implementation of settable extension property
annelo-msft Apr 9, 2024
443c709
functional prototype for inputs; with lots of open questions
annelo-msft Apr 9, 2024
43b4afe
updates
annelo-msft Apr 10, 2024
99f8265
starting the model-inheritance design exploration
annelo-msft Apr 10, 2024
9140b1d
update to dictionary approach
annelo-msft Apr 17, 2024
fa9fbff
nits
annelo-msft Apr 17, 2024
9699f63
Updates to JsonModelList, input extension
annelo-msft Apr 18, 2024
0829d5c
add 'emitted' subtype of BinaryData
annelo-msft Apr 18, 2024
d6dcaca
update 3rd-party model serialization method
annelo-msft Apr 18, 2024
8ab3c85
add Azure response subtypes
annelo-msft Apr 18, 2024
f10b1bb
updates
annelo-msft Apr 18, 2024
09e5bc6
use dictionary for output model
annelo-msft Apr 18, 2024
5d6b7b2
functional e2e, using 'AW' approach - this doesn't work
annelo-msft Apr 19, 2024
56639be
make e2e work by separating which types of values are written from di…
annelo-msft Apr 19, 2024
b2ac716
WIP - trying Mads's suggestion
annelo-msft Apr 20, 2024
04c0255
use local ClientModel; remove BinaryData subtype; update input extens…
annelo-msft Apr 22, 2024
0652870
rework input model wrapper type
annelo-msft Apr 22, 2024
24124c9
handle output models; no change really
annelo-msft Apr 23, 2024
687a88a
nits
annelo-msft Apr 23, 2024
8226cf8
nits
annelo-msft Apr 23, 2024
f629e00
updates
annelo-msft Apr 23, 2024
d97c28c
nits and updates
annelo-msft Apr 23, 2024
6f2b486
rework things a bit
annelo-msft Apr 23, 2024
b124eff
revert unneeded changes
annelo-msft Apr 23, 2024
4cf6fa6
update clients
annelo-msft Apr 23, 2024
6ae64d3
rename file
annelo-msft Apr 23, 2024
dd32b09
nits
annelo-msft Apr 23, 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
46 changes: 22 additions & 24 deletions tsp-output/@azure-tools/typespec-csharp/OpenAI.sln
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
# Visual Studio Version 17
VisualStudioVersion = 17.9.34701.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI", "src\OpenAI.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI", "src\OpenAI.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Tests", "tests\OpenAI.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI.Tests", "tests\OpenAI.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp", "app\DemoApp\DemoApp.csproj", "{79A5AD41-2A38-4771-93FE-0B3BCC6DB61A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureOpenAI", "azoai\AzureOpenAI\AzureOpenAI.csproj", "{FB61EB83-7171-48F4-9423-E64B99BDAA5A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ClientModel", "..\..\..\..\azure-sdk-for-net\sdk\core\System.ClientModel\src\System.ClientModel.csproj", "{8364F37B-2B3D-4CAA-8F20-5B808E19C6CE}"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points to the version of ClientModel in this PR: Prototype of JsonModel abstract class

EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -40,6 +26,18 @@ Global
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
{79A5AD41-2A38-4771-93FE-0B3BCC6DB61A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79A5AD41-2A38-4771-93FE-0B3BCC6DB61A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79A5AD41-2A38-4771-93FE-0B3BCC6DB61A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79A5AD41-2A38-4771-93FE-0B3BCC6DB61A}.Release|Any CPU.Build.0 = Release|Any CPU
{FB61EB83-7171-48F4-9423-E64B99BDAA5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB61EB83-7171-48F4-9423-E64B99BDAA5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB61EB83-7171-48F4-9423-E64B99BDAA5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB61EB83-7171-48F4-9423-E64B99BDAA5A}.Release|Any CPU.Build.0 = Release|Any CPU
{8364F37B-2B3D-4CAA-8F20-5B808E19C6CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8364F37B-2B3D-4CAA-8F20-5B808E19C6CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8364F37B-2B3D-4CAA-8F20-5B808E19C6CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8364F37B-2B3D-4CAA-8F20-5B808E19C6CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions tsp-output/@azure-tools/typespec-csharp/app/DemoApp/DemoApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\azoai\AzureOpenAI\AzureOpenAI.csproj" />
<ProjectReference Include="..\..\src\OpenAI.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;

namespace ClientModel.Tests.Mocks;

public class MockPipelineTransport : PipelineTransport
{
private readonly Func<int, (int Status, BinaryData? Content)> _responseFactory;
private int _retryCount;

public string Id { get; }

public Action<int, PipelineMessage>? OnSendingRequest { get; set; }
public Action<int, PipelineMessage>? OnReceivedResponse { get; set; }

public MockPipelineTransport(string id, params int[] codes)
: this(id, i => (codes[i], BinaryData.FromString(string.Empty)))
{
}

public MockPipelineTransport(string id, Func<int, (int Status, BinaryData? Content)> responseFactory)
{
Id = id;
_responseFactory = responseFactory;
}

protected override PipelineMessage CreateMessageCore()
{
return new RetriableTransportMessage();
}

protected override void ProcessCore(PipelineMessage message)
{
try
{
Stamp(message, "Transport");

OnSendingRequest?.Invoke(_retryCount, message);

if (message is RetriableTransportMessage transportMessage)
{
(int status, BinaryData? content) = _responseFactory(_retryCount);
transportMessage.SetResponse(status, content);
}

OnReceivedResponse?.Invoke(_retryCount, message);
}
finally
{
_retryCount++;
}
}

protected override ValueTask ProcessCoreAsync(PipelineMessage message)
{
try
{
Stamp(message, "Transport");

OnSendingRequest?.Invoke(_retryCount, message);

if (message is RetriableTransportMessage transportMessage)
{
(int status, BinaryData? content) = _responseFactory(_retryCount);
transportMessage.SetResponse(status, content);
}

OnReceivedResponse?.Invoke(_retryCount, message);
}
finally
{
_retryCount++;
}

return new ValueTask();
}

private void Stamp(PipelineMessage message, string prefix)
{
List<string> values;

if (message.TryGetProperty(typeof(ObservablePolicy), out object? prop) &&
prop is List<string> list)
{
values = list;
}
else
{
values = new List<string>();
message.SetProperty(typeof(ObservablePolicy), values);
}

values.Add($"{prefix}:{Id}");
}

private class RetriableTransportMessage : PipelineMessage
{
public RetriableTransportMessage() : this(new TransportRequest())
{
}

protected internal RetriableTransportMessage(PipelineRequest request) : base(request)
{
}

public void SetResponse(int status, BinaryData? content)
{
Response = new RetriableTransportResponse(status, content);
}
}

private class TransportRequest : PipelineRequest
{
private Uri? _uri;
private readonly PipelineRequestHeaders _headers;
private string _method;
private BinaryContent? _content;

public TransportRequest()
{
_headers = new MockRequestHeaders();
_uri = new Uri("https://www.example.com");
_method = "GET";
}

public override void Dispose() { }

protected override BinaryContent? ContentCore
{
get => _content;
set => _content = value;
}

protected override PipelineRequestHeaders HeadersCore
=> _headers;

protected override string MethodCore
{
get => _method;
set => _method = value;
}

protected override Uri? UriCore
{
get => _uri;
set => _uri = value;
}
}

private class RetriableTransportResponse : PipelineResponse
{
private Stream? _contentStream;
private BinaryData _content;

public RetriableTransportResponse(int status, BinaryData? content)
{
Status = status;
ContentStream = content?.ToStream();
_content = content ?? BinaryData.FromString(string.Empty);
}

public override int Status { get; }

public override string ReasonPhrase => throw new NotImplementedException();

public override Stream? ContentStream
{
get => _contentStream;
set => _contentStream = value;
}

public override BinaryData Content => _content;

protected override PipelineResponseHeaders HeadersCore
=> throw new NotImplementedException();

public override void Dispose() { }

public override BinaryData BufferContent(CancellationToken cancellationToken = default)
{
return _content = _contentStream == null ?
BinaryData.FromString(string.Empty) :
BinaryData.FromStream(_contentStream);
}

public override ValueTask<BinaryData> BufferContentAsync(CancellationToken cancellationToken = default)
{
return new(_content = _contentStream == null ?
BinaryData.FromString(string.Empty) :
BinaryData.FromStream(_contentStream));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;

namespace ClientModel.Tests.Mocks;

public class MockRequestHeaders : PipelineRequestHeaders
{
private readonly Dictionary<string, string> _headers;

public MockRequestHeaders()
{
_headers = new Dictionary<string, string>();
}

public override void Add(string name, string value)
{
if (_headers.ContainsKey(name))
{
_headers[name] += string.Concat(",", value);
}
else
{
_headers[name] = value;
}
}

public override IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
throw new NotImplementedException();
}

public override bool Remove(string name)
{
return _headers.Remove(name);
}

public override void Set(string name, string value)
{
_headers[name] = value;
}

public override bool TryGetValue(string name, out string? value)
{
return _headers.TryGetValue(name, out value);
}

public override bool TryGetValues(string name, out IEnumerable<string>? values)
{
throw new NotImplementedException();
}
}
Loading
Loading