Skip to content

Commit e78b187

Browse files
committed
fix: add test for the exported symbol
1 parent 53e799e commit e78b187

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/responses.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// This source code is licensed under the terms described in the LICENSE file in
55
// the root directory of this source tree.
66

7+
import { getResponseOutputText } from 'llama-stack-client';
78
import { createResponseHeaders } from 'llama-stack-client/core';
89
import { Headers } from 'llama-stack-client/_shims/index';
910

@@ -29,3 +30,62 @@ describe('response parsing', () => {
2930
expect(headers['content-type']).toBe('text/xml, application/json');
3031
});
3132
});
33+
34+
describe('getResponseOutputText helper', () => {
35+
test('can be imported from package entry point and concatenates text', () => {
36+
const response = {
37+
id: 'resp_123',
38+
created_at: 0,
39+
model: 'llama-example',
40+
status: 'completed',
41+
output: [
42+
{
43+
type: 'message',
44+
role: 'assistant',
45+
content: [
46+
{ type: 'output_text', text: 'Hello ' },
47+
{ type: 'output_text', text: 'world' },
48+
],
49+
},
50+
{
51+
type: 'message',
52+
role: 'assistant',
53+
content: '!',
54+
},
55+
],
56+
};
57+
58+
expect(getResponseOutputText(response as any)).toBe('Hello world!');
59+
});
60+
});
61+
62+
describe('getResponseOutputText package export', () => {
63+
test('allows streaming responses to be flattened when imported from llama-stack-client', () => {
64+
const response = {
65+
id: 'resp_stream',
66+
created_at: 0,
67+
model: 'llama-example',
68+
status: 'completed',
69+
output: [
70+
{
71+
type: 'message',
72+
role: 'assistant',
73+
content: [
74+
'Streaming ',
75+
{ type: 'output_text', text: 'chunks ' },
76+
{ type: 'output_text', text: 'are ' },
77+
{ type: 'output_text', text: 'supported.' },
78+
],
79+
},
80+
{
81+
type: 'message',
82+
role: 'assistant',
83+
content: ' Enjoy!',
84+
},
85+
],
86+
};
87+
88+
expect(typeof getResponseOutputText).toBe('function');
89+
expect(getResponseOutputText(response as any)).toBe('Streaming chunks are supported. Enjoy!');
90+
});
91+
});

0 commit comments

Comments
 (0)