mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
35 lines
573 B
TypeScript
35 lines
573 B
TypeScript
import type { IDataObject } from 'n8n-workflow';
|
|
|
|
/**
|
|
* Formats the response from the LLM chain into a consistent structure
|
|
*/
|
|
export function formatResponse(response: unknown, version: number): IDataObject {
|
|
if (typeof response === 'string') {
|
|
return {
|
|
text: response.trim(),
|
|
};
|
|
}
|
|
|
|
if (Array.isArray(response)) {
|
|
return {
|
|
data: response,
|
|
};
|
|
}
|
|
|
|
if (response instanceof Object) {
|
|
if (version >= 1.6) {
|
|
return response as IDataObject;
|
|
}
|
|
|
|
return {
|
|
text: JSON.stringify(response),
|
|
};
|
|
}
|
|
|
|
return {
|
|
response: {
|
|
text: response,
|
|
},
|
|
};
|
|
}
|