@@ -27,11 +27,33 @@ import LlamaStackClient from 'llama-stack-client';
2727
2828const client = new LlamaStackClient ();
2929
30- const healthInfo = await client .inspect . health ( );
30+ const model = await client .models . register ({ model_id : ' model_id ' } );
3131
32- console .log (healthInfo . status );
32+ console .log (model . identifier );
3333```
3434
35+ ## Streaming responses
36+
37+ We provide support for streaming responses using Server Sent Events (SSE).
38+
39+ ``` ts
40+ import LlamaStackClient from ' llama-stack-client' ;
41+
42+ const client = new LlamaStackClient ();
43+
44+ const stream = await client .chat .completions .create ({
45+ messages: [{ content: ' string' , role: ' user' }],
46+ model: ' model' ,
47+ stream: true ,
48+ });
49+ for await (const chatCompletionChunk of stream ) {
50+ console .log (chatCompletionChunk );
51+ }
52+ ```
53+
54+ If you need to cancel a stream, you can ` break ` from the loop
55+ or call ` stream.controller.abort() ` .
56+
3557### Request & Response types
3658
3759This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
@@ -42,7 +64,13 @@ import LlamaStackClient from 'llama-stack-client';
4264
4365const client = new LlamaStackClient ();
4466
45- const healthInfo: LlamaStackClient .HealthInfo = await client .inspect .health ();
67+ const params: LlamaStackClient .Chat .CompletionCreateParams = {
68+ messages: [{ content: ' string' , role: ' user' }],
69+ model: ' model' ,
70+ };
71+ const completion: LlamaStackClient .Chat .CompletionCreateResponse = await client .chat .completions .create (
72+ params ,
73+ );
4674```
4775
4876Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -85,15 +113,17 @@ a subclass of `APIError` will be thrown:
85113
86114<!-- prettier-ignore -->
87115``` ts
88- const healthInfo = await client .inspect .health ().catch (async (err ) => {
89- if (err instanceof LlamaStackClient .APIError ) {
90- console .log (err .status ); // 400
91- console .log (err .name ); // BadRequestError
92- console .log (err .headers ); // {server: 'nginx', ...}
93- } else {
94- throw err ;
95- }
96- });
116+ const completion = await client .chat .completions
117+ .create ({ messages: [{ content: ' string' , role: ' user' }], model: ' model' })
118+ .catch (async (err ) => {
119+ if (err instanceof LlamaStackClient .APIError ) {
120+ console .log (err .status ); // 400
121+ console .log (err .name ); // BadRequestError
122+ console .log (err .headers ); // {server: 'nginx', ...}
123+ } else {
124+ throw err ;
125+ }
126+ });
97127```
98128
99129Error codes are as follows:
@@ -125,7 +155,7 @@ const client = new LlamaStackClient({
125155});
126156
127157// Or, configure per-request:
128- await client .inspect . health ( {
158+ await client .chat . completions . create ({ messages : [{ content : ' string ' , role : ' user ' }], model : ' model ' }, {
129159 maxRetries: 5 ,
130160});
131161```
@@ -142,7 +172,7 @@ const client = new LlamaStackClient({
142172});
143173
144174// Override per-request:
145- await client .inspect . health ( {
175+ await client .chat . completions . create ({ messages: [{ content: ' string ' , role: ' user ' }], model: ' model ' }, {
146176 timeout: 5 * 1000 ,
147177});
148178```
@@ -163,13 +193,17 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
163193``` ts
164194const client = new LlamaStackClient ();
165195
166- const response = await client .inspect .health ().asResponse ();
196+ const response = await client .chat .completions
197+ .create ({ messages: [{ content: ' string' , role: ' user' }], model: ' model' })
198+ .asResponse ();
167199console .log (response .headers .get (' X-My-Header' ));
168200console .log (response .statusText ); // access the underlying Response object
169201
170- const { data : healthInfo, response : raw } = await client .inspect .health ().withResponse ();
202+ const { data : completion, response : raw } = await client .chat .completions
203+ .create ({ messages: [{ content: ' string' , role: ' user' }], model: ' model' })
204+ .withResponse ();
171205console .log (raw .headers .get (' X-My-Header' ));
172- console .log (healthInfo . status );
206+ console .log (completion );
173207```
174208
175209### Making custom/undocumented requests
@@ -273,9 +307,12 @@ const client = new LlamaStackClient({
273307});
274308
275309// Override per-request:
276- await client .inspect .health ({
277- httpAgent: new http .Agent ({ keepAlive: false }),
278- });
310+ await client .chat .completions .create (
311+ { messages: [{ content: ' string' , role: ' user' }], model: ' model' },
312+ {
313+ httpAgent: new http .Agent ({ keepAlive: false }),
314+ },
315+ );
279316```
280317
281318## Semantic versioning
0 commit comments