Skip to content

Commit 0e4954e

Browse files
authored
Rename L.assistantStruct -> L.assistantSchema, misc. (#362)
1 parent d694d75 commit 0e4954e

29 files changed

+413
-161
lines changed

.changeset/modern-eyes-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"liminal": minor
3+
---
4+
5+
Rename `L.assistantStruct` to `L.assistantSchema`, is it now supports all schemas, not just struct schemas. Template tag calls are properly dedented and normalized. Additionally, `L.userJson` now uses the optional schema to JSONC-encode with description annotations as comments on corresponding fields.

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.css linguist-vendored
2-
*.html linguist-vendored
2+
*.html linguist-vendored
3+
*.vue linguist-vendored

bun.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/_logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Console, Effect, flow } from "effect"
22
import { L, LPretty } from "liminal"
33

4-
export const logger = L.handle(flow(
4+
export const logger = L.listen(flow(
55
LPretty.event,
66
Console.log,
7-
Effect.andThen(Console.log()),
7+
Effect.andThen(Console.log()), // Line-break between events.
88
))

examples/activity_suggestions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Effect.gen(function*() {
1818
let i = 0
1919
const activities: Array<typeof Activity.Type> = []
2020
while (i < 5) {
21-
activities.push(yield* L.assistantStruct(Activity))
21+
activities.push(yield* L.assistantSchema(Activity))
2222
yield* L.user`Another please.`
2323
i++
2424
}

examples/basic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { logger } from "./_logger.ts"
55

66
Effect.gen(function*() {
77
yield* logger
8-
yield* L.user`Hey`
8+
yield* L.user`Hey.`
99
yield* L.assistant
1010
}).pipe(
1111
L.strand,
12-
Effect.scoped,
1312
Effect.provide(ModelLive),
13+
Effect.scoped,
1414
Effect.runFork,
1515
)

examples/chaining.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Effect.gen(function*() {
1818
1919
Copy to evaluate: ${copy}
2020
`
21-
const qualityMetrics = yield* L.assistantStruct({
21+
const qualityMetrics = yield* L.assistantSchema({
2222
hasCallToAction: Schema.Boolean,
2323
emotionalAppeal: Schema.Number,
2424
clarity: Schema.Number,

examples/compare_models.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { OpenAiLanguageModel } from "@effect/ai-openai"
2-
import { Effect, Schema } from "effect"
2+
import { Console, Effect, Schema } from "effect"
33
import { L } from "liminal"
44
import { ClientLive, ModelLive } from "./_layers.ts"
55
import { logger } from "./_logger.ts"
66

77
Effect.gen(function*() {
88
yield* logger
9+
910
yield* L.user`Write a rap about type-level programming in TypeScript`
1011
yield* L.assistant
1112
yield* L.user`Rewrite it in whatever way you think best.`
12-
const variants = yield* Effect.all({
13+
14+
const rewrites = yield* Effect.all({
1315
a: L.branch(L.assistant),
1416
b: L.assistant.pipe(
1517
L.branch,
@@ -20,16 +22,16 @@ Effect.gen(function*() {
2022
Effect.provide(OpenAiLanguageModel.model("gpt-3.5-turbo")),
2123
),
2224
}, { concurrency: "unbounded" })
25+
2326
yield* L.clear
2427
yield* L.user`
2528
Out of the following variants, which is your favorite?:
2629
27-
${JSON.stringify(variants)}
30+
${JSON.stringify(rewrites)}
2831
`
29-
const { key } = yield* L.assistantStruct({
30-
key: Schema.Literal("a", "b", "c"),
31-
})
32-
return variants[key]
32+
yield* L.assistantSchema(Schema.Literal("a", "b", "c")).pipe(
33+
Effect.flatMap((key) => Console.log(rewrites[key])),
34+
)
3335
}).pipe(
3436
L.strand,
3537
Effect.scoped,

examples/documentation_qa.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,10 @@ import * as Console from "effect/Console"
55
import { L } from "liminal"
66
import { ModelLive } from "./_layers.ts"
77

8+
// TODO: use this for actual docs
89
declare const LIB_DIR: string
910
declare const DOCS_DIR: string
1011

11-
const Suggestions = Schema.Struct({
12-
suggestions: Schema.Option(
13-
Schema.Array(
14-
Schema.String.pipe(Schema.annotations({
15-
description: "Improvements to be made to the document.",
16-
})),
17-
),
18-
),
19-
})
20-
2112
Effect.gen(function*() {
2213
yield* L.user`I'm about to provide you with a repomix summary of the current codebase.`
2314

@@ -41,7 +32,13 @@ Effect.gen(function*() {
4132
4233
${fs.readFileString(docPath)}
4334
`
44-
const maybeChanges = yield* L.assistantStruct(Suggestions)
35+
const maybeChanges = yield* L.assistantSchema(Schema.Option(
36+
Schema.Array(
37+
Schema.String.pipe(Schema.annotations({
38+
description: "Improvements to be made to the document.",
39+
})),
40+
),
41+
))
4542
return [docPath, maybeChanges] as const
4643
}),
4744
L.branch,

examples/jsonc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { L, LPretty } from "liminal"
44
const ExampleSchema = Schema.Struct({
55
inner: Schema.String.pipe(
66
Schema.annotations({
7-
jsonSchema: {
8-
description: "Some description for the LLM.",
9-
},
7+
description: "Some description for the LLM.",
108
}),
119
),
1210
})
1311

1412
Effect.gen(function*() {
1513
yield* L.userJson({ inner: "value" }, ExampleSchema)
16-
const message = yield* yield* L.messages.pipe(Effect.map(Array.head))
14+
const message = yield* yield* L.messages.pipe(
15+
Effect.map(Array.head),
16+
)
1717
yield* Console.log(LPretty.message(message))
1818
}).pipe(
1919
L.strand,

0 commit comments

Comments
 (0)