mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 01:48:05 +00:00
copy getResponseOutputText for now
This commit is contained in:
parent
afa663e683
commit
a94093bcbd
2 changed files with 39 additions and 2 deletions
|
|
@ -11,8 +11,7 @@
|
|||
* IMPORTANT: Test cases and IDs must match EXACTLY with Python tests to use recorded API responses.
|
||||
*/
|
||||
|
||||
import { createTestClient, requireTextModel } from '../setup';
|
||||
import { getResponseOutputText } from 'llama-stack-client';
|
||||
import { createTestClient, requireTextModel, getResponseOutputText } from '../setup';
|
||||
|
||||
describe('Responses API - Basic', () => {
|
||||
// Test cases matching llama-stack/tests/integration/responses/fixtures/test_cases.py
|
||||
|
|
|
|||
|
|
@ -149,3 +149,41 @@ export function requireEmbeddingModel(): string {
|
|||
}
|
||||
return TEST_CONFIG.embeddingModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts aggregated text output from a ResponseObject.
|
||||
* This concatenates all text content from the response's output array.
|
||||
*
|
||||
* Copied from llama-stack-client's response-helpers until it's available in published version.
|
||||
*/
|
||||
export function getResponseOutputText(response: any): string {
|
||||
const pieces: string[] = [];
|
||||
|
||||
for (const output of response.output ?? []) {
|
||||
if (!output || output.type !== 'message') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const content = output.content;
|
||||
if (typeof content === 'string') {
|
||||
pieces.push(content);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Array.isArray(content)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const item of content) {
|
||||
if (typeof item === 'string') {
|
||||
pieces.push(item);
|
||||
continue;
|
||||
}
|
||||
if (item && item.type === 'output_text' && 'text' in item && typeof item.text === 'string') {
|
||||
pieces.push(item.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pieces.join('');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue