Skip to content

Commit 10e745a

Browse files
authored
Merge pull request #16 from PAIR-code/iislucas-improve-readme
docs: improve main README with what this library supports
2 parents accaceb + 726d6f9 commit 10e745a

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,46 @@
44
[![npm latest version](https://img.shields.io/npm/v/ts-llmt/latest.svg)](https://www.npmjs.com/package/ts-llmt)
55

66
This repository holds experimental code aimed at providing native TypeScript
7-
support for Large Language Model Templates. The key idea being explored is that
8-
templates have a type that corresponds to the names of the variables within the
9-
template.
7+
support for Large Language Model Templates.
108

11-
For example:
9+
The key idea is to track "named-holes" in templates at type-checking (typing)
10+
time. This means:
11+
12+
- You never need to debug an accidental substitution for the wrong variable name.
13+
- You can substitute for some variables but not others, in any order you like, and the remaining
14+
variables are tracked in the type.
15+
- You can substitute templates with more holes into a named-hole in a template, and you get the
16+
correct remaining holes in the right places in the final template.
17+
- The same hole can appear in multiple places, substitution substitutes it everywhere, as you would
18+
expect.
19+
- There is support for few-shot prompts (where you have some iterated sub-template over a data
20+
structure).
21+
22+
Here's a mini-example:
1223

1324
```ts
1425
import { nv, template } from 'ts-llmt';
1526

1627
const thingVar = nv('thing');
1728
const thing2Var = nv('thing2');
18-
// The type of `whatIsAtoB` is inferred to be `Template<"thing" | "thing2">`
29+
// *NOTE*: type of `whatIsAtoB` is magically inferred to be:
30+
// `Template<"thing" | "thing2">`
1931
const whatIsAtoB = template`what is a ${thingVar} to a ${thing2Var}?`;
2032

21-
// Replacing the thing variable give type: `Template<"thing2">`
33+
// Replacing the `thing` variable in whatIsAtoB, gives the type:
34+
// `Template<"thing2">`
2235
const whatIsTabletoB = whatIsAtoB.vars.thing.substStr('table');
2336

2437
// The escaped raw form of this template is as so:
2538
expect(whatIsTabletoB.escaped).toEqual('what is a table to a {{thing2}}?');
2639
```
2740

28-
A nice feature of this is that you get as "as-you-type" error checking, and
29-
arguments can be auto-completed by the IDE. e.g. you can directly reference the
30-
variables from the 'vars' parameter of a template, and anything else is an
31-
as-you-type error in your editor.
41+
The key nice feature of this is that you get _as "as-you-type" error checking_,
42+
and _arguments can be auto-completed by the IDE_. You can never substitute for a
43+
variable that is not there.
3244

33-
You can do multi-variable replacement nicely, and still have all the wonderful
34-
type-checking like so:
45+
You can do multi-variable replacement nicely too, and still have all the
46+
wonderful type-checking like so:
3547

3648
```ts
3749
whatIsAtoB.substs({ thing: 'table', thing2: 'chair' });

0 commit comments

Comments
 (0)