-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ef73a1
commit 73e1028
Showing
11 changed files
with
165 additions
and
134 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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
*.log | ||
yalc.lock | ||
|
||
.vitepress/cache | ||
|
||
.vercel/ | ||
.turbo/ | ||
.next/ | ||
|
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,2 +1,2 @@ | ||
export const DEFAULT_COPILOT_TEMPERATURE = 0.1 as const; | ||
export const DEFAULT_COPILOT_MAX_TOKENS = 64 as const; | ||
export const DEFAULT_COPILOT_TEMPERATURE = 0.5 as const; | ||
export const DEFAULT_COPILOT_MAX_TOKENS = 4096 as const; |
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
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
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
66 changes: 66 additions & 0 deletions
66
packages/monacopilot/src/classes/text-overlap-calculator.ts
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,66 @@ | ||
export class TextOverlapCalculator { | ||
public findOverlaps( | ||
completion: string, | ||
textBeforeCursor: string, | ||
textAfterCursor: string, | ||
): { | ||
startOverlapLength: number; | ||
maxOverlapLength: number; | ||
} { | ||
if (!completion) { | ||
return { | ||
startOverlapLength: 0, | ||
maxOverlapLength: 0, | ||
}; | ||
} | ||
|
||
const completionLength = completion.length; | ||
const beforeLength = textBeforeCursor.length; | ||
const afterLength = textAfterCursor.length; | ||
|
||
let prefixOverlapLength = 0; | ||
let suffixOverlapLength = 0; | ||
let startOverlapLength = 0; | ||
|
||
const maxBeforeOverlap = Math.min(completionLength, beforeLength); | ||
for (let i = 1; i <= maxBeforeOverlap; i++) { | ||
const completionStart = completion.substring(0, i); | ||
const textEnd = textBeforeCursor.slice(-i); | ||
if (completionStart === textEnd) { | ||
startOverlapLength = i; | ||
} | ||
} | ||
|
||
const maxAfterOverlap = Math.min(completionLength, afterLength); | ||
|
||
for (let i = 0; i < maxAfterOverlap; i++) { | ||
if (completion[i] !== textAfterCursor[i]) break; | ||
prefixOverlapLength++; | ||
} | ||
|
||
for (let i = 1; i <= maxAfterOverlap; i++) { | ||
if (completion.slice(-i) === textAfterCursor.slice(0, i)) { | ||
suffixOverlapLength = i; | ||
} | ||
} | ||
|
||
let maxOverlapLength = Math.max( | ||
prefixOverlapLength, | ||
suffixOverlapLength, | ||
); | ||
|
||
if (maxOverlapLength === 0) { | ||
for (let i = 1; i < completionLength; i++) { | ||
if (textAfterCursor.startsWith(completion.substring(i))) { | ||
maxOverlapLength = completionLength - i; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return { | ||
startOverlapLength, | ||
maxOverlapLength, | ||
}; | ||
} | ||
} |
Oops, something went wrong.