{"id":26158091,"url":"https://github.com/johnmai-dev/minja-swift","last_synced_at":"2025-12-25T01:13:16.660Z","repository":{"id":273194306,"uuid":"918958015","full_name":"johnmai-dev/minja-swift","owner":"johnmai-dev","description":"📄 A swift wrapper of the minja","archived":false,"fork":false,"pushed_at":"2025-01-19T10:48:31.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T11:28:57.266Z","etag":null,"topics":["jinja","jinja2","minja","template"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnmai-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-19T10:39:00.000Z","updated_at":"2025-01-19T10:48:33.000Z","dependencies_parsed_at":"2025-01-19T11:39:38.535Z","dependency_job_id":null,"html_url":"https://github.com/johnmai-dev/minja-swift","commit_stats":null,"previous_names":["johnmai-dev/minja-swift"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmai-dev%2Fminja-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmai-dev%2Fminja-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmai-dev%2Fminja-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnmai-dev%2Fminja-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnmai-dev","download_url":"https://codeload.github.com/johnmai-dev/minja-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243015337,"owners_count":20222070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jinja","jinja2","minja","template"],"created_at":"2025-03-11T10:31:23.954Z","updated_at":"2025-12-25T01:13:11.634Z","avatar_url":"https://github.com/johnmai-dev.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# minja-swift\n\nminja-swift is a swift wrapper of the [Minja](https://github.com/google/minja).\n\n\u003e [Minja](https://github.com/google/minja) is a minimalistic C++ Jinja templating engine for LLM chat templates\n\n\u003e [!WARNING]  \n\u003e TL;DR: use of Minja is *at your own risk*, and the risks are plenty!\n\u003e See [Security \u0026 Privacy](https://github.com/google/minja/tree/main?tab=readme-ov-file#security--privacy) section below.\n\n# Usage\n\n```swift\nlet template = ChatTemplate(\n    source:\n    \"{% for message in messages %}{{ '\u003c|' + message['role'] + '|\u003e\\\\n' + message['content'] + '\u003c|end|\u003e' + '\\\\n' }}{% endfor %}\",\n    bosToken: \"\u003c|start|\u003e\",\n    eosToken: \"\u003c|end|\u003e\"\n)\n\nlet result = try template.apply(\n    messages: [\n        [\"role\": \"user\", \"content\": \"Hello\"],\n        [\"role\": \"assistant\", \"content\": \"Hi\"]\n    ],\n    tools: [\n    [\n        \"type\": \"function\",\n        \"function\": [\n            \"name\": \"google_search\",\n            \"arguments\": [\"query\": \"2+2\"],\n        ],\n    ]\n    ],\n    addGenerationPrompt: true\n)\n```\n\n# Swift Package Manager\n\nAdd the following to your `Package.swift` file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/johnmai-dev/minja-swift\", from: \"0.0.1\")\n]\n```\n\nAnd then add `minja-swift` as a dependency for your target:\n\n```swift\ntargets: [\n    .target(\n        name: \"YourTarget\",\n        dependencies: [\n            .product(name: \"Minja\", package: \"minja-swift\")\n        ]\n    )\n]\n```\n\nAnd then set `Swift Compiler - Language` to `C++/Objective-C++ Interoperability` in the `Build Settings` tab of your\ntarget.\n\n## Benchmark [Minja Swift](https://github.com/johnmai-dev/minja-swift) vs [Jinja Swift](https://github.com/johnmai-dev/Jinja)\n\nbenchmark branch: https://github.com/johnmai-dev/minja-swift/tree/benchmark\n\n```bash\nname                            time           std        iterations\n--------------------------------------------------------------------\nminja-swift benchmark -\u003e         440583.000 ns ±   2.48 %       3103\nminja-swift 1000 benchmark -\u003e    440083.000 ns ±   1.75 %       1000\nminja-swift 2500 benchmark -\u003e    441125.000 ns ±   1.80 %       2500\nminja-swift 5000 benchmark -\u003e    443209.000 ns ±   2.41 %       5000\nminja-swift 10000 benchmark -\u003e   443375.000 ns ±   1.85 %      10000\njinja-swift benchmark -\u003e        1057916.000 ns ±   0.96 %       1318\njinja-swift 1000 benchmark -\u003e   1058583.000 ns ±   0.99 %       1000\njinja-swift 2500 benchmark -\u003e   1058292.000 ns ±   1.03 %       2500\njinja-swift 5000 benchmark -\u003e   1060417.000 ns ±   2.31 %       5000\njinja-swift 10000 benchmark -\u003e  1059875.000 ns ±   2.07 %      10000\n```\n\n## To Do\n\n- [x] Wapper for [chat-template.hpp](https://github.com/google/minja/blob/main/include/minja/chat-template.hpp)\n- [ ] Wapper for [minja.hpp](https://github.com/google/minja/blob/main/include/minja/minja.hpp)\n\n# License\n\n[MIT License](LICENSE)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnmai-dev%2Fminja-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnmai-dev%2Fminja-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnmai-dev%2Fminja-swift/lists"}