Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/transformers/src/pipelines/text-generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ function isChat(x) {
export class TextGenerationPipeline
extends /** @type {new (options: TextPipelineConstructorArgs) => TextGenerationPipelineType} */ (Pipeline)
{
/**
* @param {string | string[] | import('../tokenization_utils.js').Message[] | import('../tokenization_utils.js').Message[][]} texts
* @param {Partial<TextGenerationConfig>} generate_kwargs
*/
async _call(texts, generate_kwargs = {}) {
let isBatched = false;
let isChatInput = false;
Expand Down
22 changes: 21 additions & 1 deletion packages/transformers/src/tokenization_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,30 @@ const SPECIAL_TOKEN_ATTRIBUTES = [
// additional_special_tokens (TODO)
];

/**
* @typedef {Object} TextContent
* @property {'text'} type The type of content (must be 'text').
* @property {string} text The text content.
*/

/**
* @typedef {Object} ImageContent
* @property {'image'} type The type of content (must be 'image').
* @property {string | import('./utils/image.js').RawImage} image Optional URL of the image.
*
* Note: This works for SmolVLM. Qwen2VL and Idefics3 have different implementations. TODO: We should have a standardised way to handle images
*/

/**
* @typedef {TextContent | ImageContent} MessageContent
* Base type for message content. This is a discriminated union that can be extended with additional content types.
* Example: `@typedef {TextContent | ImageContent | AudioContent} MessageContent`
*/

/**
* @typedef {Object} Message
* @property {string} role The role of the message (e.g., "user" or "assistant" or "system").
* @property {string} content The content of the message.
* @property {string | MessageContent[]} content The content of the message. Can be a simple string or an array of content objects.
*/

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"noEmit": false,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"composite": true
"composite": true,
"strictNullChecks": false
},
"typeAcquisition": {
"include": ["jest"]
Expand Down