-
Notifications
You must be signed in to change notification settings - Fork 87
/
index.d.ts
119 lines (106 loc) · 2.74 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
declare module 'openai-api' {
export interface CompletionOpts {
engine: string;
prompt?: string;
maxTokens?: number;
temperature?: number;
topP?: number;
n?: number;
stream?: boolean;
logprobs?: number;
echo?: boolean;
stop?: string | string[];
presencePenalty?: number;
frequencyPenalty?: number;
bestOf?: number;
user?: string;
logitBias?: { [token: string]: number; };
}
export interface Completion {
data: {
id: string;
object: string;
created: number;
model: string;
choices: Choice[];
};
}
export interface Choice {
text: string;
index: number;
logprobs: any;
finish_reason: string;
}
export interface SearchOpts {
engine: string;
documents?: string[];
file?: string;
query: string;
maxRerank?: number;
returnMetadata?: boolean;
}
export interface Search {
data: Document[];
object: string;
}
export interface Document {
document: number;
object: string;
score: number;
metadata?: any;
}
export interface Embedding {
object: string;
data: EmbeddingData[];
model: string;
}
export interface EmbeddingData {
object: string;
index: number;
embedding: number[];
}
export interface ChatOpts {
model: string;
message: ChatMessage[];
max_tokens?: number;
temperature?: number;
top_p?: number;
n?: number;
stream?: boolean;
logprobs?: number;
echo?: boolean;
stop?: string | string[];
presence_penalty?: number;
frequency_penalty?: number;
user?: string;
logit_bias?: { [token: string]: number; };
}
export interface ChatResponse {
data: {
id: string;
object: string;
created: number;
model: string;
usage: { prompt_tokens: number, completion_tokens: number, total_tokens: number };
choices: ChatChoice[];
};
}
export interface ChatChoice {
message: ChatMessage[];
index: number;
logprobs: any;
finish_reason: string;
}
export interface ChatMessage {
role: string;
content: string;
}
class OpenAI {
constructor(api: string);
complete(opts: CompletionOpts): Promise<Completion>;
encode(str: string): number[];
search(opts: SearchOpts): Promise<Search>;
chat(opts: ChatOpts): Promise<ChatResponse>;
}
export default OpenAI;
}