Skip to content

Commit 4d2915c

Browse files
committed
Added .prettierrc
1 parent 1562a8c commit 4d2915c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3975
-4401
lines changed

ai-assistant/.prettierrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"printWidth": 110,
3+
"tabWidth": 3,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": false,
7+
"trailingComma": "es5",
8+
"bracketSpacing": true,
9+
"arrowParens": "always",
10+
"requirePragma": false,
11+
"insertPragma": false,
12+
"proseWrap": "always",
13+
"bracketSameLine": false,
14+
"endOfLine": "lf"
15+
}

ai-assistant/bun.lockb

368 Bytes
Binary file not shown.

ai-assistant/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"scripts": {
3-
"dev": "clear && tsx src/test.ts"
3+
"dev": "clear && tsx src/test.ts",
4+
"pretty": "prettier --config .prettierrc --write ./src/*"
45
},
56
"devDependencies": {
67
"@rocket.chat/apps-cli": "^1.11.1",
78
"@rocket.chat/apps-engine": "^1.19.0",
89
"@types/node": "14.14.6",
10+
"esbuild": "^0.19.4",
11+
"prettier": "^3.3.3",
912
"tslint": "^5.10.0",
1013
"tsx": "^4.17.0",
11-
"typescript": "^4.0.5",
12-
"esbuild": "^0.19.4"
14+
"typescript": "^4.0.5"
1315
},
1416
"dependencies": {}
1517
}

ai-assistant/src/RocketChatterApp.ts

Lines changed: 61 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,70 @@
11
import {
2-
IAppAccessors,
3-
IConfigurationExtend,
4-
IHttp,
5-
ILogger,
6-
IModify,
7-
IPersistence,
8-
IRead,
9-
} from "@rocket.chat/apps-engine/definition/accessors";
10-
import { App } from "@rocket.chat/apps-engine/definition/App";
11-
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
2+
IAppAccessors,
3+
IConfigurationExtend,
4+
IHttp,
5+
ILogger,
6+
IModify,
7+
IPersistence,
8+
IRead,
9+
} from "@rocket.chat/apps-engine/definition/accessors"
10+
import { App } from "@rocket.chat/apps-engine/definition/App"
11+
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata"
1212

13-
import {
14-
ApiSecurity,
15-
ApiVisibility,
16-
} from "@rocket.chat/apps-engine/definition/api";
17-
import { UIKitViewSubmitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit";
18-
import { AskCodeCommand } from "./commands/AskCodeCommand";
19-
import { AskDocsCommand } from "./commands/AskDocsCommand";
20-
import { DiagramCommand } from "./commands/DiagramCommand";
21-
import { DocumentCommand } from "./commands/DocumentCommand";
22-
import { FindSimilarCommand } from "./commands/FindSimilar";
23-
import { HelpCommand } from "./commands/HelpCommand";
24-
import { ImportanceCommand } from "./commands/ImportanceCommand";
25-
import { ImproveCommand } from "./commands/ImproveCommand";
26-
import { TestcasesCommand } from "./commands/TestcasesCommand";
27-
import { TranslateCommand } from "./commands/TranslateCommand";
28-
import { WhyUsedCommand } from "./commands/WhyUsedCommand";
29-
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations";
30-
import { IngestEndpoint } from "./endpoints/ingest";
31-
import { PurgeDBEndpoint } from "./endpoints/purgeDB";
32-
import { handleModalViewSubmit } from "./utils/handleModalViewSubmit";
13+
import { ApiSecurity, ApiVisibility } from "@rocket.chat/apps-engine/definition/api"
14+
import { UIKitViewSubmitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit"
15+
import { AskCodeCommand } from "./commands/AskCodeCommand"
16+
import { AskDocsCommand } from "./commands/AskDocsCommand"
17+
import { DiagramCommand } from "./commands/DiagramCommand"
18+
import { DocumentCommand } from "./commands/DocumentCommand"
19+
import { FindSimilarCommand } from "./commands/FindSimilar"
20+
import { HelpCommand } from "./commands/HelpCommand"
21+
import { ImportanceCommand } from "./commands/ImportanceCommand"
22+
import { ImproveCommand } from "./commands/ImproveCommand"
23+
import { TestcasesCommand } from "./commands/TestcasesCommand"
24+
import { TranslateCommand } from "./commands/TranslateCommand"
25+
import { WhyUsedCommand } from "./commands/WhyUsedCommand"
26+
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations"
27+
import { IngestEndpoint } from "./endpoints/ingest"
28+
import { PurgeDBEndpoint } from "./endpoints/purgeDB"
29+
import { handleModalViewSubmit } from "./utils/handleModalViewSubmit"
3330

3431
export class RocketChatterApp extends App {
35-
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
36-
super(info, logger, accessors);
37-
}
32+
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
33+
super(info, logger, accessors)
34+
}
3835

39-
public async executeViewSubmitHandler(
40-
context: UIKitViewSubmitInteractionContext,
41-
read: IRead,
42-
http: IHttp,
43-
persistence: IPersistence,
44-
modify: IModify
45-
) {
46-
handleModalViewSubmit(context, read, http, modify);
47-
}
36+
public async executeViewSubmitHandler(
37+
context: UIKitViewSubmitInteractionContext,
38+
read: IRead,
39+
http: IHttp,
40+
persistence: IPersistence,
41+
modify: IModify
42+
) {
43+
handleModalViewSubmit(context, read, http, modify)
44+
}
4845

49-
public async extendConfiguration(configuration: IConfigurationExtend) {
50-
configuration.slashCommands.provideSlashCommand(new HelpCommand());
46+
public async extendConfiguration(configuration: IConfigurationExtend) {
47+
configuration.slashCommands.provideSlashCommand(new HelpCommand())
5148

52-
configuration.slashCommands.provideSlashCommand(new AskCodeCommand());
53-
configuration.slashCommands.provideSlashCommand(new AskDocsCommand());
54-
configuration.slashCommands.provideSlashCommand(new DiagramCommand());
55-
configuration.slashCommands.provideSlashCommand(new DocumentCommand());
56-
configuration.slashCommands.provideSlashCommand(
57-
new FindSimilarCommand()
58-
);
59-
configuration.slashCommands.provideSlashCommand(
60-
new ImportanceCommand()
61-
);
62-
configuration.slashCommands.provideSlashCommand(new ImproveCommand());
63-
configuration.slashCommands.provideSlashCommand(new TestcasesCommand());
64-
configuration.slashCommands.provideSlashCommand(new TranslateCommand());
65-
configuration.slashCommands.provideSlashCommand(new WhyUsedCommand());
49+
configuration.slashCommands.provideSlashCommand(new AskCodeCommand())
50+
configuration.slashCommands.provideSlashCommand(new AskDocsCommand())
51+
configuration.slashCommands.provideSlashCommand(new DiagramCommand())
52+
configuration.slashCommands.provideSlashCommand(new DocumentCommand())
53+
configuration.slashCommands.provideSlashCommand(new FindSimilarCommand())
54+
configuration.slashCommands.provideSlashCommand(new ImportanceCommand())
55+
configuration.slashCommands.provideSlashCommand(new ImproveCommand())
56+
configuration.slashCommands.provideSlashCommand(new TestcasesCommand())
57+
configuration.slashCommands.provideSlashCommand(new TranslateCommand())
58+
configuration.slashCommands.provideSlashCommand(new WhyUsedCommand())
6659

67-
await configuration.api.provideApi({
68-
visibility: ApiVisibility.PUBLIC,
69-
security: ApiSecurity.UNSECURE,
70-
endpoints: [
71-
new IngestEndpoint(this),
72-
new PurgeDBEndpoint(this),
73-
new EstablishRelationsEndpoint(this),
74-
],
75-
});
76-
}
60+
await configuration.api.provideApi({
61+
visibility: ApiVisibility.PUBLIC,
62+
security: ApiSecurity.UNSECURE,
63+
endpoints: [
64+
new IngestEndpoint(this),
65+
new PurgeDBEndpoint(this),
66+
new EstablishRelationsEndpoint(this),
67+
],
68+
})
69+
}
7770
}
Lines changed: 82 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,94 @@
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";
1+
import { IHttp, IModify, IRead } from "@rocket.chat/apps-engine/definition/accessors"
2+
import { ISlashCommand, SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"
103

11-
import { PromptFactory } from "../core/prompt.factory";
12-
import { Query } from "../core/query";
13-
import { Neo4j } from "../core/services/db/neo4j";
14-
import { MiniLML6 } from "../core/services/embeddings/minilml6";
15-
import { Llama3_70B } from "../core/services/llm/llama3_70B";
16-
import { handleCommandResponse } from "../utils/handleCommandResponse";
4+
import { PromptFactory } from "../core/prompt.factory"
5+
import { Query } from "../core/query"
6+
import { Neo4j } from "../core/services/db/neo4j"
7+
import { MiniLML6 } from "../core/services/embeddings/minilml6"
8+
import { Llama3_70B } from "../core/services/llm/llama3_70B"
9+
import { handleCommandResponse } from "../utils/handleCommandResponse"
1710

1811
export class AskCodeCommand implements ISlashCommand {
19-
public command = "rcc-askcode";
20-
public i18nParamsExample = "";
21-
public i18nDescription = "";
22-
public providesPreview = false;
12+
public command = "rcc-askcode"
13+
public i18nParamsExample = ""
14+
public i18nDescription = ""
15+
public providesPreview = false
2316

24-
/**
25-
* Processes the user's query and returns the answer.
26-
*
27-
* @param {IHttp} http - The HTTP object used for making requests.
28-
* @param {string} query - The user's query.
29-
* @returns {Promise<string | null>} A promise that resolves to the response to be given to the user or `null` if no answer or no reference is found.
30-
*/
31-
private async process(http: IHttp, query: string): Promise<string | null> {
32-
const db = new Neo4j(http);
33-
const llm = new Llama3_70B(http);
34-
const embeddingModel = new MiniLML6(http);
17+
/**
18+
* Processes the user's query and returns the answer.
19+
*
20+
* @param {IHttp} http - The HTTP object used for making requests.
21+
* @param {string} query - The user's query.
22+
* @returns {Promise<string | null>} A promise that resolves to the response to be given to the user or `null` if no answer or no reference is found.
23+
*/
24+
private async process(http: IHttp, query: string): Promise<string | null> {
25+
const db = new Neo4j(http)
26+
const llm = new Llama3_70B(http)
27+
const embeddingModel = new MiniLML6(http)
3528

36-
/**
37-
* ---------------------------------------------------------------------------------------------
38-
* STEP 1:
39-
* Extract the possible keywords from the user's query
40-
* ---------------------------------------------------------------------------------------------
41-
*/
42-
const keywords = await Query.getDBKeywordsFromQuery(llm, query);
43-
if (!keywords.length) return null;
29+
/**
30+
* ---------------------------------------------------------------------------------------------
31+
* STEP 1:
32+
* Extract the possible keywords from the user's query
33+
* ---------------------------------------------------------------------------------------------
34+
*/
35+
const keywords = await Query.getDBKeywordsFromQuery(llm, query)
36+
if (!keywords.length) return null
4437

45-
/**
46-
* ---------------------------------------------------------------------------------------------
47-
* STEP 2:
48-
* Query the database to find the nodes names of which are similar to what user has requested
49-
* ---------------------------------------------------------------------------------------------
50-
*/
51-
const results = await Query.getCodeNodesFromKeywords(
52-
db,
53-
embeddingModel,
54-
keywords
55-
);
56-
if (!results.length) return null;
38+
/**
39+
* ---------------------------------------------------------------------------------------------
40+
* STEP 2:
41+
* Query the database to find the nodes names of which are similar to what user has requested
42+
* ---------------------------------------------------------------------------------------------
43+
*/
44+
const results = await Query.getCodeNodesFromKeywords(db, embeddingModel, keywords)
45+
if (!results.length) return null
5746

58-
/**
59-
* ---------------------------------------------------------------------------------------------
60-
* STEP 3:
61-
* Generate the answer and diagram for the user's query given the nodes data
62-
* ---------------------------------------------------------------------------------------------
63-
*/
64-
const answer = await llm.ask(
65-
PromptFactory.makeAskCodePrompt(
66-
results.map((x) => x.code).join("\n\n"),
67-
query
68-
)
69-
);
70-
if (!answer) return null;
47+
/**
48+
* ---------------------------------------------------------------------------------------------
49+
* STEP 3:
50+
* Generate the answer and diagram for the user's query given the nodes data
51+
* ---------------------------------------------------------------------------------------------
52+
*/
53+
const answer = await llm.ask(
54+
PromptFactory.makeAskCodePrompt(results.map((x) => x.code).join("\n\n"), query)
55+
)
56+
if (!answer) return null
7157

72-
return answer;
73-
}
58+
return answer
59+
}
7460

75-
/**
76-
* Executes the AskCodeCommand.
77-
*
78-
* @param context - The SlashCommandContext object.
79-
* @param read - The IRead object.
80-
* @param modify - The IModify object.
81-
* @param http - The IHttp object.
82-
* @returns A Promise that resolves to void.
83-
*/
84-
public async executor(
85-
context: SlashCommandContext,
86-
read: IRead,
87-
modify: IModify,
88-
http: IHttp
89-
): Promise<void> {
90-
const query = context.getArguments().join(" ");
91-
if (!query) return;
61+
/**
62+
* Executes the AskCodeCommand.
63+
*
64+
* @param context - The SlashCommandContext object.
65+
* @param read - The IRead object.
66+
* @param modify - The IModify object.
67+
* @param http - The IHttp object.
68+
* @returns A Promise that resolves to void.
69+
*/
70+
public async executor(
71+
context: SlashCommandContext,
72+
read: IRead,
73+
modify: IModify,
74+
http: IHttp
75+
): Promise<void> {
76+
const query = context.getArguments().join(" ")
77+
if (!query) return
9278

93-
const sendEditedMessage = await handleCommandResponse(
94-
query,
95-
context.getSender(),
96-
context.getRoom(),
97-
modify,
98-
this.command
99-
);
79+
const sendEditedMessage = await handleCommandResponse(
80+
query,
81+
context.getSender(),
82+
context.getRoom(),
83+
modify,
84+
this.command
85+
)
10086

101-
const res = await this.process(http, query);
102-
if (res) {
103-
await sendEditedMessage(res);
104-
} else {
105-
await sendEditedMessage("❌ Unable to process your query");
106-
}
107-
}
87+
const res = await this.process(http, query)
88+
if (res) {
89+
await sendEditedMessage(res)
90+
} else {
91+
await sendEditedMessage("❌ Unable to process your query")
92+
}
93+
}
10894
}

0 commit comments

Comments
 (0)