Skip to content

Commit b13c1bc

Browse files
committed
Minor fixes
1 parent a99ab29 commit b13c1bc

File tree

8 files changed

+62
-7
lines changed

8 files changed

+62
-7
lines changed

ai-assistant/src/RocketChatterApp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { TranslateCommand } from "./commands/TranslateCommand";
2828
import { WhyUsedCommand } from "./commands/WhyUsedCommand";
2929
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations";
3030
import { IngestEndpoint } from "./endpoints/ingest";
31+
import { LLMEndpoint } from "./endpoints/llm";
3132
import { PurgeDBEndpoint } from "./endpoints/purgeDB";
3233
import { handleModalViewSubmit } from "./utils/handleModalViewSubmit";
3334

@@ -73,8 +74,8 @@ export class RocketChatterApp extends App {
7374
new IngestEndpoint(this),
7475
new PurgeDBEndpoint(this),
7576
new EstablishRelationsEndpoint(this),
77+
new LLMEndpoint(this),
7678
],
7779
});
78-
7980
}
8081
}

ai-assistant/src/commands/AskCommand.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
IHttp,
33
IModify,
4-
IRead
4+
IRead,
55
} from "@rocket.chat/apps-engine/definition/accessors";
66
import {
77
ISlashCommand,
@@ -57,7 +57,10 @@ export class AskCommand implements ISlashCommand {
5757
* ---------------------------------------------------------------------------------------------
5858
*/
5959
const answer = await llm.ask(
60-
PromptFactory.makeAskPrompt(JSON.stringify(results), query)
60+
PromptFactory.makeAskPrompt(
61+
results.map((x) => x.code).join("\n\n"),
62+
query
63+
)
6164
);
6265
console.log("ANSWER", answer);
6366
if (!answer) return null;

ai-assistant/src/commands/DiagramCommand.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export class DiagramCommand implements ISlashCommand {
5858
* ---------------------------------------------------------------------------------------------
5959
*/
6060
const diagram = await llm.ask(
61-
PromptFactory.makeDiagramPrompt(JSON.stringify(results), query)
61+
PromptFactory.makeDiagramPrompt(
62+
results.map((x) => x.code).join("\n\n"),
63+
query
64+
)
6265
);
6366
console.log(diagram);
6467
if (!diagram) return null;

ai-assistant/src/commands/TranslateCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class TranslateCommand implements ISlashCommand {
5050
*/
5151
const res = await llm.ask(
5252
PromptFactory.makeTranslatePrompt(
53-
JSON.stringify(codeNodes),
53+
codeNodes.map((x) => x.code).join("\n\n"),
5454
targetEntity,
5555
targetLanguage
5656
)

ai-assistant/src/commands/WhyUsedCommand.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export class WhyUsedCommand implements ISlashCommand {
6363
* ---------------------------------------------------------------------------------------------
6464
*/
6565
const result = await llm.ask(
66-
PromptFactory.makeWhyUsedPrompt(JSON.stringify(codeNodes), query)
66+
PromptFactory.makeWhyUsedPrompt(
67+
codeNodes.map((x) => x.code).join("\n\n"),
68+
query
69+
)
6770
);
6871
if (!result) return null;
6972

ai-assistant/src/core/prompt/prompt.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export class Prompt {
77
get messages() {
88
return this._messages;
99
}
10+
set messages(messages: PromptMessages) {
11+
this._messages = messages;
12+
}
1013

1114
pushSystem(content: string) {
1215
this._messages.push({ role: "system", content });

ai-assistant/src/endpoints/llm.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
IHttp,
3+
IModify,
4+
IPersistence,
5+
IRead,
6+
} from "@rocket.chat/apps-engine/definition/accessors";
7+
import {
8+
ApiEndpoint,
9+
IApiEndpointInfo,
10+
IApiRequest,
11+
IApiResponse,
12+
} from "@rocket.chat/apps-engine/definition/api";
13+
14+
export class LLMEndpoint extends ApiEndpoint {
15+
public path = "llm";
16+
17+
public async post(
18+
request: IApiRequest,
19+
endpoint: IApiEndpointInfo,
20+
read: IRead,
21+
modify: IModify,
22+
http: IHttp,
23+
persis: IPersistence
24+
): Promise<IApiResponse> {
25+
const url = `http://mistral-7b/v1/chat/completions`;
26+
const res = await http.post(url, {
27+
headers: {
28+
"Content-Type": "application/json",
29+
},
30+
data: {
31+
model: "mistral",
32+
temprature: 0,
33+
messages: request.content.messages,
34+
},
35+
});
36+
37+
return this.success(res);
38+
}
39+
}

ai-assistant/src/modals/suggestModal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ async function process(http: IHttp, query: string): Promise<string | null> {
7979
* ---------------------------------------------------------------------------------------------
8080
*/
8181
const answer = await llm.ask(
82-
PromptFactory.makeSuggestPrompt(JSON.stringify(codeNodes), query)
82+
PromptFactory.makeSuggestPrompt(
83+
codeNodes.map((x) => x.code).join("\n\n"),
84+
query
85+
)
8386
);
8487
if (!answer) return null;
8588

0 commit comments

Comments
 (0)