-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jinja] Add support for macros and | tojson
#692
Conversation
Example usage: import { Template } from "@huggingface/jinja";
import { downloadFile } from "@huggingface/hub";
// Download config file from the Hugging Face Hub
const config = await (
await downloadFile({
repo: "CohereForAI/c4ai-command-r-plus",
path: "tokenizer_config.json",
revision: "refs/pr/46",
})
).json();
// Construct template from config
const template = new Template(config.chat_template.find((t) => t.name === "tool_use").template);
// Define messages and tools
const messages = [{ role: "user", content: "Whats the biggest penguin in the world?" }];
const tools = [
{
name: "directly_answer",
description: "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
parameters: { type: "object", properties: {} },
},
{
name: "internet_search",
description: "Returns a list of relevant document snippets for a textual query retrieved from the internet",
parameters: {
type: "object",
properties: { query: { type: "string", description: "Query to search the internet with" } },
required: ["query"],
},
return: { type: "string", description: "Some text" },
},
];
// Render template
const result = template.render({
messages,
tools,
bos_token: config.bos_token,
eos_token: config.eos_token,
});
console.log(result); Outputs:
NOTE: I will add some example usage to the README/docs once the PR in transformers is finalized. |
| tojson
Now also supports I also want to add an e2e test for a template which uses macros - @Rocketknight1 know of any? |
Yes, that works! You can also use Mistral-7B-Instruct or Hermes-2-Pro |
Also note that we currently implement |
Perfect! I've added tests for both those templates, and both function correctly! I think this PR is ready to merge after another look tomorrow. |
Finally got around to adding this to Transformers.js (v3). Merging! 🚀 |
Adds support for Macros. See here for more information: https://jinja.palletsprojects.com/en/3.1.x/templates/#macros
cc @Rocketknight1