{"id":15713552,"url":"https://github.com/kojix2/tiktoken-cr","last_synced_at":"2026-03-10T14:33:57.320Z","repository":{"id":186508036,"uuid":"674840841","full_name":"kojix2/tiktoken-cr","owner":"kojix2","description":"Tiktoken for Crystalists","archived":false,"fork":false,"pushed_at":"2025-07-04T03:40:08.000Z","size":108,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-04T04:26:55.723Z","etag":null,"topics":["crystal","tiktoken"],"latest_commit_sha":null,"homepage":"https://kojix2.github.io/tiktoken-cr/","language":"Crystal","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/kojix2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"ko_fi":"kojix2"}},"created_at":"2023-08-04T23:44:30.000Z","updated_at":"2025-07-04T03:39:48.000Z","dependencies_parsed_at":"2024-10-24T10:51:13.811Z","dependency_job_id":"d8df0981-9541-4dab-a475-34e49604dc07","html_url":"https://github.com/kojix2/tiktoken-cr","commit_stats":null,"previous_names":["kojix2/tiktoken-cr"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kojix2/tiktoken-cr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Ftiktoken-cr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Ftiktoken-cr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Ftiktoken-cr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Ftiktoken-cr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kojix2","download_url":"https://codeload.github.com/kojix2/tiktoken-cr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Ftiktoken-cr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30337292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T12:41:07.687Z","status":"ssl_error","status_checked_at":"2026-03-10T12:41:06.728Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["crystal","tiktoken"],"created_at":"2024-10-03T21:32:04.862Z","updated_at":"2026-03-10T14:33:57.312Z","avatar_url":"https://github.com/kojix2.png","language":"Crystal","funding_links":["https://ko-fi.com/kojix2"],"categories":[],"sub_categories":[],"readme":"# tiktoken-cr\n\n[![test](https://github.com/kojix2/tiktoken-cr/actions/workflows/test.yml/badge.svg)](https://github.com/kojix2/tiktoken-cr/actions/workflows/test.yml)\n[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Ftiktoken-cr%2Flines)](https://tokei.kojix2.net/github/kojix2/tiktoken-cr)\n\nTiktoken for Crystalists.\n\n- [tiktoken-c](https://github.com/kojix2/tiktoken-c)\n\n## Installation\n\n```bash\n# Clone with submodules and build tiktoken-c\ngit clone --recursive https://github.com/kojix2/tiktoken-cr\ncd tiktoken-cr \u0026\u0026 cd tiktoken-c \u0026\u0026 cargo build --release \u0026\u0026 cd ..\n\n# Run with library path\nexport LD_LIBRARY_PATH=./tiktoken-c/target/release:$LD_LIBRARY_PATH  # Linux\nexport DYLD_LIBRARY_PATH=./tiktoken-c/target/release:$DYLD_LIBRARY_PATH  # macOS\ncrystal build your_program.cr\n\n# Or use --link-flags\ncrystal build your_program.cr --link-flags \"-L $(pwd)/tiktoken-c/target/release\"\n```\n\nAdd to `shard.yml`:\n\n```yaml\ndependencies:\n  tiktoken:\n    github: kojix2/tiktoken-cr\n```\n\n## Usage\n\n### Using model name\n\n```crystal\nrequire \"tiktoken\"\n\ntext = \"吾輩は猫である。名前はたぬき。\"\n\nencoding = Tiktoken.encoding_for_model(\"gpt-4\")\ntokens = encoding.encode_with_special_tokens(text)\n# [7305, 122, 164, 120, 102, 15682, 163, 234, 104, 16556, 30591, 30369, 1811, 13372, 25580, 15682, 28713, 2243, 105, 50834, 1811]\n\nencoding.decode(tokens)\n# \"吾輩は猫である。名前はたぬき。\"\n```\n\n### Using encoding directly\n\nYou can also create encodings directly:\n\n```crystal\nrequire \"tiktoken\"\n\n# Available encodings:\nencoding = Tiktoken::Encoding.r50k_base       # GPT-3 models\nencoding = Tiktoken::Encoding.p50k_base       # Code models\nencoding = Tiktoken::Encoding.p50k_edit       # Edit models\nencoding = Tiktoken::Encoding.cl100k_base     # ChatGPT models\nencoding = Tiktoken::Encoding.o200k_base      # GPT-4o, o1, o3 models\nencoding = Tiktoken::Encoding.o200k_harmony   # gpt-oss models\n\ntext = \"Hello, world!\"\ntokens = encoding.encode(text)\ndecoded = encoding.decode(tokens)\n```\n\n### Count the number of ChatGPT tokens\n\n```crystal\nmodel = \"gpt-4\"\nmessages = [\n  {\n    \"role\"    =\u003e \"system\",\n    \"content\" =\u003e \"You are a helpful assistant that only speaks French.\",\n  },\n  {\n    \"role\"    =\u003e \"user\",\n    \"content\" =\u003e \"Hello, how are you?\",\n  },\n  {\n    \"role\"    =\u003e \"assistant\",\n    \"content\" =\u003e \"Parlez-vous francais?\",\n  },\n]\n\nTiktoken.num_tokens_from_messages(model, messages)\n# 36\n\nTiktoken.chat_completion_max_tokens(model, messages)\n# 8156\n```\n\n## Documentation\n\n[API Documentation](https://kojix2.github.io/tiktoken-cr/)\n\n## Contributing\n\n- Report bugs\n- Fix bugs and submit pull requests\n- Write, clarify, or fix documentation\n- Suggest or add new features\n- Make a donation\n\n## Acknowledgement\n\nThis project is inspired by [tiktoken_ruby](https://github.com/IAPark/tiktoken_ruby).\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Ftiktoken-cr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkojix2%2Ftiktoken-cr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Ftiktoken-cr/lists"}