-
Notifications
You must be signed in to change notification settings - Fork 22
Add Microsoft.Extensions.AI support #10
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
Conversation
sd-st
left a comment
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.
Hey, thanks for the PR!
I left some comments; I'm not super familiar with Microsoft.Extensions.AI so some comments are probably a little silly. Overall though this looks really good, just had a few minor points.
Aside from the comments:
- We should probably add this to the README, and also put an example for it in
examples - Some lints are failing (You can check this with
./scripts/lint)
src/Anthropic.Client/Services/Beta/Messages/AnthropicClientBetaExtensions.cs
Outdated
Show resolved
Hide resolved
src/Anthropic.Client/Services/Beta/Messages/AnthropicClientBetaExtensions.cs
Outdated
Show resolved
Hide resolved
src/Anthropic.Client/Services/Beta/Messages/AnthropicClientBetaExtensions.cs
Outdated
Show resolved
Hide resolved
src/Anthropic.Client.Tests/AnthropicClientBetaExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/Anthropic.Client/Services/Beta/Messages/AnthropicClientBetaExtensions.cs
Outdated
Show resolved
Hide resolved
|
@sd-st, I just merged in the latest in main, and there are a few changes that are quite cumbersome. In particular, making all of the properties on MessageCreateParams be |
|
Actually, @sd-st, when you combine the init-only aspect with the fact that all of the init's always set a value for the specified property even when storing null, it's basically impossible to now do the right thing, as you can't conditionally set an init. |
|
Looks like I can work around it for now by just using the raw properties and bypassing the strongly-typed API altogether... |
|
I'll let Stephen take a look tomorrow and give his opinion as well, but I think:
I've not looked deeply at this PR so not sure which one applies, but just wanted to note that |
They can, and when it's just public double? Temperature
{
get
{
if (!this._bodyProperties.TryGetValue("temperature", out JsonElement element))
return null;
return JsonSerializer.Deserialize<double?>(element, ModelBase.SerializerOptions);
}
init
{
this._bodyProperties["temperature"] = JsonSerializer.SerializeToElement(
value,
ModelBase.SerializerOptions
);
}
}It's nullable, but if you set public static MessageCreateParams Create(double? temperature)
{
...
}I can't implement it like this because of the public static MessageCreateParams Create(double? temperature)
{
MessageCreateParams p = new();
if (temperature is not null)
{
p.Temperature = temperature;
}
return p;
}and I can't write it like this because doing so populates the MessageCreateParams with an empty temperature, which will result in public static MessageCreateParams Create(double? temperature)
{
return new()
{
Temperature = temperature,
};
}which means my option is to write it like: public static MessageCreateParams Create(double? temperature)
{
return temperature is not null ?
new()
{
Temperature = temperature,
} :
new();
}That's fine if I just have the one property to set. But if I have two, now I have four possible ways I need to construct the instance. Three properties, eight. Etc. It's exponential. I could, as you suggest, with these now being records, use I pushed a commit that drops down to just working with the raw JSON. But from a usability perspective, it's quite poor. Separate from this PR and just for general usability of the library, I'd urge reconsidering |
|
Ah, hmmm, for properties that can only be omitted or set to non-null, I think we should turn I'll need to double check the codegen implementation tomorrow to see if that's what we're currently doing (can't tell from this PR cause I'm not sure off the top of my head what the schema of each property is). If it's not what we're doing, then I'll fix that, which should help in most cases (it's rare-ish for an API to have a property that can be both null or omitted) |
|
@stephentoub FYI many of the above improvements we discussed (including init for non-required properties) have been put into |
|
Thanks, @sd-st. Updated and rebased on next. |
sd-st
left a comment
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.
Aside from the comments, there are some failing lints (./scripts/lint) and it probably makes sense to add something about this to the readme and examples
|
Thanks, @sd-st. All feedback addressed and merged with latest next. |
|
Ah, I missed your comment about linting errors... where can I see them? |
If you run |
|
Ok, done. Thanks. |
a808311 to
d360e12
Compare
|
@sd-st, I've rebased back on main now that it's been updated with everything from next. Anything else I can do to help push this forward? Thanks! |
|
Hey @stephentoub - sorry about the long delay here. Haven't forgotten about this, just have some fairly high pri stuff on my plate. I'm hoping to get to this over the next few days but I'm off on Friday so I can't make any promises. |
|
Sounds good. Thanks. |
src/Anthropic/Services/Beta/Messages/AnthropicBetaClientExtensions.cs
Outdated
Show resolved
Hide resolved
src/Anthropic/Services/Beta/Messages/AnthropicBetaClientExtensions.cs
Outdated
Show resolved
Hide resolved
src/Anthropic/Services/Beta/Messages/AnthropicBetaClientExtensions.cs
Outdated
Show resolved
Hide resolved
|
FYI, we will probably still want to merge this into |
Ok :) Rebased back on next. |
sd-st
left a comment
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.
Looks pretty good! Just had a few minor comments. As an aside, the formatting looks a tiny bit weird in some places - I suspect a ./scripts/format should clean things up
* Make WithOptions virtual and return correct type on foundry implementation * code cleanup * revert moving constructor * fix indentation
|
@stephentoub I got a pretty big diff from |
Done, thanks. |
c78c8db to
bab3e3b
Compare
|
@stephentoub Hey, really sorry about all the merge conflicts. If you want to do one more conflict fix + formatting pass (if it needs it) I'll be standing by to give it a quick review + merge. Excited to get this in (: |
sd-st
left a comment
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.
Yay! Thank you for this PR (:
|
Thank you, @sd-st. |
Fixes #4
This provides implementations of
IChatClientfor both the main and beta clients. The actual src additions are a few hundred lines; most of the PR is extensive tests covering using the anthropic clients via IChatClient, providing coverage of both.