-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple .NET connector from Semantic Kernel (#211)
* Decouple .NET connector from Semantic Kernel: there was just a helper using SK, that can be moved to extension methods for people using SK. No need to depend on SK which could cause version conflicts. * Refactor agent config, replace `IAgentConfig` with `AgentConfigBase`
- Loading branch information
Showing
12 changed files
with
98 additions
and
145 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
examples/dotnet/dotnet-03-simple-chatbot/ConnectorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Text; | ||
using Microsoft.SemanticKernel.ChatCompletion; | ||
using Microsoft.SemanticWorkbench.Connector; | ||
|
||
namespace AgentExample; | ||
|
||
public static class ConnectorExtensions | ||
{ | ||
// TODO: the list of participants is incomplete, because agents see only participants being added | ||
public static string GetParticipantName(this Conversation conversation, string id) | ||
{ | ||
if (conversation.Participants.TryGetValue(id, out Participant? participant)) | ||
{ | ||
return participant.Name; | ||
} | ||
|
||
return "Unknown"; | ||
} | ||
|
||
public static ChatHistory ToSemanticKernelChatHistory( | ||
this Conversation conversation, | ||
string assistantId, | ||
string systemPrompt) | ||
{ | ||
var result = new ChatHistory(systemPrompt); | ||
|
||
foreach (Message msg in conversation.Messages) | ||
{ | ||
if (msg.Sender.Id == assistantId) | ||
{ | ||
result.AddAssistantMessage(msg.Content!); | ||
} | ||
else | ||
{ | ||
result.AddUserMessage( | ||
$"[{conversation.GetParticipantName(msg.Sender.Id)}] {msg.Content}"); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static string ToHtmlString( | ||
this Conversation conversation, | ||
string assistantId) | ||
{ | ||
var result = new StringBuilder(); | ||
result.AppendLine("<style>"); | ||
result.AppendLine("DIV.conversationHistory { padding: 0 20px 60px 20px; }"); | ||
result.AppendLine("DIV.conversationHistory P { margin: 0 0 8px 0; }"); | ||
result.AppendLine("</style>"); | ||
result.AppendLine("<div class='conversationHistory'>"); | ||
|
||
foreach (var msg in conversation.Messages) | ||
{ | ||
result.AppendLine("<p>"); | ||
if (msg.Sender.Id == assistantId) | ||
{ | ||
result.AppendLine("<b>Assistant</b><br/>"); | ||
} | ||
else | ||
{ | ||
result | ||
.Append("<b>") | ||
.Append(conversation.GetParticipantName(msg.Sender.Id)) | ||
.AppendLine("</b><br/>"); | ||
} | ||
|
||
result.AppendLine(msg.Content).AppendLine("</p>"); | ||
} | ||
|
||
result.Append("</div>"); | ||
|
||
return result.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
libraries/dotnet/WorkbenchConnector/AgentConfig/IAgentConfig.cs
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
libraries/dotnet/WorkbenchConnector/Models/ChatHistoryExt.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.