forked from pollinations/pollinations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
139 lines (130 loc) · 3.93 KB
/
types.ts
File metadata and controls
139 lines (130 loc) · 3.93 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Shared types for the text generation service.
*/
/** OpenAI-style chat message. */
export interface ChatMessage {
role: string;
content?: string | unknown[] | null;
tool_call_id?: string;
name?: string;
tool_calls?: unknown[];
function_call?: unknown;
reasoning_content?: unknown;
audio?: unknown;
[key: string]: unknown;
}
/** Options bag threaded through transforms and generation functions. */
export interface TransformOptions {
model?: string;
modelDef?: unknown;
modelConfig?: Record<string, unknown>;
requestedModel?: string;
stream?: boolean;
temperature?: number;
top_p?: number;
presence_penalty?: number;
frequency_penalty?: number;
repetition_penalty?: number;
seed?: number;
max_tokens?: number;
max_completion_tokens?: number;
response_format?: { type: string; [key: string]: unknown };
tools?: unknown[];
tool_choice?: unknown;
additionalHeaders?: Record<string, string>;
userApiKey?: string;
jsonMode?: boolean;
voice?: string;
reasoning_effort?: string;
thinking_budget?: number;
modalities?: string[];
audio?: Record<string, unknown>;
stream_options?: Record<string, unknown>;
isPrivate?: boolean;
referrer?: string;
[key: string]: unknown;
}
/** Result returned by transform functions. */
export interface TransformResult {
messages: ChatMessage[];
options: TransformOptions;
}
/** A transform function that takes messages and options, returns a TransformResult. */
export type TransformFn = (
messages: ChatMessage[],
options: TransformOptions,
) => TransformResult | Promise<TransformResult>;
/** OpenAI-style chat completion choice. */
export interface CompletionChoice {
message?: Record<string, unknown>;
delta?: Record<string, unknown>;
finish_reason?: string | null;
index?: number;
[key: string]: unknown;
}
/** OpenAI-style chat completion response. */
export interface ChatCompletion {
id?: string;
object?: string;
created?: number;
model?: string;
choices?: CompletionChoice[];
usage?: Record<string, number>;
citations?: string[];
error?: string | { message?: string; status?: number; details?: unknown };
stream?: boolean;
responseStream?: AsyncIterable<unknown> | NodeJS.ReadableStream | null;
requestData?: unknown;
[key: string]: unknown;
}
/** Error with optional HTTP status, details, and model info. */
export interface ServiceError extends Error {
status?: number;
code?: number | string;
details?: unknown;
model?: string;
provider?: string;
originalProvider?: string;
response?: { data?: unknown };
}
/** Request data extracted from incoming HTTP requests. */
export interface RequestData {
messages: ChatMessage[];
model?: string;
temperature?: number;
top_p?: number;
presence_penalty?: number;
frequency_penalty?: number;
repetition_penalty?: number;
seed?: number;
stream?: boolean;
isPrivate?: boolean;
referrer?: string;
voice?: string;
jsonMode?: boolean;
tools?: unknown[];
tool_choice?: unknown;
modalities?: string[];
audio?: Record<string, unknown>;
reasoning_effort?: string;
thinking_budget?: number;
response_format?: { type: string; [key: string]: unknown };
max_tokens?: number;
max_completion_tokens?: number;
stop?: unknown;
stream_options?: Record<string, unknown>;
logprobs?: unknown;
top_logprobs?: unknown;
logit_bias?: unknown;
user?: unknown;
[key: string]: unknown;
}
/** Configuration for the generic OpenAI client. */
export interface OpenAIClientConfig {
endpoint: string | ((model: string, options: TransformOptions) => string);
authHeaderName?: string;
authHeaderValue: () => string;
defaultOptions?: Record<string, unknown>;
formatResponse?: ((...args: unknown[]) => unknown) | null;
additionalHeaders?: Record<string, string>;
}