Skip to content

Commit

Permalink
Addressing comments by @Henry and @spolu. Support for multi mentions …
Browse files Browse the repository at this point in the history
…in progress
  • Loading branch information
lasryaric committed Oct 5, 2023
1 parent 2588324 commit 7578520
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 66 deletions.
32 changes: 28 additions & 4 deletions connectors/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions connectors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dd-trace": "^3.16.0",
"eventsource-parser": "^1.0.0",
"express": "^4.18.2",
"fast-levenshtein": "^3.0.0",
"fp-ts": "^2.16.0",
"fs-extra": "^11.1.1",
"googleapis": "^118.0.0",
Expand All @@ -51,6 +52,7 @@
},
"devDependencies": {
"@types/eslint": "^8.21.3",
"@types/fast-levenshtein": "^0.0.2",
"@types/node": "^18.15.5",
"@types/p-queue": "^3.2.1",
"@typescript-eslint/eslint-plugin": "^5.56.0",
Expand Down
48 changes: 27 additions & 21 deletions connectors/src/connectors/slack/bot.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import levenshtein from "fast-levenshtein";

import {
AgentActionType,
AgentGenerationSuccessEvent,
AgentMessageType,
DustAPI,
RetrievalDocumentType,
} from "@connectors/lib/dust_api";
import { editDistance } from "@connectors/lib/edit_distance";
import {
Connector,
ModelId,
Expand Down Expand Up @@ -191,7 +192,7 @@ async function botAnswerMessage(
}
}
// Extract all ~mentions.
const mentionCandidates = message.match(/~(\S+)/g) || [];
const mentionCandidates = message.match(/~[a-zA-Z0-9_-]{1,20}/g) || [];

let mentions: { assistantName: string; assistantId: string }[] = [];
if (mentionCandidates.length > 0) {
Expand All @@ -201,31 +202,36 @@ async function botAnswerMessage(
}
const agentConfigurations = agentConfigurationsRes.value;
for (const mc of mentionCandidates) {
const scores: {
assistantId: string;
assistantName: string;
distance: number;
}[] = [];
let bestCandidate:
| {
assistantId: string;
assistantName: string;
distance: number;
}
| undefined = undefined;
for (const agentConfiguration of agentConfigurations) {
const distance = editDistance(
mc.slice(1).toLocaleLowerCase(),
const distance = levenshtein.get(
mc.slice(1).toLowerCase(),
agentConfiguration.name.toLowerCase()
);
scores.push({
assistantId: agentConfiguration.sId,
assistantName: agentConfiguration.name,
distance: distance,
});
if (bestCandidate === undefined || bestCandidate.distance > distance) {
bestCandidate = {
assistantId: agentConfiguration.sId,
assistantName: agentConfiguration.name,
distance: distance,
};
}
}
scores.sort((a, b) => {
return a.distance - b.distance;
});
const bestScore = scores[0];
if (bestScore) {

if (bestCandidate) {
mentions.push({
assistantId: bestScore.assistantId,
assistantName: bestScore.assistantName,
assistantId: bestCandidate.assistantId,
assistantName: bestCandidate.assistantName,
});
message = message.replace(
mc,
`:metion[${bestCandidate.assistantName}]{${bestCandidate.assistantId}}`
);
}
}
}
Expand Down
41 changes: 0 additions & 41 deletions connectors/src/lib/edit_distance.ts

This file was deleted.

0 comments on commit 7578520

Please sign in to comment.