forked from bterlson/openai-in-typespec
-
Notifications
You must be signed in to change notification settings - Fork 1
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
annelo-msft
wants to merge
32
commits into
azoai-generate-clean
Choose a base branch
from
azoai-client-inheritance3
base: azoai-generate-clean
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
df95c53
Add Azure client
annelo-msft 60575d9
updates
annelo-msft 45b680a
updates
annelo-msft 51e2eec
beginning work on extension methods
annelo-msft 0ac5efe
WIP
annelo-msft 8ca386f
Initial implementation of settable extension property
annelo-msft 443c709
functional prototype for inputs; with lots of open questions
annelo-msft 43b4afe
updates
annelo-msft 99f8265
starting the model-inheritance design exploration
annelo-msft 9140b1d
update to dictionary approach
annelo-msft fa9fbff
nits
annelo-msft 9699f63
Updates to JsonModelList, input extension
annelo-msft 0829d5c
add 'emitted' subtype of BinaryData
annelo-msft d6dcaca
update 3rd-party model serialization method
annelo-msft 8ab3c85
add Azure response subtypes
annelo-msft f10b1bb
updates
annelo-msft 09e5bc6
use dictionary for output model
annelo-msft 5d6b7b2
functional e2e, using 'AW' approach - this doesn't work
annelo-msft 56639be
make e2e work by separating which types of values are written from di…
annelo-msft b2ac716
WIP - trying Mads's suggestion
annelo-msft 04c0255
use local ClientModel; remove BinaryData subtype; update input extens…
annelo-msft 0652870
rework input model wrapper type
annelo-msft 24124c9
handle output models; no change really
annelo-msft 687a88a
nits
annelo-msft 8226cf8
nits
annelo-msft f629e00
updates
annelo-msft d97c28c
nits and updates
annelo-msft 6f2b486
rework things a bit
annelo-msft b124eff
revert unneeded changes
annelo-msft 4cf6fa6
update clients
annelo-msft 6ae64d3
rename file
annelo-msft dd32b09
nits
annelo-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tsp-output/@azure-tools/typespec-csharp/app/DemoApp/DemoApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
196 changes: 196 additions & 0 deletions
196
tsp-output/@azure-tools/typespec-csharp/app/DemoApp/Mocks/MockPipelineTransport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
tsp-output/@azure-tools/typespec-csharp/app/DemoApp/Mocks/MockRequestHeaders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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