feat(input): upgrade graph personalization, english morphology detection, and atomic SendInput replacement
This commit is contained in:
parent
52eef21bab
commit
cd4a452148
21 changed files with 1098 additions and 110 deletions
|
|
@ -43,7 +43,7 @@ import {
|
|||
type SuggestionStep
|
||||
} from '@d3ro/core/input-intelligence'
|
||||
import { renderRawChatPrompt, rawChatStopSequences } from '@d3ro/core/chat-template'
|
||||
import { buildQueryTerms, splitSentences } from '@d3ro/core/personal-graph'
|
||||
import { buildQueryTerms, scoreCandidatePersonalization, splitSentences } from '@d3ro/core/personal-graph'
|
||||
import { copiesContext } from '@d3ro/core/suggestion-confidence'
|
||||
import { splitFirstWord } from '@d3ro/core/suggestion-text'
|
||||
import { predictPersonalContinuation } from '@d3ro/core/personal-ngram'
|
||||
|
|
@ -1028,14 +1028,22 @@ export class SuggestionService extends EventEmitter {
|
|||
|
||||
private _collectMemoryHints(prefix: string, appName: string | null): LocalMemoryContext {
|
||||
const telemetry = getInputTelemetryService()
|
||||
const graphContext = getPersonalGraphService().retrieveContext(prefix, 4, { appName })
|
||||
const recentWrites = telemetry
|
||||
.listRecentWrites({
|
||||
windowHandle: this._lastContext?.windowHandle ?? null,
|
||||
appName,
|
||||
windowTitle: this._lastContext?.windowTitle ?? null
|
||||
})
|
||||
.map((entry) => entry.text)
|
||||
const graphContext = getPersonalGraphService().retrieveContext(prefix, 4, { appName, recentWrites })
|
||||
const phrases = telemetry.listPhrases(120)
|
||||
// 지금 글과 용어가 겹치는 문구만 — 문맥과 무관한 "자주 쓰는 말" 은 프롬프트를 흐린다.
|
||||
const writing = analyzeWritingContext(prefix)
|
||||
const lastRecentWrite = recentWrites.length > 0 ? recentWrites[recentWrites.length - 1] ?? '' : ''
|
||||
const relevanceTerms = new Set(
|
||||
buildQueryTerms([
|
||||
{ text: writing.currentSentence, weight: 2 },
|
||||
{ text: writing.lastSentence, weight: 1 }
|
||||
{ text: writing.lastSentence || lastRecentWrite, weight: 1 }
|
||||
]).keys()
|
||||
)
|
||||
const phraseHints = selectPhraseHints(phrases, prefix, 5, { appName, relevanceTerms })
|
||||
|
|
@ -1759,6 +1767,32 @@ export class SuggestionService extends EventEmitter {
|
|||
if (token !== this._generationToken || this._isDuplicateCandidate(candidate.text)) return false
|
||||
|
||||
this._candidates.push({ ...candidate, rank: this._candidates.length })
|
||||
if (this._activeIndex === 0 && this._candidates.length >= 2) {
|
||||
const personalContext = {
|
||||
prefix,
|
||||
continuationHints: memory.continuationHints,
|
||||
followUpHints: memory.followUpHints,
|
||||
relatedHints: memory.relatedHints,
|
||||
phraseHints: memory.phraseHints
|
||||
}
|
||||
const newScore = scoreCandidatePersonalization(candidate.text, personalContext)
|
||||
if (newScore >= 1.5) {
|
||||
const personalItems = this._candidates.filter((item) => item.source === 'personal')
|
||||
const modelItems = this._candidates
|
||||
.filter((item) => item.source !== 'personal')
|
||||
.map((item, idx) => ({
|
||||
item,
|
||||
idx,
|
||||
score: scoreCandidatePersonalization(item.text, personalContext)
|
||||
}))
|
||||
.sort((a, b) => (Math.abs(b.score - a.score) >= 0.8 ? b.score - a.score : a.idx - b.idx))
|
||||
.map((entry) => entry.item)
|
||||
this._candidates = [...personalItems, ...modelItems].map((item, index) => ({
|
||||
...item,
|
||||
rank: index
|
||||
}))
|
||||
}
|
||||
}
|
||||
logger.debug(`제안 후보 추가 ${this._candidates.length}/${SUGGESTION_DEFAULTS.maxCandidatesTotal}`)
|
||||
this._armVisibleTtl()
|
||||
this.emit('updated', this.getState())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue