Skip to content

Commit bb05118

Browse files
committed
Update Microsoft.Extensions.AI to 9.3.0-preview.1.25114.11
1 parent 4d153b1 commit bb05118

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/BotSharp.Plugin.MicrosoftExtensionsAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

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

src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAIChatCompletionProvider.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public MicrosoftExtensionsAIChatCompletionProvider(
3838
IServiceProvider services)
3939
{
4040
_client = client;
41-
_model = _client.Metadata.ModelId;
41+
_model = _client.GetService<ChatClientMetadata>()?.ModelId;
4242
_logger = logger;
4343
_services = services;
4444
}
@@ -71,14 +71,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
7171
if (agentService.RenderFunction(agent, function))
7272
{
7373
var property = agentService.RenderFunctionProperty(agent, function);
74-
(options.Tools ??= []).Add(new NopAIFunction(new(function.Name)
75-
{
76-
Description = function.Description,
77-
Parameters = property?.Properties.RootElement.Deserialize<Dictionary<string, object?>>()?.Select(p => new AIFunctionParameterMetadata(p.Key)
78-
{
79-
Schema = p.Value,
80-
}).ToList() ?? [],
81-
}));
74+
(options.Tools ??= []).Add(new NopAIFunction(function.Name, function.Description, JsonSerializer.SerializeToElement(property)));
8275
}
8376
}
8477
}
@@ -111,7 +104,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
111104
messages.Add(new(ChatRole.Assistant,
112105
[
113106
new FunctionCallContent(x.FunctionName, x.FunctionName, JsonSerializer.Deserialize<Dictionary<string, object?>>(x.FunctionArgs ?? "{}")),
114-
new FunctionResultContent(x.FunctionName, x.FunctionName, x.Content)
107+
new FunctionResultContent(x.FunctionName, x.Content)
115108
]));
116109
}
117110
else if (x.Role == AgentRole.System || x.Role == AgentRole.Assistant)
@@ -127,17 +120,17 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
127120
{
128121
if (!string.IsNullOrEmpty(file.FileData))
129122
{
130-
contents.Add(new ImageContent(file.FileData));
123+
contents.Add(new DataContent(file.FileData));
131124
}
132125
else if (!string.IsNullOrEmpty(file.FileStorageUrl))
133126
{
134127
var contentType = FileUtility.GetFileContentType(file.FileStorageUrl);
135128
var bytes = fileStorage!.GetFileBytes(file.FileStorageUrl);
136-
contents.Add(new ImageContent(bytes, contentType));
129+
contents.Add(new DataContent(bytes, contentType));
137130
}
138131
else if (!string.IsNullOrEmpty(file.FileUrl))
139132
{
140-
contents.Add(new ImageContent(file.FileUrl));
133+
contents.Add(new DataContent(file.FileUrl));
141134
}
142135
}
143136
}
@@ -146,7 +139,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
146139
}
147140
}
148141

149-
var completion = await _client.CompleteAsync(messages);
142+
var completion = await _client.GetResponseAsync(messages);
150143

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

178-
private sealed class NopAIFunction(AIFunctionMetadata metadata) : AIFunction
171+
private sealed class NopAIFunction(string name, string description, JsonElement schema) : AIFunction
179172
{
180-
public override AIFunctionMetadata Metadata { get; } = metadata;
173+
public override string Name => name;
174+
175+
public override string Description => description;
176+
177+
public override JsonElement JsonSchema => schema;
181178

182179
protected override Task<object?> InvokeCoreAsync(IEnumerable<KeyValuePair<string, object?>> arguments, CancellationToken cancellationToken) =>
183180
throw new NotSupportedException();

src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAITextCompletionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<string> GetCompletion(string text, string agentId, string mess
4949
await Task.WhenAll(hooks.Select(hook => hook.BeforeGenerating(agent, [userMessage])));
5050

5151
_tokenStatistics.StartTimer();
52-
var completion = await _chatClient.CompleteAsync(text);
52+
var completion = await _chatClient.GetResponseAsync(text);
5353
var result = string.Concat(completion.Message.Contents.OfType<TextContent>());
5454
_tokenStatistics.StopTimer();
5555

0 commit comments

Comments
 (0)