{"id":28515190,"url":"https://github.com/pair-code/ts-llmt","last_synced_at":"2025-08-31T17:34:10.304Z","repository":{"id":239568271,"uuid":"794017271","full_name":"PAIR-code/ts-llmt","owner":"PAIR-code","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-29T13:55:26.000Z","size":210,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-09T11:59:49.276Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PAIR-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2024-04-30T09:50:59.000Z","updated_at":"2024-10-29T13:55:26.000Z","dependencies_parsed_at":"2024-05-13T11:26:45.748Z","dependency_job_id":"d7e79dfe-6705-471f-aa61-dd9d59b08c96","html_url":"https://github.com/PAIR-code/ts-llmt","commit_stats":null,"previous_names":["pair-code/ts-llmt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PAIR-code/ts-llmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PAIR-code%2Fts-llmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PAIR-code%2Fts-llmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PAIR-code%2Fts-llmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PAIR-code%2Fts-llmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PAIR-code","download_url":"https://codeload.github.com/PAIR-code/ts-llmt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PAIR-code%2Fts-llmt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263718199,"owners_count":23500791,"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":[],"created_at":"2025-06-09T03:04:53.980Z","updated_at":"2025-07-05T09:30:48.103Z","avatar_url":"https://github.com/PAIR-code.png","language":"TypeScript","readme":"# TypeScript Large Language Model Templates (TS-LLMT)\r\n\r\n[![Build Status](https://github.com/PAIR-code/ts-llmt/actions/workflows/release_workflow.yaml/badge.svg)](https://github.com/PAIR-code/ts-llmt/actions/workflows/release_workflow.yaml)\r\n[![npm latest version](https://img.shields.io/npm/v/ts-llmt/latest.svg)](https://www.npmjs.com/package/ts-llmt)\r\n\r\nThis repository holds experimental code aimed at providing native TypeScript\r\nsupport for Large Language Model Templates.\r\n\r\nThe key idea is to track \"named-holes\" in templates at type-checking (typing)\r\ntime. This means:\r\n\r\n- You never need to debug an accidental substitution for the wrong variable name.\r\n- You can substitute for some variables but not others, in any order you like, and the remaining\r\n  variables are tracked in the type.\r\n- You can substitute templates with more holes into a named-hole in a template, and you get the\r\n  correct remaining holes in the right places in the final template.\r\n- The same hole can appear in multiple places, substitution substitutes it everywhere, as you would\r\n  expect.\r\n- There is support for few-shot prompts (where you have some iterated sub-template over a data\r\n  structure).\r\n\r\nHere's a mini-example:\r\n\r\n```ts\r\nimport { nv, template } from 'ts-llmt';\r\n\r\nconst thingVar = nv('thing');\r\nconst thing2Var = nv('thing2');\r\n// *NOTE*: type of `whatIsAtoB` is magically inferred to be:\r\n//         `Template\u003c\"thing\" | \"thing2\"\u003e`\r\nconst whatIsAtoB = template`what is a ${thingVar} to a ${thing2Var}?`;\r\n\r\n// Replacing the `thing` variable in whatIsAtoB, gives the type:\r\n//         `Template\u003c\"thing2\"\u003e`\r\nconst whatIsTabletoB = whatIsAtoB.vars.thing.substStr('table');\r\n\r\n// The escaped raw form of this template is as so:\r\nexpect(whatIsTabletoB.escaped).toEqual('what is a table to a {{thing2}}?');\r\n```\r\n\r\nThe key nice feature of this is that you get _as \"as-you-type\" error checking_,\r\nand _arguments can be auto-completed by the IDE_. You can never substitute for a\r\nvariable that is not there.\r\n\r\nYou can do multi-variable replacement nicely too, and still have all the\r\nwonderful type-checking like so:\r\n\r\n```ts\r\nwhatIsAtoB.substs({ thing: 'table', thing2: 'chair' });\r\nexpect(whatIsTabletoB.escaped).toEqual('what is a table to a chair?');\r\n```\r\n\r\n## License: Apache 2.0\r\n\r\nSource code for this library is released under the [Apache 2.0\r\nlicense](https://spdx.org/licenses/Apache-2.0.html). The full text of the\r\nApache-2.0 license is available in the accompanying [`LICENSE.md`](./LICENSE.md)\r\nfile.\r\n\r\n## Contributing\r\n\r\nSee the [`CONTRIBUTING.md`](./CONTRIBUTING.md) file for details of how to\r\ncontribute, setup your environment, run tests, check license headers, style, and\r\nformat your commit messages.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpair-code%2Fts-llmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpair-code%2Fts-llmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpair-code%2Fts-llmt/lists"}