Skip to content

Commit

Permalink
Changing Docs Structure + Code Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Nov 26, 2024
1 parent 0cbdc0e commit 6e0c581
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
instructions.
- [OpenAI Guide &rarr;](https://platform.openai.com/docs/guides/structured-outputs)<br />The OpenAI
platform's guide on Structured Outputs
- [Pattern Libraries &rarr;](https://structured-outputs.dev/patterns)<br />Pattern libraries
modeling common schemas using Structured Outputs TypeScript.
- [Pattern Libraries &rarr;](https://structured-outputs.dev/patterns)<br />Pattern libraries for
common use cases with Structured Outputs TypeScript.

## Installation

Expand Down
73 changes: 56 additions & 17 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { transformerTwoslash } from "@shikijs/vitepress-twoslash"
import { defineConfig } from "vitepress"
import { DefaultTheme, defineConfig } from "vitepress"
import { LIB_DESCRIPTION } from "../../constants.ts"

export default defineConfig({
title: "Structured Outputs TS",
description: LIB_DESCRIPTION,
markdown: {
codeTransformers: [transformerTwoslash()],
theme: {
dark: "github-dark",
light: "github-light",
},
},
sitemap: {
hostname: "http://structured-outputs.dev",
Expand All @@ -18,28 +22,27 @@ export default defineConfig({
editLink: {
pattern: "https://github.com/harrysolovay/structured-outputs/edit/main/docs/:path",
},
nav: [{
text: "Manual",
link: "/",
}],
nav: [
{
text: "Manual",
link: "/",
},
{
text: "Patterns",
link: "/patterns",
},
],
search: {
provider: "local",
},
sidebar: {
"/": {
base: "",
items: [{
text: "", // For now
collapsed: false,
items: [
{ text: "Overview", link: "/" },
{ text: "Quickstart", link: "quickstart" },
{ text: "Types", link: "types" },
{ text: "Context", link: "context" },
{ text: "Patterns", link: "patterns" },
{ text: "Common Errors", link: "common-errors" },
],
}],
items: manualItems(),
},
"/patterns/": {
base: "",
items: patternsItems(),
},
},
socialLinks: [{
Expand All @@ -48,3 +51,39 @@ export default defineConfig({
}],
},
})

function manualItems(): DefaultTheme.SidebarItem[] {
return [
{
text: "Manual",
collapsed: false,
items: [
{ text: "Overview", link: "/" },
{ text: "Quickstart", link: "quickstart" },
{ text: "Types", link: "types" },
{ text: "Context", link: "context" },
{ text: "Common Errors", link: "common-errors" },
],
},
]
}

function patternsItems(): DefaultTheme.SidebarItem[] {
return [
{
text: "Patterns",
collapsed: false,
items: [
{ text: "Overview", link: "patterns" },
{ text: "Authoring", link: "patterns/authoring" },
],
},
{
text: "Pattern Libraries",
collapsed: false,
items: [
{ text: "..." },
],
},
]
}
4 changes: 2 additions & 2 deletions docs/common-errors.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
prev:
text: Patterns
link: patterns
text: Context
link: context
next: false
---

Expand Down
4 changes: 2 additions & 2 deletions docs/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ prev:
text: Types
link: types
next:
text: Patterns
link: patterns
text: Common Errors
link: common-errors
---

# Context
Expand Down
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
title: Overview
prev: false
next:
title: Quickstart
link: quickstart
---

# Structured Outputs TypeScript
Expand Down
22 changes: 13 additions & 9 deletions docs/patterns.md → docs/patterns/authoring.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
---
prev:
text: Context
link: context
next:
text: Common Errors
link: common-errors
text: Patterns Overview
link: patterns
next: false
---

# Patterns

Patterns abstract over the core types described in [the types section](./types.md).
# Authoring Patterns

## Functional Patterns

Expand Down Expand Up @@ -51,9 +47,17 @@ import { T } from "structured-outputs"
const Critique = T.Option(T.string)

Critique
// TODO: enable ^? upon union flattening
// ^?
```

<br />
<br />
<br />
<br />
<br />
<br />
<br />

### `Date`

```ts twoslash
Expand Down
23 changes: 23 additions & 0 deletions docs/patterns/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
prev: false
next:
text: Authoring Patterns
link: patterns/authoring
---

# Patterns Overview

`structured-outputs` was designed to enable the creation of libraries that abstract over the core
types described in [the types section](../types.md). The aim is to enable an ecosystem of libraries
that make available reusable types for common use cases.

These types' context can be parameterized, such that end developers can apply context as necessary
([see context section](../context.md)).

## Requesting Patterns

If you have an idea for a `structured-outputs` pattern library, please feel free to open an issue in
the GitHub.

If you already created a library, please feel free to submit a pull request that adds it to the
"Pattern Libraries" list of this very documentation.
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
prev:
text: Overview
link: overview
link: /
next:
text: Types
link: types
Expand Down
16 changes: 15 additions & 1 deletion docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,23 @@ const Organism = T.taggedUnion({
})

Organism
// TODO: reenable ^? after union flattening
// ^?
```

<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />

## Transform Types

We may often want to transform the data returned by the OpenAI service into a different type. In
Expand Down
7 changes: 1 addition & 6 deletions types/taggedUnion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Ty } from "./Ty.ts"

// TODO: flatten signature
export function taggedUnion<M extends Record<string, Ty | null>>(members: M): Ty<
{
[K in keyof M]:
& { type: K }
& (M[K] extends Ty ? { value: M[K]["T"] } : {})
}[keyof M],
{ [K in keyof M]: M[K] extends Ty ? { type: K; value: M[K]["T"] } : { type: K } }[keyof M],
Exclude<M[keyof M], null>["P"],
false
> {
Expand Down

0 comments on commit 6e0c581

Please sign in to comment.