Skip to content

Commit 7c4b900

Browse files
committed
Added command for testing LLM (/rcc-test)
1 parent dc7f631 commit 7c4b900

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

ai-assistant/src/RocketChatterApp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { FindSimilarCommand } from "./commands/FindSimilar";
2323
import { HelpCommand } from "./commands/HelpCommand";
2424
import { ImportanceCommand } from "./commands/ImportanceCommand";
2525
import { ImproveCommand } from "./commands/ImproveCommand";
26+
import { TestCommand } from "./commands/TestLLM";
2627
import { TranslateCommand } from "./commands/TranslateCommand";
2728
import { WhyUsedCommand } from "./commands/WhyUsedCommand";
2829
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations";
@@ -63,6 +64,8 @@ export class RocketChatterApp extends App {
6364
configuration.slashCommands.provideSlashCommand(new TranslateCommand());
6465
configuration.slashCommands.provideSlashCommand(new WhyUsedCommand());
6566

67+
configuration.slashCommands.provideSlashCommand(new TestCommand());
68+
6669
await configuration.api.provideApi({
6770
visibility: ApiVisibility.PUBLIC,
6871
security: ApiSecurity.UNSECURE,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
IHttp,
3+
IModify,
4+
IRead,
5+
} from "@rocket.chat/apps-engine/definition/accessors";
6+
import {
7+
ISlashCommand,
8+
SlashCommandContext,
9+
} from "@rocket.chat/apps-engine/definition/slashcommands";
10+
11+
import { Llama3_70B } from "../core/llm/llama3_70B";
12+
import { Prompt } from "../core/prompt/prompt";
13+
import { handleCommandResponse } from "../utils/handleCommandResponse";
14+
15+
export class TestCommand implements ISlashCommand {
16+
public command = "rcc-test";
17+
public i18nParamsExample = "";
18+
public i18nDescription = "";
19+
public providesPreview = false;
20+
21+
private async process(http: IHttp, query: string): Promise<string | null> {
22+
const llm = new Llama3_70B(http);
23+
24+
const prompt = new Prompt();
25+
prompt.pushUser(query);
26+
27+
const answer = await llm.ask(prompt);
28+
if (!answer) return null;
29+
30+
return answer;
31+
}
32+
33+
public async executor(
34+
context: SlashCommandContext,
35+
read: IRead,
36+
modify: IModify,
37+
http: IHttp
38+
): Promise<void> {
39+
const query = context.getArguments().join(" ");
40+
if (!query) return;
41+
42+
const sendEditedMessage = await handleCommandResponse(
43+
query,
44+
context.getSender(),
45+
context.getRoom(),
46+
modify,
47+
this.command
48+
);
49+
50+
const res = await this.process(http, query);
51+
if (res) {
52+
await sendEditedMessage(res);
53+
} else {
54+
await sendEditedMessage("❌ Unable to process your query");
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)