fix(iflow): inject stream_options for usage data in streaming
Add stream_options: { include_usage: true } to iFlow streaming requests
to get token usage data in the final streaming chunk. This fixes token
counts showing as 0 for iFlow streaming requests.
Only injected when streaming is enabled and body.messages exists (OpenAI
format), and the client hasn't already set stream_options.
Note: Applied only to iFlow executor instead of BaseExecutor to avoid
affecting all providers globally. This gives us more control and allows
testing with iFlow first.
Fixes #74
Co-authored-by: Ibrahim Ryan <ryan@nuevanext.com>
Made-with: Cursor
This commit is contained in:
@@ -89,7 +89,7 @@ export class IFlowExecutor extends BaseExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform request body (passthrough for iFlow)
|
* Transform request body - inject stream_options for usage data
|
||||||
* @param {string} model - Model name
|
* @param {string} model - Model name
|
||||||
* @param {object} body - Request body
|
* @param {object} body - Request body
|
||||||
* @param {boolean} stream - Whether streaming is enabled
|
* @param {boolean} stream - Whether streaming is enabled
|
||||||
@@ -97,6 +97,10 @@ export class IFlowExecutor extends BaseExecutor {
|
|||||||
* @returns {object} Transformed body
|
* @returns {object} Transformed body
|
||||||
*/
|
*/
|
||||||
transformRequest(model, body, stream, credentials) {
|
transformRequest(model, body, stream, credentials) {
|
||||||
|
// Inject stream_options for streaming requests to get usage data
|
||||||
|
if (stream && body.messages && !body.stream_options) {
|
||||||
|
body.stream_options = { include_usage: true };
|
||||||
|
}
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user