-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix--diagramming
- Loading branch information
Showing
68 changed files
with
3,970 additions
and
4,403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"printWidth": 110, | ||
"tabWidth": 3, | ||
"useTabs": false, | ||
"semi": false, | ||
"singleQuote": false, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"arrowParens": "always", | ||
"requirePragma": false, | ||
"insertPragma": false, | ||
"proseWrap": "always", | ||
"bracketSameLine": false, | ||
"endOfLine": "lf" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
{ | ||
"scripts": { | ||
"dev": "clear && tsx src/test.ts" | ||
"dev": "clear && tsx src/test.ts", | ||
"pretty": "prettier --config .prettierrc --write ./src/*" | ||
}, | ||
"devDependencies": { | ||
"@rocket.chat/apps-cli": "^1.11.1", | ||
"@rocket.chat/apps-engine": "^1.19.0", | ||
"@types/node": "14.14.6", | ||
"esbuild": "^0.19.4", | ||
"prettier": "^3.3.3", | ||
"tslint": "^5.10.0", | ||
"tsx": "^4.17.0", | ||
"typescript": "^4.0.5" | ||
} | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,70 @@ | ||
import { | ||
IAppAccessors, | ||
IConfigurationExtend, | ||
IHttp, | ||
ILogger, | ||
IModify, | ||
IPersistence, | ||
IRead, | ||
} from "@rocket.chat/apps-engine/definition/accessors"; | ||
import { App } from "@rocket.chat/apps-engine/definition/App"; | ||
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata"; | ||
IAppAccessors, | ||
IConfigurationExtend, | ||
IHttp, | ||
ILogger, | ||
IModify, | ||
IPersistence, | ||
IRead, | ||
} from "@rocket.chat/apps-engine/definition/accessors" | ||
import { App } from "@rocket.chat/apps-engine/definition/App" | ||
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata" | ||
|
||
import { | ||
ApiSecurity, | ||
ApiVisibility, | ||
} from "@rocket.chat/apps-engine/definition/api"; | ||
import { UIKitViewSubmitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit"; | ||
import { AskCodeCommand } from "./commands/AskCodeCommand"; | ||
import { AskDocsCommand } from "./commands/AskDocsCommand"; | ||
import { DiagramCommand } from "./commands/DiagramCommand"; | ||
import { DocumentCommand } from "./commands/DocumentCommand"; | ||
import { FindSimilarCommand } from "./commands/FindSimilar"; | ||
import { HelpCommand } from "./commands/HelpCommand"; | ||
import { ImportanceCommand } from "./commands/ImportanceCommand"; | ||
import { ImproveCommand } from "./commands/ImproveCommand"; | ||
import { TestcasesCommand } from "./commands/TestcasesCommand"; | ||
import { TranslateCommand } from "./commands/TranslateCommand"; | ||
import { WhyUsedCommand } from "./commands/WhyUsedCommand"; | ||
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations"; | ||
import { IngestEndpoint } from "./endpoints/ingest"; | ||
import { PurgeDBEndpoint } from "./endpoints/purgeDB"; | ||
import { handleModalViewSubmit } from "./utils/handleModalViewSubmit"; | ||
import { ApiSecurity, ApiVisibility } from "@rocket.chat/apps-engine/definition/api" | ||
import { UIKitViewSubmitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit" | ||
import { AskCodeCommand } from "./commands/AskCodeCommand" | ||
import { AskDocsCommand } from "./commands/AskDocsCommand" | ||
import { DiagramCommand } from "./commands/DiagramCommand" | ||
import { DocumentCommand } from "./commands/DocumentCommand" | ||
import { FindSimilarCommand } from "./commands/FindSimilar" | ||
import { HelpCommand } from "./commands/HelpCommand" | ||
import { ImportanceCommand } from "./commands/ImportanceCommand" | ||
import { ImproveCommand } from "./commands/ImproveCommand" | ||
import { TestcasesCommand } from "./commands/TestcasesCommand" | ||
import { TranslateCommand } from "./commands/TranslateCommand" | ||
import { WhyUsedCommand } from "./commands/WhyUsedCommand" | ||
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations" | ||
import { IngestEndpoint } from "./endpoints/ingest" | ||
import { PurgeDBEndpoint } from "./endpoints/purgeDB" | ||
import { handleModalViewSubmit } from "./utils/handleModalViewSubmit" | ||
|
||
export class RocketChatterApp extends App { | ||
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { | ||
super(info, logger, accessors); | ||
} | ||
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { | ||
super(info, logger, accessors) | ||
} | ||
|
||
public async executeViewSubmitHandler( | ||
context: UIKitViewSubmitInteractionContext, | ||
read: IRead, | ||
http: IHttp, | ||
persistence: IPersistence, | ||
modify: IModify | ||
) { | ||
handleModalViewSubmit(context, read, http, modify); | ||
} | ||
public async executeViewSubmitHandler( | ||
context: UIKitViewSubmitInteractionContext, | ||
read: IRead, | ||
http: IHttp, | ||
persistence: IPersistence, | ||
modify: IModify | ||
) { | ||
handleModalViewSubmit(context, read, http, modify) | ||
} | ||
|
||
public async extendConfiguration(configuration: IConfigurationExtend) { | ||
configuration.slashCommands.provideSlashCommand(new HelpCommand()); | ||
public async extendConfiguration(configuration: IConfigurationExtend) { | ||
configuration.slashCommands.provideSlashCommand(new HelpCommand()) | ||
|
||
configuration.slashCommands.provideSlashCommand(new AskCodeCommand()); | ||
configuration.slashCommands.provideSlashCommand(new AskDocsCommand()); | ||
configuration.slashCommands.provideSlashCommand(new DiagramCommand()); | ||
configuration.slashCommands.provideSlashCommand(new DocumentCommand()); | ||
configuration.slashCommands.provideSlashCommand( | ||
new FindSimilarCommand() | ||
); | ||
configuration.slashCommands.provideSlashCommand( | ||
new ImportanceCommand() | ||
); | ||
configuration.slashCommands.provideSlashCommand(new ImproveCommand()); | ||
configuration.slashCommands.provideSlashCommand(new TestcasesCommand()); | ||
configuration.slashCommands.provideSlashCommand(new TranslateCommand()); | ||
configuration.slashCommands.provideSlashCommand(new WhyUsedCommand()); | ||
configuration.slashCommands.provideSlashCommand(new AskCodeCommand()) | ||
configuration.slashCommands.provideSlashCommand(new AskDocsCommand()) | ||
configuration.slashCommands.provideSlashCommand(new DiagramCommand()) | ||
configuration.slashCommands.provideSlashCommand(new DocumentCommand()) | ||
configuration.slashCommands.provideSlashCommand(new FindSimilarCommand()) | ||
configuration.slashCommands.provideSlashCommand(new ImportanceCommand()) | ||
configuration.slashCommands.provideSlashCommand(new ImproveCommand()) | ||
configuration.slashCommands.provideSlashCommand(new TestcasesCommand()) | ||
configuration.slashCommands.provideSlashCommand(new TranslateCommand()) | ||
configuration.slashCommands.provideSlashCommand(new WhyUsedCommand()) | ||
|
||
await configuration.api.provideApi({ | ||
visibility: ApiVisibility.PUBLIC, | ||
security: ApiSecurity.UNSECURE, | ||
endpoints: [ | ||
new IngestEndpoint(this), | ||
new PurgeDBEndpoint(this), | ||
new EstablishRelationsEndpoint(this), | ||
], | ||
}); | ||
} | ||
await configuration.api.provideApi({ | ||
visibility: ApiVisibility.PUBLIC, | ||
security: ApiSecurity.UNSECURE, | ||
endpoints: [ | ||
new IngestEndpoint(this), | ||
new PurgeDBEndpoint(this), | ||
new EstablishRelationsEndpoint(this), | ||
], | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,94 @@ | ||
import { | ||
IHttp, | ||
IModify, | ||
IRead, | ||
} from "@rocket.chat/apps-engine/definition/accessors"; | ||
import { | ||
ISlashCommand, | ||
SlashCommandContext, | ||
} from "@rocket.chat/apps-engine/definition/slashcommands"; | ||
import { IHttp, IModify, IRead } from "@rocket.chat/apps-engine/definition/accessors" | ||
import { ISlashCommand, SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands" | ||
|
||
import { PromptFactory } from "../core/prompt.factory"; | ||
import { Query } from "../core/query"; | ||
import { Neo4j } from "../core/services/db/neo4j"; | ||
import { MiniLML6 } from "../core/services/embeddings/minilml6"; | ||
import { Llama3_70B } from "../core/services/llm/llama3_70B"; | ||
import { handleCommandResponse } from "../utils/handleCommandResponse"; | ||
import { PromptFactory } from "../core/prompt.factory" | ||
import { Query } from "../core/query" | ||
import { Neo4j } from "../core/services/db/neo4j" | ||
import { MiniLML6 } from "../core/services/embeddings/minilml6" | ||
import { Llama3_70B } from "../core/services/llm/llama3_70B" | ||
import { handleCommandResponse } from "../utils/handleCommandResponse" | ||
|
||
export class AskCodeCommand implements ISlashCommand { | ||
public command = "rcc-askcode"; | ||
public i18nParamsExample = ""; | ||
public i18nDescription = ""; | ||
public providesPreview = false; | ||
public command = "rcc-askcode" | ||
public i18nParamsExample = "" | ||
public i18nDescription = "" | ||
public providesPreview = false | ||
|
||
/** | ||
* Processes the user's query and returns the answer. | ||
* | ||
* @param {IHttp} http - The HTTP object used for making requests. | ||
* @param {string} query - The user's query. | ||
* @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. | ||
*/ | ||
private async process(http: IHttp, query: string): Promise<string | null> { | ||
const db = new Neo4j(http); | ||
const llm = new Llama3_70B(http); | ||
const embeddingModel = new MiniLML6(http); | ||
/** | ||
* Processes the user's query and returns the answer. | ||
* | ||
* @param {IHttp} http - The HTTP object used for making requests. | ||
* @param {string} query - The user's query. | ||
* @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. | ||
*/ | ||
private async process(http: IHttp, query: string): Promise<string | null> { | ||
const db = new Neo4j(http) | ||
const llm = new Llama3_70B(http) | ||
const embeddingModel = new MiniLML6(http) | ||
|
||
/** | ||
* --------------------------------------------------------------------------------------------- | ||
* STEP 1: | ||
* Extract the possible keywords from the user's query | ||
* --------------------------------------------------------------------------------------------- | ||
*/ | ||
const keywords = await Query.getDBKeywordsFromQuery(llm, query); | ||
if (!keywords.length) return null; | ||
/** | ||
* --------------------------------------------------------------------------------------------- | ||
* STEP 1: | ||
* Extract the possible keywords from the user's query | ||
* --------------------------------------------------------------------------------------------- | ||
*/ | ||
const keywords = await Query.getDBKeywordsFromQuery(llm, query) | ||
if (!keywords.length) return null | ||
|
||
/** | ||
* --------------------------------------------------------------------------------------------- | ||
* STEP 2: | ||
* Query the database to find the nodes names of which are similar to what user has requested | ||
* --------------------------------------------------------------------------------------------- | ||
*/ | ||
const results = await Query.getCodeNodesFromKeywords( | ||
db, | ||
embeddingModel, | ||
keywords | ||
); | ||
if (!results.length) return null; | ||
/** | ||
* --------------------------------------------------------------------------------------------- | ||
* STEP 2: | ||
* Query the database to find the nodes names of which are similar to what user has requested | ||
* --------------------------------------------------------------------------------------------- | ||
*/ | ||
const results = await Query.getCodeNodesFromKeywords(db, embeddingModel, keywords) | ||
if (!results.length) return null | ||
|
||
/** | ||
* --------------------------------------------------------------------------------------------- | ||
* STEP 3: | ||
* Generate the answer and diagram for the user's query given the nodes data | ||
* --------------------------------------------------------------------------------------------- | ||
*/ | ||
const answer = await llm.ask( | ||
PromptFactory.makeAskCodePrompt( | ||
results.map((x) => x.code).join("\n\n"), | ||
query | ||
) | ||
); | ||
if (!answer) return null; | ||
/** | ||
* --------------------------------------------------------------------------------------------- | ||
* STEP 3: | ||
* Generate the answer and diagram for the user's query given the nodes data | ||
* --------------------------------------------------------------------------------------------- | ||
*/ | ||
const answer = await llm.ask( | ||
PromptFactory.makeAskCodePrompt(results.map((x) => x.code).join("\n\n"), query) | ||
) | ||
if (!answer) return null | ||
|
||
return answer; | ||
} | ||
return answer | ||
} | ||
|
||
/** | ||
* Executes the AskCodeCommand. | ||
* | ||
* @param context - The SlashCommandContext object. | ||
* @param read - The IRead object. | ||
* @param modify - The IModify object. | ||
* @param http - The IHttp object. | ||
* @returns A Promise that resolves to void. | ||
*/ | ||
public async executor( | ||
context: SlashCommandContext, | ||
read: IRead, | ||
modify: IModify, | ||
http: IHttp | ||
): Promise<void> { | ||
const query = context.getArguments().join(" "); | ||
if (!query) return; | ||
/** | ||
* Executes the AskCodeCommand. | ||
* | ||
* @param context - The SlashCommandContext object. | ||
* @param read - The IRead object. | ||
* @param modify - The IModify object. | ||
* @param http - The IHttp object. | ||
* @returns A Promise that resolves to void. | ||
*/ | ||
public async executor( | ||
context: SlashCommandContext, | ||
read: IRead, | ||
modify: IModify, | ||
http: IHttp | ||
): Promise<void> { | ||
const query = context.getArguments().join(" ") | ||
if (!query) return | ||
|
||
const sendEditedMessage = await handleCommandResponse( | ||
query, | ||
context.getSender(), | ||
context.getRoom(), | ||
modify, | ||
this.command | ||
); | ||
const sendEditedMessage = await handleCommandResponse( | ||
query, | ||
context.getSender(), | ||
context.getRoom(), | ||
modify, | ||
this.command | ||
) | ||
|
||
const res = await this.process(http, query); | ||
if (res) { | ||
await sendEditedMessage(res); | ||
} else { | ||
await sendEditedMessage("❌ Unable to process your query"); | ||
} | ||
} | ||
const res = await this.process(http, query) | ||
if (res) { | ||
await sendEditedMessage(res) | ||
} else { | ||
await sendEditedMessage("❌ Unable to process your query") | ||
} | ||
} | ||
} |
Oops, something went wrong.