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

U/xiaoyun/cleanup #6

Merged
merged 6 commits into from
May 25, 2024
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
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-repl": {
"version": "0.1.205",
"commands": [
"dotnet-repl"
]
},
"docfx": {
"version": "2.67.5",
"commands": [
"docfx"
]
}
}
}
79 changes: 79 additions & 0 deletions .github/workflows/gh-page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Your GitHub workflow file under .github/workflows/
# Trigger the action on push to main
on:
workflow_dispatch:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '30 5,17 * * *'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
actions: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
publish-docs:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
# checkout autogen library
# url: https://github.com/microsoft/autogen/tree/dotnet
- name: Checkout
uses: actions/checkout@v3
- name: ls
run: ls
- name: Dotnet Setup
uses: actions/setup-dotnet@v3
with:
global-json-file: global.json

- run: dotnet tool update -g docfx
- run: docfx website/docfx.json

- name: insert clarity snippet to website/_site/index.html
run: |
# import os
# clarity_script = """
# <script type="text/javascript">
# (function(c,l,a,r,i,t,y){
# c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
# t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
# y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
# })(window, document, "clarity", "script", "lnypewntq4");
# </script>
# """

# site_folder = 'website/_site/'

# for root, dirs, files in os.walk(site_folder):
# for file in files:
# if file.endswith('.html'):
# html_path = os.path.join(root, file)

# # insert the script into the html's head section
# with open(html_path, 'r') as file:
# html = file.read()
# html = html.replace('</head>', clarity_script + '</head>')

# with open(html_path, 'w') as file:
# file.write(html)

# print(f'Clarity script inserted into {html_path}')
shell: python
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'dotnet/website/_site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,7 @@ FodyWeavers.xsd

# bin
bin
obj
obj

# website
_site
30 changes: 30 additions & 0 deletions ChatRoom.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatRoom.Tests", "test\Chat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatRoom.OpenAI", "ChatRoom\ChatRoom.OpenAI\ChatRoom.OpenAI.csproj", "{575F8BEE-0573-4DA2-9642-3AA266D9DA7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatRoom.Client.Tests", "test\ChatRoom.Client.Tests\ChatRoom.Client.Tests.csproj", "{6D582F66-BCD2-4295-B1CE-31E17A8684EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatRoom.OpenAI.Tests", "test\ChatRoom.OpenAI.Tests\ChatRoom.OpenAI.Tests.csproj", "{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -120,6 +124,30 @@ Global
{575F8BEE-0573-4DA2-9642-3AA266D9DA7F}.Release|x64.Build.0 = Release|Any CPU
{575F8BEE-0573-4DA2-9642-3AA266D9DA7F}.Release|x86.ActiveCfg = Release|Any CPU
{575F8BEE-0573-4DA2-9642-3AA266D9DA7F}.Release|x86.Build.0 = Release|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Debug|x64.ActiveCfg = Debug|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Debug|x64.Build.0 = Debug|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Debug|x86.ActiveCfg = Debug|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Debug|x86.Build.0 = Debug|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Release|Any CPU.Build.0 = Release|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Release|x64.ActiveCfg = Release|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Release|x64.Build.0 = Release|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Release|x86.ActiveCfg = Release|Any CPU
{6D582F66-BCD2-4295-B1CE-31E17A8684EA}.Release|x86.Build.0 = Release|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Debug|x64.ActiveCfg = Debug|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Debug|x64.Build.0 = Debug|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Debug|x86.ActiveCfg = Debug|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Debug|x86.Build.0 = Debug|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Release|Any CPU.Build.0 = Release|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Release|x64.ActiveCfg = Release|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Release|x64.Build.0 = Release|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Release|x86.ActiveCfg = Release|Any CPU
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -132,6 +160,8 @@ Global
{D7C64BB5-CCB5-4597-8DE2-1DAE05B79918} = {C0FE0076-894A-4462-8B31-3099EDBCE0A7}
{6AEA6834-F104-4C10-92F7-CBFB62F5B807} = {4503B3D3-D2C7-4FE8-A450-5A051089635C}
{575F8BEE-0573-4DA2-9642-3AA266D9DA7F} = {C0FE0076-894A-4462-8B31-3099EDBCE0A7}
{6D582F66-BCD2-4295-B1CE-31E17A8684EA} = {4503B3D3-D2C7-4FE8-A450-5A051089635C}
{57D8D4B6-619F-4CAA-A118-DF89AB68DE1E} = {4503B3D3-D2C7-4FE8-A450-5A051089635C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2F0A4B1-A064-41DD-B0C3-A4FF892EF46A}
Expand Down
4 changes: 3 additions & 1 deletion ChatRoom/ChatRoom.Client/ChatRoom.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -18,12 +18,14 @@

<ItemGroup>
<PackageReference Include="Spectre.Console" />
<PackageReference Include="Spectre.Console.Cli" />
<PackageReference Include="AutoGen" />
<PackageReference Include="Spectre.Console.ImageSharp" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ChatRoom.Common\ChatRoom.SDK.csproj" />
<ProjectReference Include="..\ChatRoom.OpenAI\ChatRoom.OpenAI.csproj" />
<ProjectReference Include="..\ChatRoom.Service\ChatRoom.Room.csproj" />
</ItemGroup>

Expand Down
71 changes: 71 additions & 0 deletions ChatRoom/ChatRoom.Client/ChatRoomClientCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Spectre.Console.Cli;

namespace ChatRoom.Client;

public class ChatRoomClientCommandSettings : CommandSettings
{
[Description("The room name to create.")]
[CommandOption("-r|--room <ROOM>")]
public string? Room { get; init; } = null;

[Description("The port to listen.")]
[CommandOption("-p|--port <PORT>")]
public int? Port { get; init; } = null;

[Description("Your name in the room")]
[CommandOption("-n|--name <NAME>")]
public string YourName { get; init; } = "User";

[Description("Configuration file")]
[CommandOption("-c|--config <CONFIG>")]
public string? ConfigFile { get; init; } = null;
}

public class ChatRoomClientCommand : AsyncCommand<ChatRoomClientCommandSettings>
{
public override async Task<int> ExecuteAsync(CommandContext context, ChatRoomClientCommandSettings command)
{
var config = command.ConfigFile is not null
? JsonSerializer.Deserialize<ChatRoomClientConfiguration>(File.ReadAllText(command.ConfigFile))!
: new ChatRoomClientConfiguration();

config.RoomConfig.Room = command.Room ?? config.RoomConfig.Room;
config.RoomConfig.Port = command.Port ?? config.RoomConfig.Port;
config.YourName = command.YourName;

var host = Host.CreateDefaultBuilder()
.UseOrleans(siloBuilder =>
{
siloBuilder
.UseLocalhostClustering(config.RoomConfig.Port)
.AddMemoryGrainStorage("PubSubStore")
.ConfigureLogging(logBuilder =>
{
logBuilder
.ClearProviders();
});
})
.ConfigureServices(serviceCollection =>
{
serviceCollection.AddSingleton(config);
serviceCollection.AddSingleton(config.RoomConfig);
serviceCollection.AddSingleton(config.ChannelConfig);
serviceCollection.AddHostedService<ConsoleChatRoomService>();
})
.Build();

await host.RunAsync();

return 0;
}
}
29 changes: 29 additions & 0 deletions ChatRoom/ChatRoom.Client/ChatRoomClientConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Text.Json.Serialization;
using ChatRoom.Room;
using Json.Schema.Generation;

namespace ChatRoom.Client;

public class ChatRoomClientConfiguration
{
[Description("The configuration for the chat room")]
[JsonPropertyName("room_config")]
public RoomConfiguration RoomConfig { get; set; } = new RoomConfiguration();

[Description("The configuration for the chat channel")]
[JsonPropertyName("channel_config")]
public ChannelConfiguration ChannelConfig { get; set; } = new ChannelConfiguration();

[JsonPropertyName("agent_extensions")]
public List<AgentExtensionConfiguration> AgentExtensions { get; set; } = [];

[JsonPropertyName("name")]
[Description("Your name in the chat room")]
public string YourName { get; set; } = "User";
}

public class AgentExtensionConfiguration
{
[JsonPropertyName("name")]
public string Name { get; init; } = null!;
}
24 changes: 11 additions & 13 deletions ChatRoom/ChatRoom.Client/ConsoleChatRoomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ public class ConsoleChatRoomService : IHostedService
private Task? _processTask = null;
private readonly ConsoleRoomObserver _roomObserver;
private readonly IRoomObserver _roomObserverRef;
private readonly Dictionary<string, IChannelObserver> _channelObservers = new();
private readonly ChatRoomClientConfiguration _configuration;

public ConsoleChatRoomService(IClusterClient clsterClient)
public ConsoleChatRoomService(ChatRoomClientConfiguration configuration, IClusterClient clsterClient)
{
_configuration = configuration;
_roomObserver = new ConsoleRoomObserver();
_roomObserverRef = clsterClient.CreateObjectReference<IRoomObserver>(_roomObserver);
_clusterClient = clsterClient;
_clientContext = new ClientContext(_clusterClient, UserName: "Zhang", CurrentChannel: "General", CurrentRoom: "room");
_clientContext = new ClientContext(_clusterClient, UserName: configuration.YourName, CurrentChannel: "General", CurrentRoom: configuration.RoomConfig.Room);
}

public async Task StartAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -145,13 +146,6 @@ async Task ProcessLoopAsync(ClientContext context, CancellationToken ct)
}

var firstTwoCharacters = input.Length >= 2 ? input[..2] : string.Empty;
if (firstTwoCharacters is "/n")
{
context = context with { UserName = input.Replace("/n", "").Trim() };
AnsiConsole.MarkupLine(
"[dim][[STATUS]][/] Set username to [lime]{0}[/]", context.UserName);
continue;
}

if (firstTwoCharacters switch
{
Expand Down Expand Up @@ -198,14 +192,17 @@ private void PrintUsage()
}.HideHeaders();
table.AddColumn(new TableColumn("One"));

var header = new FigletText("Agent Chat Room")
var header = new FigletText("Agent")
{
Color = Color.Aqua
};
var header2 = new FigletText("ChatRoom")
{
Color = Color.Aqua
};

var markup = new Markup(
"[bold fuchsia]/j[/] [aqua]<channel>[/] to [underline green]join[/] a specific channel\n"
+ "[bold fuchsia]/n[/] [aqua]<username>[/] to set your [underline green]name[/]\n"
+ "[bold fuchsia]/l[/] to [underline green]leave[/] the current channel\n"
+ "[bold fuchsia]/h[/] to re-read channel [underline green]history[/]\n"
+ "[bold fuchsia]/m[/] to query [underline green]members[/] in the current channel\n"
Expand All @@ -224,10 +221,11 @@ private void PrintUsage()
.AddColumn(new TableColumn("Content"));

rightTable.AddRow(header)
.AddRow(header2)
.AddEmptyRow()
.AddEmptyRow()
.AddRow(markup);
table.AddRow(logo, rightTable);
table.AddRow(rightTable);

AnsiConsole.Write(table);
AnsiConsole.WriteLine();
Expand Down
20 changes: 3 additions & 17 deletions ChatRoom/ChatRoom.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Spectre.Console.Cli;

var channelHost = Host.CreateDefaultBuilder(args)
.UseOrleans(siloBuilder =>
{
siloBuilder
.UseLocalhostClustering()
.AddMemoryGrainStorage("PubSubStore")
.ConfigureLogging(logBuilder =>
{
logBuilder
.ClearProviders();
});
})
.ConfigureServices(serviceCollection => serviceCollection.AddHostedService<ConsoleChatRoomService>())
.Build();

await channelHost.StartAsync();
await channelHost.WaitForShutdownAsync();
var app = new CommandApp<ChatRoomClientCommand>();
await app.RunAsync(args);
8 changes: 8 additions & 0 deletions ChatRoom/ChatRoom.Common/AgentCollectionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using AutoGen.Core;

namespace ChatRoom.SDK
{
internal class AgentCollectionService : List<IAgent>
{
}
}
1 change: 1 addition & 0 deletions ChatRoom/ChatRoom.Common/ChatRoom.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Microsoft.Orleans.Sdk" />
<PackageReference Include="Microsoft.Orleans.Streaming" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="Spectre.Console.Cli" />
<PackageReference Include="AutoGen.Core" />
</ItemGroup>

Expand Down
Loading
Loading