forked from mhujer/ankiai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make one reqeust per word, a lot of other finessing.
- Loading branch information
Showing
8 changed files
with
170 additions
and
82 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { VocabularyExamples } from "../openai/typechat-response-schema"; | ||
|
||
export const mergeExamples = (examples: VocabularyExamples[]): VocabularyExamples[] => { | ||
const uniqueExamplesMap = new Map<number, string[]>(); | ||
|
||
// Iterate through examples and store unique example sentences by ID | ||
examples.forEach((example) => { | ||
if (uniqueExamplesMap.has(example.id)) { | ||
// If ID exists in the map, merge example sentences | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const existingSentences = uniqueExamplesMap.get(example.id)!; | ||
uniqueExamplesMap.set( | ||
example.id, | ||
[...existingSentences, ...example.exampleSentences.filter(sentence => | ||
!existingSentences.includes(sentence) | ||
)] | ||
); | ||
} else { | ||
// If ID doesn't exist, add a new entry to the map | ||
uniqueExamplesMap.set(example.id, example.exampleSentences); | ||
} | ||
}); | ||
|
||
// Convert uniqueExamplesMap back to an array of Example objects | ||
const uniqueExamples: VocabularyExamples[] = []; | ||
uniqueExamplesMap.forEach((exampleSentences, id) => { | ||
uniqueExamples.push({ id, exampleSentences }); | ||
}); | ||
|
||
return uniqueExamples; | ||
} |
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,3 @@ | ||
export const removeSentencesWithoutCharacter = (sentences: string[], mustContainCharacter: string): string[] => { | ||
return sentences.filter(str => str.includes(mustContainCharacter)); | ||
} |