Skip to content

Commit ecbe8b0

Browse files
committed
Minor fixes to the DB and Help pages
1 parent 3e1fbc2 commit ecbe8b0

File tree

6 files changed

+58
-28
lines changed

6 files changed

+58
-28
lines changed

Readme.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,16 @@ Did you like this tool? Give us a visit :) [https://prographers.com/](https://pr
1616
- Parameters for controlling the bot's behavior
1717
- Docker support
1818
- Full documentation
19-
- Custom pre-defined commands
19+
- Custom pre-defined and dynamic commands
20+
- Context, a system message for the whole thread `-context`
2021

2122
## Dependencies
2223

2324
- .NET 7.0
2425
- OpenAI-DotNet
2526
- SlackNet
2627
- SlackNet.AspNetCore
27-
28-
## Installation
29-
30-
- Clone the repository
31-
32-
```bash
33-
git clone https://github.com/Prographers/Slack-GPT.git
34-
cd Slack-GPT
35-
```
36-
37-
- Restore nuget packages
38-
39-
```bash
40-
dotnet restore
41-
```
28+
- Octokit.Net
4229

4330
## Getting OpenAI Api Key
4431

@@ -97,6 +84,9 @@ or per request.
9784
See GptDefaults.cs for more information about the defaults or `appsettings.Example.json`.
9885

9986
### Custom parameters
87+
88+
**Predefined commands**
89+
10090
You can add you own custom parameters to the bot to minimize the typing for each repated request. To do so, add the it's definition
10191
to the `GptCommands` section in `appsettings.json`. For example:
10292

@@ -121,6 +111,17 @@ usage:
121111

122112
> @GPT-4 -refactor `public class Foo { public void Bar() { Console.WriteLine("Hello World"); } }`
123113

114+
**Dynamic commands**
115+
116+
In a similar manner you can create dynamic commands. To do so, call the
117+
`/gpt commands add -command "prompt" "description" -global` command with the command name and the prompt.
118+
- `-command` How this command will be called. eg: `-prographers`
119+
- `-prompt` The prompt that will be used for this command. eg: `Prographers is software-house company...`
120+
- `-description` The description of the command. eg: `A command to add infomation about Prographers` this is optional.
121+
- `-global` flag will make the command available to all users. Otherwise it will be available for the user who created it.
122+
123+
Use `/gpt commands help` to see more information about the commands.
124+
124125
## Docker
125126

126127
You can start the docker container with the following command:
@@ -155,6 +156,21 @@ through the Slack API. The container is also running as a non-root user, and has
155156
- Deleting a message is a way to re-do the thread. So then it's easier to track the conversation when editing the message.
156157
- Ephemeral messages that are generated by the bot will disappear after slack client reloads. You can disable them in settings.
157158

159+
## Run locally from source
160+
161+
- Clone the repository
162+
163+
```bash
164+
git clone https://github.com/Prographers/Slack-GPT.git
165+
cd Slack-GPT
166+
```
167+
168+
- Restore nuget packages
169+
170+
```bash
171+
dotnet restore
172+
```
173+
158174
## Screenshot
159175

160176
Notification messages!

Slack-GPT-Socket.sln.DotSettings.user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
<TestId>NUnit3x::8513CAC6-F4FB-4821-B229-7B2E31E1DA66::net7.0::Slack_GPT_Tests.Handlers.CommandHandlerTests.CommandsCommand_AddSameCommand_MultipleUsers_CannotRemove</TestId>
2020
<TestId>NUnit3x::8513CAC6-F4FB-4821-B229-7B2E31E1DA66::net7.0::Slack_GPT_Tests.Handlers.CommandHandlerTests.WhatsNewCommand_Ok</TestId>
2121
<TestId>NUnit3x::8513CAC6-F4FB-4821-B229-7B2E31E1DA66::net7.0::Slack_GPT_Tests.Handlers.CommandHandlerTests.WhatsNewCommand_Error</TestId>
22+
<TestId>NUnit3x::8513CAC6-F4FB-4821-B229-7B2E31E1DA66::net7.0::Slack_GPT_Tests.TestLiteDB.TestNullConnectionString_Ok</TestId>
2223
</TestAncestor>
2324
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

Slack-GPT-Socket/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
builder.Services.AddSingleton<GptClient>();
1717
builder.Services.AddSingleton<GptCustomCommands>();
18-
builder.Services.AddSingleton<ILiteDatabase>(x => new LiteDatabase(builder.Configuration.GetConnectionString("LiteDB")));
18+
builder.Services.AddSingleton<ILiteDatabase>(x =>
19+
new LiteDatabase(builder.Configuration.GetConnectionString("LiteDB") ?? "Filename=:memory:;Mode=Memory;Cache=Shared")
20+
);
1921

2022
builder.Services.AddSingleton<IUserCommandDb, UserCommandDb>();
2123

Slack-GPT-Socket/SlackHandlers/Command/HelpCommandStrategy.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ public async Task<SlashCommandResponse> Execute(SlashCommand command)
3434
{
3535
// If command is just "help", return general help text
3636
if (command.Text == "help") return CommandStrategyUtils.SlashCommandResponse(GeneralHelpText(command));
37-
37+
3838
// If command is "help <command>", return help text for that command
3939
var commandName = command.Text.Substring(4).Trim();
4040

4141
foreach (var parameter in _parameterManager)
4242
{
43-
var args = new ParameterEventArgs()
43+
var args = new ParameterEventArgs
4444
{
4545
Name = commandName,
4646
UserId = command.UserId,
4747
Value = string.Empty,
4848
ValueRaw = string.Empty
4949
};
50-
50+
5151
if (parameter.CanHandle(args))
5252
{
53-
return CommandStrategyUtils.SlashCommandResponse(parameter.BuildHelpText(_gptDefaults,
53+
return CommandStrategyUtils.SlashCommandResponse(parameter.BuildHelpText(_gptDefaults,
5454
commandName, command.UserId));
5555
}
5656
}
@@ -67,11 +67,20 @@ public async Task<SlashCommandResponse> Execute(SlashCommand command)
6767
private string GeneralHelpText(SlashCommand command)
6868
{
6969
var sb = new StringBuilder();
70-
sb.AppendLine("Here are the commands you can use with the model\n" +
71-
"Commands are only accepted if put at the beginning of the prompt eg:" +
72-
"-command <prompt>\n" +
73-
"@GPT -command <prompt>\n" +
74-
"/gpt -command <prompt>\n");
70+
sb.AppendLine("Here are the commands you can use with the model");
71+
sb.AppendLine("Commands are only accepted if put at the beginning of the prompt eg:");
72+
sb.AppendLine("`-command <prompt>`");
73+
sb.AppendLine($"`@{_botInfo.BotInfo.User} -command <prompt>`");
74+
sb.AppendLine("`/gpt -command <prompt>`");
75+
sb.AppendLine();
76+
sb.AppendLine("You can also use the following commands:");
77+
sb.AppendLine(" - `/gpt help` - Display this help");
78+
sb.AppendLine(" - `/gpt status` - Get the status of the bot");
79+
sb.AppendLine(" - `/gpt commands` - List all commands");
80+
sb.AppendLine(" - `/gpt whatsNew` - List the latest changes");
81+
sb.AppendLine(" - `/gpt help <command>` - List help for a specific parameter command");
82+
83+
sb.AppendLine();
7584
foreach (var parameter in _parameterManager)
7685
{
7786
sb.AppendLine(parameter.BuildShortHelpText(_gptDefaults, command.UserId));

Slack-GPT-Socket/Utilities/LiteDB/UserCommandDB.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public UserCommandDb(ILiteDatabase database)
1515
_commands.EnsureIndex(x => x.Command);
1616
_commands.EnsureIndex(x => x.UserId);
1717
}
18-
18+
1919
/// <inheritdoc />
2020
public GptUserCommand? FindCommand(string command, string? userId = null)
2121
{

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ services:
88
labels:
99
- "com.centurylinklabs.watchtower.scope=slack-gpt"
1010
volumes:
11-
- ./appsettings.json:/app/appsettings.json
11+
# See appsettings.json.example for configuration this file is required
12+
- ./appsettings.json:/app/appsettings.json
13+
- slack-gpt-liteDB:/app/app.db
1214

1315
watchtower-slack-gpt:
1416
image: containrrr/watchtower

0 commit comments

Comments
 (0)