Skip to content

Commit

Permalink
In "Use in transformers", use messages if conversational (#728)
Browse files Browse the repository at this point in the history
Increase visibility of conversational capabilities of `text-generation`
pipeline

![Screenshot from 2024-05-30
18-45-05](https://github.com/huggingface/huggingface.js/assets/7246357/e58af649-3943-49a8-815e-800c5d97aae0)

---------

Co-authored-by: Julien Chaumond <[email protected]>
  • Loading branch information
osanseviero and julien-c authored May 31, 2024
1 parent a352941 commit 8df8f6a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,17 @@ export const transformers = (model: ModelData): string[] => {
}

if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
const pipelineSnippet = [
"# Use a pipeline as a high-level helper",
"from transformers import pipeline",
"",
`pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")",
].join("\n");
return [pipelineSnippet, autoSnippet];
const pipelineSnippet = ["# Use a pipeline as a high-level helper", "from transformers import pipeline", ""];

if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
}
pipelineSnippet.push(`pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
pipelineSnippet.push("pipe(messages)");
}

return [pipelineSnippet.join("\n"), autoSnippet];
}
return [autoSnippet];
};
Expand Down

0 comments on commit 8df8f6a

Please sign in to comment.