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 eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<AzureSearchDocumentsVersion>11.6.0</AzureSearchDocumentsVersion>
<MicrosoftSemanticKernelConnectorsAzureAISearchVersion>1.37.0-preview</MicrosoftSemanticKernelConnectorsAzureAISearchVersion>
<MicrosoftSemanticKernelCoreVersion>1.37.0</MicrosoftSemanticKernelCoreVersion>
<OllamaSharpVersion>5.0.7</OllamaSharpVersion>
<OllamaSharpVersion>5.1.5</OllamaSharpVersion>
<OpenAIVersion>2.2.0-beta.1</OpenAIVersion>
<PdfPigVersion>0.1.9</PdfPigVersion>
<SystemLinqAsyncVersion>6.0.1</SystemLinqAsyncVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectTemplates/GeneratedContent.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<_MicrosoftExtensionsAIVersion>9.3.0-preview.1.25114.11</_MicrosoftExtensionsAIVersion>
<_MicrosoftExtensionsAIVersion>9.3.0-preview.1.25161.3</_MicrosoftExtensionsAIVersion>

<!-- Specify package version variables used in template content. -->
<GeneratedContentProperties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!--#if (UseManagedIdentity) -->
<PackageReference Include="Azure.Identity" Version="${AzureIdentityVersion}" />
<!--#endif -->
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.AI" Version="${MicrosoftExtensionsAIVersion}" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="${MicrosoftSemanticKernelCoreVersion}" />
<PackageReference Include="PdfPig" Version="${PdfPigVersion}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,29 @@
// aren't supported because Ollama will not support both streaming and using Tools
currentResponseCancellation = new();
var response = await ChatClient.GetResponseAsync(messages, chatOptions, currentResponseCancellation.Token);
currentResponseMessage = response.Message;
ChatMessageItem.NotifyChanged(currentResponseMessage);

// Store responses in the conversation, and begin getting suggestions
messages.AddMessages(response);
#else*@
// Stream and display a new response from the IChatClient
var responseText = new TextContent("");
currentResponseMessage = new ChatMessage(ChatRole.Assistant, [responseText]);
currentResponseCancellation = new();
await foreach (var chunk in ChatClient.GetStreamingResponseAsync(messages, chatOptions, currentResponseCancellation.Token))

// Pass a copy of the messages then add messages to the list while handling the streaming responses
var requestMessages = messages.ToArray();

await foreach (var update in ChatClient.GetStreamingResponseAsync(requestMessages, chatOptions, currentResponseCancellation.Token))
{
responseText.Text += chunk.Text;
AddMessages(messages, update, filter: c => c is not TextContent);
responseText.Text += update.Text;
ChatMessageItem.NotifyChanged(currentResponseMessage);
}
@*#endif*@

// Store the final response in the conversation, and begin getting suggestions
messages.Add(currentResponseMessage!);
currentResponseMessage = null;
@*#endif*@
chatSuggestions?.Update(messages);
}

Expand All @@ -108,6 +114,24 @@
await chatInput!.FocusAsync();
}

@*#if (!IsOllama)*@
// TODO: Needed until https://github.com/dotnet/extensions/issues/6114 is resolved, which will introduce
// an extension method on IList<ChatMessage> for adding messages from a ChatResponseUpdate.
private static void AddMessages(IList<ChatMessage> list, ChatResponseUpdate update, Func<AIContent, bool> filter)
{
var contentsList = update.Contents.Where(filter).ToList();
if (contentsList.Count > 0)
{
list.Add(new(update.Role ?? ChatRole.Assistant, contentsList)
{
AuthorName = update.AuthorName,
RawRepresentation = update.RawRepresentation,
AdditionalProperties = update.AdditionalProperties,
});
}
}

@*#endif*@
[Description("Searches for information using a phrase or keyword")]
private async Task<IEnumerable<string>> SearchAsync(
[Description("The phrase to search for.")] string searchPhrase,
Expand Down
Loading