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

.NET Connector improvements #263

Merged
merged 84 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7cb6d04
aspire-ize semantic workbench
tommasodotNET Oct 17, 2024
eb7616f
using localhost globally
tommasodotNET Oct 18, 2024
72efe3b
working example with aspire and uvicorn integration
tommasodotNET Oct 30, 2024
4e5aec2
dynamic python port
tommasodotNET Oct 30, 2024
25ffb12
python assistant port defined via env var
tommasodotNET Oct 30, 2024
c14c7af
python assistant read workbench service url from env
tommasodotNET Oct 30, 2024
395ac99
reverting port changes for python services
tommasodotNET Oct 31, 2024
dcdae5e
using correct env var for python assistant and dockerfile for FE
tommasodotNET Oct 31, 2024
f2f95cf
use custom env var for workbench service endpoint in app
tommasodotNET Nov 4, 2024
521a63b
correct injection of workbench servic endoint
tommasodotNET Nov 4, 2024
b5d0523
ensure correct env var are used in dotnet example 3
tommasodotNET Nov 4, 2024
a5d71ed
deploy via azd using workaround for dockerfile
tommasodotNET Nov 4, 2024
8ebb7e0
using correct env var for workbench_service url in python assistants
tommasodotNET Nov 4, 2024
92d6b07
working deployment with azd
tommasodotNET Nov 12, 2024
0579f2d
don't pass port during frontend docker build - not needed
tommasodotNET Nov 12, 2024
cc3d3f6
working deployment with hardcoded appids in wk service
tommasodotNET Nov 15, 2024
5ea3865
update doc
tommasodotNET Nov 15, 2024
1f01853
app registration id is now picked from .env in docker
tommasodotNET Nov 15, 2024
fcb51dc
working deployment of dotnet example
tommasodotNET Nov 17, 2024
cf0fcdc
working assistant deployment
tommasodotNET Nov 17, 2024
39f9d24
reorders apphost
tommasodotNET Nov 17, 2024
546aab2
reorders packages
tommasodotNET Nov 17, 2024
2bd7301
Merge branch 'feature/aspire-orchestration' into sk-aspire-orchestrator
tommasodotNET Nov 18, 2024
1439600
Merge pull request #1 from tommasodotNET/sk-aspire-orchestrator
tommasodotNET Nov 18, 2024
bfc6ad2
cleans up
tommasodotNET Nov 18, 2024
cf616a7
adds doc
tommasodotNET Nov 18, 2024
b995bd5
uses new start assistant
tommasodotNET Nov 18, 2024
7d75f20
imrpove doc
tommasodotNET Nov 18, 2024
75adb16
updates doc
tommasodotNET Nov 18, 2024
78f2f8b
fixes assistant container params
tommasodotNET Nov 18, 2024
3bc4132
differentiate aspire dockerfile from already existing ones
tommasodotNET Nov 19, 2024
9194aa8
Minor code style changes
dluc Nov 20, 2024
478558e
cleans workbench app dockerfile
tommasodotNET Nov 21, 2024
b79c010
Merge branch 'feature/aspire-orchestration' of github.com:tommasodotN…
tommasodotNET Nov 21, 2024
a49bdc6
back to 127.0.0.1 on workbench config
tommasodotNET Nov 21, 2024
6e22f25
fixes workbench app docker-entrypoint logs
tommasodotNET Nov 21, 2024
2c5d5b1
revert space on start
tommasodotNET Nov 21, 2024
edf02f7
removed next-steps.md
tommasodotNET Nov 21, 2024
b2edabb
removes sshd from Dockerfile workbench service and assistant
tommasodotNET Nov 21, 2024
9f999e0
reverts .env.example
tommasodotNET Nov 21, 2024
1549338
reverts settings.py
tommasodotNET Nov 21, 2024
04fdd9c
improve readme
tommasodotNET Nov 21, 2024
d8ebe56
improves readme requirements
tommasodotNET Nov 21, 2024
d21dd93
Update aspire-orchestrator/SemanticWorkbench.Aspire.Hosting.Extension…
tommasodotNET Nov 21, 2024
d807ddb
Update aspire-orchestrator/SemanticWorkbench.Aspire.Hosting.Extension…
tommasodotNET Nov 21, 2024
436724f
fixes folder for apphost in doc
tommasodotNET Nov 21, 2024
18f5e55
Merge branch 'feature/aspire-orchestration' of github.com:tommasodotN…
tommasodotNET Nov 21, 2024
b0d15ae
using arg value for vite_semanticworkbenchurl
tommasodotNET Nov 21, 2024
5164b96
moves dockerfileextensions to separate class
tommasodotNET Nov 21, 2024
e36aed7
aspire overwrites correct var env for agents
tommasodotNET Nov 22, 2024
1f57be4
adds copyright
tommasodotNET Nov 22, 2024
979c982
Revert "using arg value for vite_semanticworkbenchurl"
tommasodotNET Nov 22, 2024
6cce626
deletes aspire-manifest
tommasodotNET Nov 22, 2024
894edd0
uses workaround for workbench service url in frontend
tommasodotNET Nov 22, 2024
ecbd522
dockerignore .env files
tommasodotNET Nov 22, 2024
7550962
dockerignore .azure folder
tommasodotNET Nov 22, 2024
173be67
adds comment on agent autoreference
tommasodotNET Nov 22, 2024
6e000fc
adds doc for dotnet dev certs
tommasodotNET Nov 22, 2024
d486df2
use env var for entra ID config
tommasodotNET Nov 22, 2024
dee1515
read entraid config from appsettings
tommasodotNET Nov 22, 2024
b5d46c9
adds default values for app registration
tommasodotNET Nov 22, 2024
151e3b5
Code style
dluc Nov 22, 2024
3966a6d
Update workbench-service/.env.example
dluc Nov 22, 2024
69577ff
Add comment to new docker file
dluc Nov 22, 2024
5c268bb
Code style
dluc Nov 22, 2024
a81b81a
Revert code style changes
dluc Nov 22, 2024
c85664c
Revert changes to agent 3 csproj
dluc Nov 22, 2024
3751414
Update examples/dotnet/dotnet-03-simple-chatbot/Program.cs
dluc Nov 22, 2024
37f9a73
Update examples/dotnet/dotnet-03-simple-chatbot/dotnet-03-simple-chat…
dluc Nov 22, 2024
2ec753d
Update libraries/python/semantic-workbench-assistant/semantic_workben…
dluc Nov 22, 2024
2a2a7a3
Update workbench-app/src/Constants.ts
dluc Nov 22, 2024
1ab7323
Update workbench-app/src/global.d.ts
dluc Nov 22, 2024
1710d40
Fix SLN filename
dluc Nov 23, 2024
b171320
Fix project names
dluc Nov 23, 2024
90ca96b
Reorg projects
dluc Nov 23, 2024
a6252ad
Fix URLs and ping errors
dluc Nov 23, 2024
c2f0449
Handle ping exceptions
dluc Nov 23, 2024
7095216
Improve logging
dluc Nov 25, 2024
5831c2b
Change ping frequency
dluc Nov 25, 2024
7b7bbc3
Auto detect port in use and better handle some exceptions
dluc Nov 25, 2024
590e67e
Remove Aspire files
dluc Nov 25, 2024
1c689de
Fix build warnings
dluc Nov 26, 2024
74707f1
Update workbench-app/.env.example
dluc Nov 26, 2024
207e1d5
Update workbench-app/index.html
dluc Nov 26, 2024
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
5 changes: 3 additions & 2 deletions examples/dotnet/dotnet-01-echo-bot/dotnet-01-echo-bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<RootNamespace>AgentExample</RootNamespace>
<PackageId>AgentExample</PackageId>
<NoWarn>$(NoWarn);CA1515;IDE0290;</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,15 +28,15 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
28 changes: 14 additions & 14 deletions examples/dotnet/dotnet-02-message-types-demo/MyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ public override Task ReceiveMessageAsync(
Message message,
CancellationToken cancellationToken = default)
{
switch (this.Config.Behavior.ToLowerInvariant())
return this.Config.Behavior.ToLowerInvariant() switch
{
case "echo": return this.EchoExampleAsync(conversationId, message, cancellationToken);
case "reverse": return this.ReverseExampleAsync(conversationId, message, cancellationToken);
case "safety check": return this.SafetyCheckExampleAsync(conversationId, message, cancellationToken);
case "markdown sample": return this.MarkdownExampleAsync(conversationId, message, cancellationToken);
case "html sample": return this.HTMLExampleAsync(conversationId, message, cancellationToken);
case "code sample": return this.CodeExampleAsync(conversationId, message, cancellationToken);
case "json sample": return this.JSONExampleAsync(conversationId, message, cancellationToken);
case "mermaid sample": return this.MermaidExampleAsync(conversationId, message, cancellationToken);
case "music sample": return this.MusicExampleAsync(conversationId, message, cancellationToken);
case "none": return this.NoneExampleAsync(conversationId, message, cancellationToken);
default: return this.NoneExampleAsync(conversationId, message, cancellationToken);
}
"echo" => this.EchoExampleAsync(conversationId, message, cancellationToken),
"reverse" => this.ReverseExampleAsync(conversationId, message, cancellationToken),
"safety check" => this.SafetyCheckExampleAsync(conversationId, message, cancellationToken),
"markdown sample" => this.MarkdownExampleAsync(conversationId, message, cancellationToken),
"html sample" => this.HTMLExampleAsync(conversationId, message, cancellationToken),
"code sample" => this.CodeExampleAsync(conversationId, message, cancellationToken),
"json sample" => this.JSONExampleAsync(conversationId, message, cancellationToken),
"mermaid sample" => this.MermaidExampleAsync(conversationId, message, cancellationToken),
"music sample" => this.MusicExampleAsync(conversationId, message, cancellationToken),
"none" => this.NoneExampleAsync(conversationId, message, cancellationToken),
_ => this.NoneExampleAsync(conversationId, message, cancellationToken)
};
}

// Check text with Azure Content Safety
Expand All @@ -111,7 +111,7 @@ public override Task ReceiveMessageAsync(
Response<AnalyzeTextResult>? result = await this._contentSafety.AnalyzeTextAsync(text, cancellationToken).ConfigureAwait(false);

bool isSafe = result.HasValue && result.Value.CategoriesAnalysis.All(x => x.Severity is 0);
IEnumerable<string> report = result.HasValue ? result.Value.CategoriesAnalysis.Select(x => $"{x.Category}: {x.Severity}") : Array.Empty<string>();
IEnumerable<string> report = result.HasValue ? result.Value.CategoriesAnalysis.Select(x => $"{x.Category}: {x.Severity}") : [];

return (isSafe, report);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<RootNamespace>AgentExample</RootNamespace>
<PackageId>AgentExample</PackageId>
<NoWarn>$(NoWarn);CA1308;CA1861;</NoWarn>
<NoWarn>$(NoWarn);CA1308;CA1861;CA1515;IDE0290;</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,15 +31,15 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
9 changes: 8 additions & 1 deletion examples/dotnet/dotnet-03-simple-chatbot/MyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ public override async Task ReceiveMessageAsync(
{
// Show some status while working...
await this.SetAgentStatusAsync(conversationId, "Thinking...", cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
this.Log.LogWarning(e, "Something went wrong while setting temporary status");
}

try
{
// Update the chat history to include the message received
var conversation = await base.AddMessageToHistoryAsync(conversationId, message, cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -319,7 +326,7 @@ private IChatCompletionService GetChatCompletionService()
Response<AnalyzeTextResult>? result = await this._contentSafety.AnalyzeTextAsync(text, cancellationToken).ConfigureAwait(false);

bool isSafe = result.HasValue && result.Value.CategoriesAnalysis.All(x => x.Severity is 0);
IEnumerable<string> report = result.HasValue ? result.Value.CategoriesAnalysis.Select(x => $"{x.Category}: {x.Severity}") : Array.Empty<string>();
IEnumerable<string> report = result.HasValue ? result.Value.CategoriesAnalysis.Select(x => $"{x.Category}: {x.Severity}") : [];

return (isSafe, report);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Text.Json;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticWorkbench.Connector;

namespace AgentExample;

public sealed class MyWorkbenchConnector : WorkbenchConnector<MyAgentConfig>
internal sealed class MyWorkbenchConnector : WorkbenchConnector<MyAgentConfig>
{
private readonly IServiceProvider _sp;
private readonly IConfiguration _appConfig;
Expand All @@ -15,11 +16,13 @@ public MyWorkbenchConnector(
IServiceProvider sp,
IConfiguration appConfig,
IAgentServiceStorage storage,
IServer httpServer,
ILoggerFactory? loggerFactory = null)
: base(
workbenchConfig: appConfig.GetSection("Workbench").Get<WorkbenchConfig>(),
defaultAgentConfig: appConfig.GetSection("Agent").Get<MyAgentConfig>(),
storage: storage,
httpServer: httpServer,
logger: loggerFactory?.CreateLogger<MyWorkbenchConnector>() ?? new NullLogger<MyWorkbenchConnector>())
{
this._sp = sp;
Expand Down
4 changes: 2 additions & 2 deletions examples/dotnet/dotnet-03-simple-chatbot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ internal static async Task Main(string[] args)
app.UseCors(CORSPolicyName);

// Connect to workbench backend, keep alive, and accept incoming requests
var connectorEndpoint = app.Configuration.GetSection("Workbench").Get<WorkbenchConfig>()!.ConnectorEndpoint;
using var agentService = app.UseAgentWebservice<MyAgentConfig>(connectorEndpoint, true);
var connectorApiPrefix = app.Configuration.GetSection("Workbench").Get<WorkbenchConfig>()!.ConnectorApiPrefix;
using var agentService = app.UseAgentWebservice<MyAgentConfig>(connectorApiPrefix, true);
await agentService.ConnectAsync().ConfigureAwait(false);

// Start app and webservice
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
28 changes: 11 additions & 17 deletions examples/dotnet/dotnet-03-simple-chatbot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
// Unique ID of the service. Semantic Workbench will store this event to identify the server
// so you should keep the value fixed to match the conversations tracked across service restarts.
"ConnectorId": "AgentExample03",
// The endpoint of your service, where semantic workbench will send communications too.
// This should match hostname, port, protocol and path of the web service. You can use
// this also to route semantic workbench through a proxy or a gateway if needed.
"ConnectorEndpoint": "http://127.0.0.1:9103/myagents",
// Semantic Workbench endpoint.
// The host where the connector receives requests sent by the workbench.
// Locally, this is usually "http://127.0.0.1:<some port>"
// On Azure, this will be something like "https://contoso.azurewebsites.net"
// Leave this setting empty to use "127.0.0.1" and autodetect the port in use.
// You can use an env var to set this value, e.g. Workbench__ConnectorHost=https://contoso.azurewebsites.net
"ConnectorHost": "",
// This is the prefix of all the endpoints exposed by the connector
"ConnectorApiPrefix": "/myagents",
// Semantic Workbench backend endpoint.
// The connector connects to this workbench endpoint to register its presence.
// The workbench connects back to the connector to send events (see ConnectorHost and ConnectorApiPrefix).
"WorkbenchEndpoint": "http://127.0.0.1:3000",
// Name of your agent service
"ConnectorName": ".NET Multi Agent Service",
Expand Down Expand Up @@ -48,18 +54,6 @@
"Endpoint": "https://api.openai.com/v1/",
"ApiKey": "sk-..."
},
// Web service settings
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9103"
}
// "Https": {
// "Url": "https://*:19103
// }
}
},
// .NET Logger settings
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
<Nullable>enable</Nullable>
<RootNamespace>AgentExample</RootNamespace>
<PackageId>AgentExample</PackageId>
<NoWarn>$(NoWarn);SKEXP0010;CA1861;</NoWarn>
<NoWarn>$(NoWarn);SKEXP0010;CA1861;CA1515;IDE0290;CA1031;CA1812;</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.3.241104.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
Expand All @@ -34,15 +30,15 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -60,4 +56,8 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" />
</ItemGroup>

</Project>
Loading