-
Notifications
You must be signed in to change notification settings - Fork 283
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
Add @huggingface/ollama-utils
#1111
base: main
Are you sure you want to change the base?
Conversation
packages/ollama-utils/tsup.config.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you feel up to it you can use tshy
instead, like in @hugginface/tasks
.
It has more accurate exports / better compatibility with all that includes the package (and as long as you don't have different code in browser/node it should be easy to configure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't get around the error with this line:
src/chat-template.ts:1:43 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@huggingface/jinja")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts' or create a local package.json file with `{ "type": "module" }`.
1 import { Template as JinjaTemplate } from "@huggingface/jinja";
~~~~~~~~~~~~~~~~~~~~
Do you have any ideas @coyotte508 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like @huggingface/jinja
maybe needs to switch to tshy
first to all corner cases (early/late node version, CJS importing MJS, MJS importing CJS, ...) are exported correctly cc @xenova
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, the exports should operate correctly
Maybe I need to restructure it like transformers.js does it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do any other hf.js libs use tshy?
btw the github action to publish should be added (with optionnally a check to check the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know enough typescript to review, but two questions/comments from myside:
- maybe in a follow-up PR we should add a scraper and something to update the mapping?
- via comments/ README/ docs we should clarify how users can add their own exception as well
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay! conceptually lgtm!
## How can I add a custom template? | ||
|
||
Most templates will be converted automatically. You can debug the output template using: | ||
- This space to retrieve the converted template: https://huggingface.co/spaces/ngxson/debug_ollama_manifest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can do both in the same space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out how to embed my script into gradio space, but will have a look later
(The template debugging space is static btw)
Co-authored-by: vb <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge + comms - today?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, suggesting a few nits
@@ -0,0 +1,56 @@ | |||
# `@huggingface/ollama-utils` | |||
|
|||
Various utilities for maintaining Ollama compatibility with models on Hugging Face hub. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Various utilities for maintaining Ollama compatibility with models on Hugging Face hub. | |
Various utilities for maintaining [Ollama compatibility with GGUF models on the Hugging Face Hub](https://huggingface.co/docs/hub/en/ollama). | |
For now, we are exposing chat template conversion to the Go format used by Ollama. |
- This space to retrieve the converted template: https://huggingface.co/spaces/ngxson/debug_ollama_manifest | ||
- And this space to apply the Go template into a list of messages: https://huggingface.co/spaces/ngxson/ollama_template_test | ||
|
||
Please only add a new template only when the conversion above is not successful. Cases that are acceptable to add a custom handler: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only add a new template only when the conversion above is not successful. Cases that are acceptable to add a custom handler: | |
Please only add a new template when the conversion process above is not successful. Cases that are acceptable include: |
To add a new custom handler: | ||
1. Edit the list of `CUSTOM_TEMPLATE_MAPPING` inside `chat-template.ts` | ||
2. Add a new test case in `chat-template.spec.ts` | ||
3. Push your change into new PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Push your change into new PR. | |
3. Push your change to a new PR. |
@@ -62,6 +62,7 @@ This is a collection of JS libraries to interact with the Hugging Face API, with | |||
- [@huggingface/tasks](packages/tasks/README.md): The definition files and source-of-truth for the Hub's main primitives like pipeline tasks, model libraries, etc. | |||
- [@huggingface/jinja](packages/jinja/README.md): A minimalistic JS implementation of the Jinja templating engine, to be used for ML chat templates. | |||
- [@huggingface/space-header](packages/space-header/README.md): Use the Space `mini_header` outside Hugging Face | |||
- [@huggingface/ollama-utils](packages/ollama-utils/README.md): Various utilities for maintaining Ollama compatibility with models on Hugging Face hub. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [@huggingface/ollama-utils](packages/ollama-utils/README.md): Various utilities for maintaining Ollama compatibility with models on Hugging Face hub. | |
- [@huggingface/ollama-utils](packages/ollama-utils/README.md): Various utilities for maintaining Ollama compatibility with models on the Hugging Face Hub. |
Documentation: https://huggingface.co/docs/hub/en/ollama | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation: https://huggingface.co/docs/hub/en/ollama |
With the ollama compatibility layer already been up and running on HF hub for a while now, we want to open-source part of the integration for (1) provide more transparency, and (2) for encouraging the community to contribute.
Therefore, we decided to publish
@huggingface/ollama-utils
, a package containing tools that power this integration.For now, the only tool that we provide is
chat-template.ts
, a tool that takes a parsed GGUF config from@huggingface/gguf
as input, then returns the ollama Go template.chat-template.ts
This module expose one single
convertGGUFTemplateToOllama
function. It works by trying (by order) these mechanisms:scripts/generate-automap.ts
RE_SPECIAL_TOKEN
CUSTOM_TEMPLATE_MAPPING
, a list of hand-picked template mapping@huggingface/jinja
. SeeconvertJinjaToGoTemplate