Skip to content

Commit

Permalink
Context Document
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Nov 26, 2024
1 parent 2c00d81 commit e89148c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
47 changes: 45 additions & 2 deletions docs/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,49 @@ next:

# Context

## Placeholding
The descriptions contained within your types serve as context for the LLM. It is for this reason
that the core unit of `structured-outputs`––`Ty`--is an infinitely-chainable tagged template
function.

## Composition
```ts twoslash
import { T } from "structured-outputs"
// ---cut---
const A = T.string`A.`
const B = A`B.`
const C = B`C.`
```

The resulting description contained within the JSON Schema will contain the concatenated
descriptions.

```json
{
"type": "string",
"description": "C. B. A."
}
```

This enables us to attach additional context to any type.

## Parameterized Context

Often times, we may want to reuse the structure of a type, but not the context. In these cases, we
can interpolate parameter keys into the template literal of the `Ty` tagged template expression.

```ts
const Character = T.object({
name: T.string,
behavior: T.string,
})`A ${"character_type"} character of a ${"story_type"} story.`
```

Whenever we wish to use this context-parameterized type, we can fill in the missing context.

```ts
const StoryCharacters = Character.fill({
character_type: "virtuous",
story_type: "romance",
})
```

We can placehold context with any valid JavaScript key type (`number` | `string` | `symbol`).
5 changes: 3 additions & 2 deletions docs/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export namespace P {

export function WithTone<T, P extends keyof any, R extends boolean>(
ty: T.Ty<T, P, R>,
): T.Ty<T, P | P.Tone> {
): T.Ty<T, P | typeof P.Tone> {
return ty`Generate with a tone of ${P.Tone}.`
}
```
Expand All @@ -147,4 +147,5 @@ const any: Ty<any, never, false> = Ty(
)
```

You could similarly create a function that returns the `Ty`.
You could similarly create a functional pattern, which accepts arguments and uses them to form the
returned `Ty`.
1 change: 0 additions & 1 deletion types/std/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./color.ts"
export * from "./Date.ts"
export * from "./Option.ts"
export * from "./Wrapper.ts"

0 comments on commit e89148c

Please sign in to comment.