Skip to content
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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<PackageVersion Include="LLamaSharp" Version="0.20.0" />
<PackageVersion Include="FaissMask" Version="0.2.0" />
<PackageVersion Include="FastText.NetWrapper" Version="1.3.0" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
<PackageVersion Include="System.Text.Encodings.Web" Version="8.0.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.1.0" />
<PackageVersion Include="Docnet.Core" Version="2.7.0-alpha.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio
private readonly IChatClient _client;
private readonly ILogger<MicrosoftExtensionsAIChatCompletionProvider> _logger;
private readonly IServiceProvider _services;
private List<string> renderedInstructions = [];
private string? _model;

/// <summary>
Expand All @@ -46,7 +45,7 @@ public MicrosoftExtensionsAIChatCompletionProvider(

/// <inheritdoc/>
public string Provider => "microsoft.extensions.ai";
public string Model => _model;
public string Model => _model ?? "";

/// <inheritdoc/>
public void SetModelName(string model) => _model = model;
Expand All @@ -56,7 +55,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
{
// Before chat completion hook
var hooks = _services.GetServices<IContentGeneratingHook>().ToArray();
renderedInstructions = [];
List<string> renderedInstructions = [];
await Task.WhenAll(hooks.Select(hook => hook.BeforeGenerating(agent, conversations)));

// Configure options
Expand Down Expand Up @@ -145,13 +144,13 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial

var completion = await _client.GetResponseAsync(messages);

RoleDialogModel result = new(AgentRole.Assistant, string.Concat(completion.Message.Contents.OfType<TextContent>()))
RoleDialogModel result = new(AgentRole.Assistant, completion.Text)
{
CurrentAgentId = agent.Id,
RenderedInstruction = string.Join("\r\n", renderedInstructions)
//RenderedInstruction = renderedInstructions,
};

if (completion.Message.Contents.OfType<FunctionCallContent>().FirstOrDefault() is { } fcc)
if (completion.Messages.SelectMany(m => m.Contents).OfType<FunctionCallContent>().FirstOrDefault() is { } fcc)
{
result.Role = AgentRole.Function;
result.MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<string> GetCompletion(string text, string agentId, string mess

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

// After chat completion hook
Expand Down
Loading