huggingface / huggingface.js

Utilities to use the Hugging Face Hub API
https://hf.co/docs/huggingface.js
MIT License
1.37k stars 213 forks source link

feat(jinja): add string rstrip and lstrip methods #854

Closed snowyu closed 1 month ago

snowyu commented 1 month ago

Done.

btw, I've implemented user-defined filters using JavaScript's original value methods: toValue(), toString(), and toJSON() mainly. It's a huge change. I'm not sure if I should submit a pull request yet.

xenova commented 1 month ago

btw, do you have an example of a chat template which uses these methods? Would be nice to add as an end-to-end unit test

snowyu commented 1 month ago

@xenova here is my WIP project PPE(Programmable Prompt Engine) CLI:https://github.com/offline-ai/cli.

Any suggestions are very welcome.

My changes are here: https://github.com/isdk/ai-tool.js/tree/main/src/utils/prompt/template/jinja

unit tests:

User story scenario:

I've written the PPE json.ai.yaml lib which convert any content to json.

I've found that LLM are better at understanding natural language than json.

So, the user can use the Object::toString(without modifing the json library) convert json to string(natural language).

---
output:
  type: "object"
  properties:
    sentiment:
      type: "string"
      description: "Sentiment (positive or negative)"
content: >-
  Needed a nice lamp for my bedroom, and this one had additional storage and not too high of a price point. Got it fast.
  The string to our lamp broke during the transit and the company happily sent over a new one. Came within a few days as well. It was easy to put together.
---
|fn |-
  # add toString() method to output object
  function output$toString(value) {
    return 'the nature lang for output JSON Schema...'
  }
# call the json lib
-> json(content=content, output=output)