Skip to content

Commit

Permalink
Upgrade .NET examples to latest connector nuget (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc authored Nov 26, 2024
1 parent e44d525 commit 03a58b3
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 44 deletions.
3 changes: 3 additions & 0 deletions examples/dotnet/dotnet-01-echo-bot/MyWorkbenchConnector.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

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

Expand All @@ -14,11 +15,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,
httpServer: httpServer,
loggerFactory?.CreateLogger<MyWorkbenchConnector>() ?? new NullLogger<MyWorkbenchConnector>())
{
this._sp = sp;
Expand Down
4 changes: 2 additions & 2 deletions examples/dotnet/dotnet-01-echo-bot/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
2 changes: 0 additions & 2 deletions examples/dotnet/dotnet-01-echo-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Project Structure
* Extend `AgentBase`.
* Implement essential methods:
* `ReceiveMessageAsync()`: **handles incoming messages using intent detection, plugins, RAG, etc.**
* `GetDefaultConfig()`: provides default settings for new agent instances.
* `ParseConfig()`: deserializes a generic object into MyAgentConfig.
* **You can override default implementation for additional customization.**
4. `MyWorkbenchConnector.cs`:
* Purpose: custom instance of WorkbenchConnector.
Expand Down
24 changes: 8 additions & 16 deletions examples/dotnet/dotnet-01-echo-bot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
// 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": "AgentExample01",
// 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:9101/myagents",
// 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 endpoint.
"WorkbenchEndpoint": "http://127.0.0.1:3000",
// Name of your agent service
Expand All @@ -25,18 +29,6 @@
"ReplyToAgents": false,
"CommandsEnabled": true
},
// Web service settings
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9101"
}
// "Https": {
// "Url": "https://*:19101"
// }
}
},
// .NET Logger settings
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

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

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

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

Expand All @@ -14,11 +15,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,
httpServer: httpServer,
loggerFactory?.CreateLogger<MyWorkbenchConnector>() ?? new NullLogger<MyWorkbenchConnector>())
{
this._sp = sp;
Expand Down
4 changes: 2 additions & 2 deletions examples/dotnet/dotnet-02-message-types-demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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
24 changes: 8 additions & 16 deletions examples/dotnet/dotnet-02-message-types-demo/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
// 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": "AgentExample02",
// 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:9102/myagents",
// 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 endpoint.
"WorkbenchEndpoint": "http://127.0.0.1:3000",
// Name of your agent service
Expand All @@ -32,18 +36,6 @@
"AuthType": "ApiKey",
"ApiKey": "..."
},
// Web service settings
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9102"
}
// "Https": {
// "Url": "https://*:19102"
// }
}
},
// .NET Logger settings
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.3.241104.1" />
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -56,8 +57,4 @@
</PackageReference>
</ItemGroup>

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

</Project>

0 comments on commit 03a58b3

Please sign in to comment.