firefox + llama.cpp == very good prose.
1/**
2 * Types adapted from llama.cpp upstream:
3 * https://github.com/ggml-org/llama.cpp/blob/master/tools/server/webui/src/lib/types/api.d.ts
4 */
5
6export interface ApiChatMessageContentPart {
7 type: string;
8 text?: string;
9 image_url?: {
10 url: string;
11 };
12 input_audio?: {
13 data: string;
14 format: "wav" | "mp3";
15 };
16}
17
18export interface ApiChatCompletionToolFunction {
19 name: string;
20 description?: string;
21 parameters: Record<string, unknown>;
22}
23
24export interface ApiChatCompletionTool {
25 type: "function";
26 function: ApiChatCompletionToolFunction;
27}
28
29export interface ApiChatCompletionToolCallFunctionDelta {
30 name?: string;
31 arguments?: string;
32}
33
34export interface ApiChatCompletionToolCallDelta {
35 index?: number;
36 id?: string;
37 type?: string;
38 function?: ApiChatCompletionToolCallFunctionDelta;
39}
40
41export type ChatRole = "system" | "user" | "assistant" | "tool";
42
43export interface ApiChatCompletionRequest {
44 messages: Array<{
45 role: ChatRole;
46 content: string | ApiChatMessageContentPart[];
47 reasoning_content?: string;
48 tool_calls?: ApiChatCompletionToolCallDelta[];
49 tool_call_id?: string;
50 }>;
51 stream?: boolean;
52 stream_options?: { include_usage: boolean };
53 model?: string;
54 return_progress?: boolean;
55 tools?: ApiChatCompletionTool[];
56 /** Reasoning parameters */
57 reasoning_format?: string;
58 /** Generation parameters */
59 temperature?: number;
60 max_tokens?: number;
61 /** Sampling parameters */
62 dynatemp_range?: number;
63 dynatemp_exponent?: number;
64 top_k?: number;
65 top_p?: number;
66 min_p?: number;
67 xtc_probability?: number;
68 xtc_threshold?: number;
69 typ_p?: number;
70 /** Penalty parameters */
71 repeat_last_n?: number;
72 repeat_penalty?: number;
73 presence_penalty?: number;
74 frequency_penalty?: number;
75 dry_multiplier?: number;
76 dry_base?: number;
77 dry_allowed_length?: number;
78 dry_penalty_last_n?: number;
79 /** Sampler configuration */
80 samplers?: string[];
81 backend_sampling?: boolean;
82 /** Custom parameters (JSON string) */
83 custom?: Record<string, unknown>;
84 timings_per_token?: boolean;
85}
86
87export interface ApiChatCompletionResponse {
88 model?: string;
89 choices: Array<{
90 model?: string;
91 metadata?: { model?: string };
92 message: {
93 content: string;
94 reasoning_content?: string;
95 model?: string;
96 tool_calls?: Array<ApiChatCompletionToolCallDelta & {
97 function?: ApiChatCompletionToolCallFunctionDelta & { arguments?: string };
98 }>;
99 };
100 finish_reason?: string | null;
101 }>;
102}
103
104export interface ApiChatCompletionStreamChunk {
105 object?: string;
106 model?: string;
107 choices: Array<{
108 model?: string;
109 metadata?: { model?: string };
110 delta: {
111 content?: string;
112 reasoning_content?: string;
113 model?: string;
114 tool_calls?: ApiChatCompletionToolCallDelta[];
115 };
116 finish_reason?: string | null;
117 }>;
118 usage?: {
119 prompt_tokens: number;
120 completion_tokens: number;
121 total_tokens: number;
122 };
123}
124
125export interface ApiHealthResponse {
126 status: "ok";
127}
128
129export interface ApiErrorResponse {
130 error:
131 | {
132 code: number;
133 message: string;
134 type: "exceed_context_size_error";
135 n_prompt_tokens: number;
136 n_ctx: number;
137 }
138 | {
139 code: number;
140 message: string;
141 type?: string;
142 };
143}