@codefionn/llmleaf-client 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/client.d.ts +11 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +41 -1
- package/dist/client.js.map +1 -1
- package/dist/gen/llmleaf/v1/llmleaf_pb.d.ts +739 -0
- package/dist/gen/llmleaf/v1/llmleaf_pb.d.ts.map +1 -1
- package/dist/gen/llmleaf/v1/llmleaf_pb.js +132 -22
- package/dist/gen/llmleaf/v1/llmleaf_pb.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +215 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/wire.d.ts +12 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +451 -0
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +49 -0
- package/src/gen/llmleaf/v1/llmleaf_pb.ts +871 -22
- package/src/index.ts +24 -0
- package/src/types.ts +257 -0
- package/src/wire.ts +455 -0
package/src/client.ts
CHANGED
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
encodeChatRequest,
|
|
11
11
|
decodeChatResponse,
|
|
12
12
|
decodeChatCompletionChunk,
|
|
13
|
+
encodeResponsesRequest,
|
|
14
|
+
decodeResponsesResponse,
|
|
15
|
+
decodeResponsesStreamEvent,
|
|
16
|
+
isTerminalResponsesEvent,
|
|
13
17
|
encodeEmbeddingRequest,
|
|
14
18
|
decodeEmbeddingResponse,
|
|
15
19
|
encodeSpeechRequest,
|
|
@@ -24,6 +28,9 @@ import type {
|
|
|
24
28
|
ChatRequest,
|
|
25
29
|
ChatResponse,
|
|
26
30
|
ChatCompletionChunk,
|
|
31
|
+
ResponsesRequest,
|
|
32
|
+
ResponsesResponse,
|
|
33
|
+
ResponsesStreamEvent,
|
|
27
34
|
EmbeddingRequest,
|
|
28
35
|
EmbeddingResponse,
|
|
29
36
|
SpeechRequest,
|
|
@@ -188,6 +195,48 @@ export class LlmleafClient {
|
|
|
188
195
|
}
|
|
189
196
|
}
|
|
190
197
|
|
|
198
|
+
// -------------------------------------------------------------------------
|
|
199
|
+
// Responses (OpenAI Responses dialect)
|
|
200
|
+
// -------------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
/** POST /v1/responses (non-streaming). */
|
|
203
|
+
async responses(req: ResponsesRequest): Promise<ResponsesResponse> {
|
|
204
|
+
const body = encodeResponsesRequest(req, false);
|
|
205
|
+
const json = await this.sendJson(this.url("/v1/responses"), body);
|
|
206
|
+
return decodeResponsesResponse(json);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* POST /v1/responses with `stream:true`. Returns an async iterable of
|
|
211
|
+
* {@link ResponsesStreamEvent}. Unlike {@link chatStream} there is no `[DONE]`
|
|
212
|
+
* sentinel: the iterator stops after the terminal `response.completed` /
|
|
213
|
+
* `response.incomplete` / `response.failed` event (or when the connection closes).
|
|
214
|
+
* Event types the SDK doesn't recognise are skipped (the dialect grows by adding types).
|
|
215
|
+
*/
|
|
216
|
+
async *responsesStream(
|
|
217
|
+
req: ResponsesRequest,
|
|
218
|
+
): AsyncGenerator<ResponsesStreamEvent, void, unknown> {
|
|
219
|
+
const body = encodeResponsesRequest(req, true);
|
|
220
|
+
const res = await this.send(this.url("/v1/responses"), {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: this.headers({
|
|
223
|
+
"content-type": "application/json",
|
|
224
|
+
accept: "text/event-stream",
|
|
225
|
+
}),
|
|
226
|
+
body: JSON.stringify(body),
|
|
227
|
+
});
|
|
228
|
+
if (!res.ok) throw await apiErrorFromResponse(res);
|
|
229
|
+
if (!res.body) {
|
|
230
|
+
throw new ApiError(res.status, "streaming response had no body");
|
|
231
|
+
}
|
|
232
|
+
for await (const payload of parseSseData(res.body)) {
|
|
233
|
+
const event = decodeResponsesStreamEvent(JSON.parse(payload));
|
|
234
|
+
if (event === undefined) continue; // unrecognised event type — skip (SPEC.md)
|
|
235
|
+
yield event;
|
|
236
|
+
if (isTerminalResponsesEvent(event.type)) return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
191
240
|
// -------------------------------------------------------------------------
|
|
192
241
|
// Embeddings
|
|
193
242
|
// -------------------------------------------------------------------------
|