-
Notifications
You must be signed in to change notification settings - Fork 281
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]>
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