-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
294 lines (272 loc) · 9.16 KB
/
Copy pathopenapi.yaml
File metadata and controls
294 lines (272 loc) · 9.16 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
openapi: 3.1.0
info:
title: llamacpp-server HTTP+SSE API
version: 1.0.0
description: |
HTTP+SSE API for the llamacpp-server. Provides model loading with progress
streaming and text generation with optional token-by-token streaming via
Server-Sent Events (SSE).
This API runs alongside the gRPC interface (defined in `api/proto/llmserver.proto`).
Both interfaces share the same inference engine and model state.
servers:
- url: http://localhost:8082
description: Default local server
paths:
/health:
get:
operationId: health
summary: Health check
description: Returns server health status. Use this to verify the server is running.
responses:
"200":
description: Server is healthy.
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: ok
/models/load:
post:
operationId: loadModel
summary: Load a model
description: |
Loads a GGUF model from the specified filesystem path. Returns an SSE
stream of progress events. The model is ready for inference after the
final `[DONE]` sentinel.
If the model is already loaded, the operation completes immediately.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/LoadModelRequest"
responses:
"200":
description: SSE stream of loading progress events.
content:
text/event-stream:
schema:
description: |
Each SSE `data:` line contains a JSON object with `progress` (0.0–1.0).
The stream ends with `data: [DONE]`.
On error, an `event: error` message is sent.
type: string
examples:
progress:
summary: Typical progress stream
value: |
data: {"progress":0.25}
data: {"progress":0.5}
data: {"progress":0.75}
data: {"progress":1}
data: [DONE]
error:
summary: Error during loading
value: |
data: {"progress":0.3}
event: error
data: "failed to load model: file not found"
"400":
description: Invalid request (missing path).
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/completions:
post:
operationId: completions
summary: Generate text completion
description: |
Generates text from a prompt using the loaded model. Supports both
streaming (SSE) and non-streaming modes.
**Streaming mode** (`"stream": true`): Returns an SSE stream where each
`data:` line contains a JSON object with the generated token. The stream
ends with `data: [DONE]`.
**Non-streaming mode** (`"stream": false`): Returns a single JSON response
with the complete generated text.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CompletionRequest"
responses:
"200":
description: |
Streaming: SSE stream of completion events.
Non-streaming: single JSON response.
content:
text/event-stream:
schema:
description: |
Each SSE `data:` line contains a JSON `CompletionResponse`.
The stream ends with `data: [DONE]`.
On error, an `event: error` message is sent.
type: string
examples:
streaming:
summary: Streaming token-by-token
value: |
data: {"message":"The","token":450,"tokens":1}
data: {"message":" capital","token":6421,"tokens":2}
data: {"message":" of","token":310,"tokens":3}
data: {"message":" France","token":4643,"tokens":4}
data: [DONE]
application/json:
schema:
$ref: "#/components/schemas/CompletionResponse"
examples:
non-streaming:
summary: Non-streaming full response
value:
message: "The capital of France is Paris."
token: 0
tokens: 0
"400":
description: Invalid request body.
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
"500":
description: Prediction failed.
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
components:
schemas:
LoadModelRequest:
type: object
required:
- path
properties:
path:
type: string
description: Filesystem path to the GGUF model file.
example: /models/SmolLM2-135M-Instruct-Q4_K_M.gguf
CompletionRequest:
type: object
required:
- model
- prompt
properties:
model:
type: string
description: Path of the loaded model (must match the path used in `/models/load`).
example: /models/SmolLM2-135M-Instruct-Q4_K_M.gguf
prompt:
type: string
description: Input text to generate from.
example: "<|im_start|>user\nWhat is the capital of France?<|im_end|>\n<|im_start|>assistant\n"
stream:
type: boolean
default: false
description: If true, tokens are streamed via SSE as they are generated.
max_tokens:
type: integer
default: 0
description: Maximum number of tokens to generate. 0 means no generation.
example: 100
temperature:
type: number
format: float
default: 0.0
description: |
Sampling temperature. 0.0 = greedy (deterministic argmax).
Higher values increase randomness.
example: 0.7
top_p:
type: number
format: float
default: 0.0
description: Nucleus sampling threshold. 0.0 or 1.0 = disabled.
example: 0.95
top_k:
type: integer
format: int32
default: 0
description: Top-k sampling. 0 = disabled.
example: 40
options:
$ref: "#/components/schemas/CompletionOptions"
CompletionOptions:
type: object
description: Advanced sampling and inference options. All fields are optional.
properties:
min_p:
type: number
format: float
description: Minimum probability threshold for sampling.
example: 0.05
min_tokens_to_keep:
type: integer
format: int32
description: Minimum number of tokens to keep during sampling.
repetition_penalty:
type: number
format: float
description: Penalty for repeated tokens. 1.0 = no penalty.
example: 1.1
length_penalty:
type: number
format: float
description: Length penalty factor.
diversity_penalty:
type: number
format: float
description: Diversity penalty factor.
no_repeat_ngram_size:
type: integer
format: int32
description: Prevent repeating n-grams of this size. 0 = disabled.
random_seed:
type: integer
format: int32
description: Random seed for reproducible sampling. -1 = random.
example: 42
max_kv_size:
type: integer
format: int32
description: Maximum KV cache size override.
prefill_step_size:
type: integer
format: int32
description: Prefill chunk size override.
kv_bits:
type: integer
format: int32
description: KV cache quantization bits.
kv_group_size:
type: integer
format: int32
description: KV cache quantization group size.
quantized_kv_start:
type: integer
format: int32
description: Layer index where quantized KV cache starts.
CompletionResponse:
type: object
properties:
message:
type: string
description: Generated text (one token in streaming mode, full text otherwise).
example: "The"
token:
type: integer
description: Token ID of the generated token.
example: 450
tokens:
type: integer
description: Running total of tokens generated so far.
example: 5
ErrorResponse:
type: object
properties:
error:
type: string
description: Human-readable error message.
example: "path is required"