-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.d.ts
69 lines (61 loc) · 1.68 KB
/
global.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Define the interface for the detector, translator and summarizer based on the API documentation.
interface Detector {
detect: (
text: string,
) => Promise<Array<{ detectedLanguage: string; confidence: number }>>;
}
interface Translator {
translate: (text: string) => Promise<string>;
}
interface Summarizer {
summarize: (text: string, options?: { context?: string }) => Promise<string>;
addEventListener: (
type: "downloadprogress",
listener: (e: { loaded: number; total: number }) => void,
) => void;
ready?: Promise<void>;
}
// DEFINE TranslationAPI INTERFACE IF NEEDED
interface TranslationAPI {
createDetector: () => Promise<Detector>;
createTranslator: (options: {
sourceLanguage: string;
targetLanguage: string;
}) => Promise<Translator>;
}
// INTERFACE FOR LANGUAGE DETECTOR
interface AILanguageDetector {
capabilities: () => Promise<{ capabilities: string }>;
create: (options?: {
monitor?: (m: EventTarget) => void;
}) => Promise<Detector & { ready?: Promise<void> }>;
}
// INTERFACE FOR AI TRANSLATOR
interface AITranslator {
translator?: {
create: (options: {
sourceLanguage: string;
targetLanguage: string;
}) => Promise<Translator>;
};
languageDetector?: AILanguageDetector;
summarizer?: AISummarizer;
}
// INTERFACE FOR SUMMARIZER
interface AISummarizer {
capabilities: () => Promise<{ available: string }>;
create: (options: {
sharedContext: string;
type: string;
format: string;
length: string;
}) => Promise<Summarizer>;
}
// INLCUDE AI PROPERTY IN GLOBAL WINDOW INTERFACE
declare global {
interface Window {
ai?: AITranslator;
}
}
// MAKES THE FILE TO BE TREATED LIKE A MODULE
export {};