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

Update Microsoft.Extensions.AI to 9.3.0-preview.1.25114.11 #892

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.1.0-preview.1.25064.3" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MicrosoftExtensionsAIChatCompletionProvider(
IServiceProvider services)
{
_client = client;
_model = _client.Metadata.ModelId;
_model = _client.GetService<ChatClientMetadata>()?.ModelId;
_logger = logger;
_services = services;
}
Expand Down Expand Up @@ -71,14 +71,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
if (agentService.RenderFunction(agent, function))
{
var property = agentService.RenderFunctionProperty(agent, function);
(options.Tools ??= []).Add(new NopAIFunction(new(function.Name)
{
Description = function.Description,
Parameters = property?.Properties.RootElement.Deserialize<Dictionary<string, object?>>()?.Select(p => new AIFunctionParameterMetadata(p.Key)
{
Schema = p.Value,
}).ToList() ?? [],
}));
(options.Tools ??= []).Add(new NopAIFunction(function.Name, function.Description, JsonSerializer.SerializeToElement(property)));
}
}
}
Expand Down Expand Up @@ -111,7 +104,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
messages.Add(new(ChatRole.Assistant,
[
new FunctionCallContent(x.FunctionName, x.FunctionName, JsonSerializer.Deserialize<Dictionary<string, object?>>(x.FunctionArgs ?? "{}")),
new FunctionResultContent(x.FunctionName, x.FunctionName, x.Content)
new FunctionResultContent(x.FunctionName, x.Content)
]));
}
else if (x.Role == AgentRole.System || x.Role == AgentRole.Assistant)
Expand All @@ -127,17 +120,17 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
{
if (!string.IsNullOrEmpty(file.FileData))
{
contents.Add(new ImageContent(file.FileData));
contents.Add(new DataContent(file.FileData));
}
else if (!string.IsNullOrEmpty(file.FileStorageUrl))
{
var contentType = FileUtility.GetFileContentType(file.FileStorageUrl);
var bytes = fileStorage!.GetFileBytes(file.FileStorageUrl);
contents.Add(new ImageContent(bytes, contentType));
contents.Add(new DataContent(bytes, contentType));
}
else if (!string.IsNullOrEmpty(file.FileUrl))
{
contents.Add(new ImageContent(file.FileUrl));
contents.Add(new DataContent(file.FileUrl));
}
}
}
Expand All @@ -146,7 +139,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
}
}

var completion = await _client.CompleteAsync(messages);
var completion = await _client.GetResponseAsync(messages);

RoleDialogModel result = new(AgentRole.Assistant, string.Concat(completion.Message.Contents.OfType<TextContent>()))
{
Expand Down Expand Up @@ -175,9 +168,13 @@ public Task<bool> GetChatCompletionsAsync(Agent agent, List<RoleDialogModel> con
public Task<bool> GetChatCompletionsStreamingAsync(Agent agent, List<RoleDialogModel> conversations, Func<RoleDialogModel, Task> onMessageReceived) =>
throw new NotImplementedException();

private sealed class NopAIFunction(AIFunctionMetadata metadata) : AIFunction
private sealed class NopAIFunction(string name, string description, JsonElement schema) : AIFunction
{
public override AIFunctionMetadata Metadata { get; } = metadata;
public override string Name => name;

public override string Description => description;

public override JsonElement JsonSchema => schema;

protected override Task<object?> InvokeCoreAsync(IEnumerable<KeyValuePair<string, object?>> arguments, CancellationToken cancellationToken) =>
throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<string> GetCompletion(string text, string agentId, string mess
await Task.WhenAll(hooks.Select(hook => hook.BeforeGenerating(agent, [userMessage])));

_tokenStatistics.StartTimer();
var completion = await _chatClient.CompleteAsync(text);
var completion = await _chatClient.GetResponseAsync(text);
var result = string.Concat(completion.Message.Contents.OfType<TextContent>());
_tokenStatistics.StopTimer();

Expand Down
Loading