Skip to content

Commit df8861a

Browse files
authored
Separate L.assistant into L.assistantText and L.assistantStruct (#340)
1 parent e8db482 commit df8861a

File tree

15 files changed

+93
-71
lines changed

15 files changed

+93
-71
lines changed

.changeset/bitter-ears-sing.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+
Separate L.assistant into L.assistantText and L.assistantStruct.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ import * as Strand from "liminal/Strand"
2727
await Effect.gen(function*() {
2828
yield* L
2929
.user`Decide on a subtopic for us to discuss within the domain of technological futurism.`
30-
yield* L.assistant()
30+
yield* L.assistantText
3131
yield* L
3232
.user`Great, please teach something interesting about this choice of subtopic.`
33-
yield* L.assistant()
33+
yield* L.assistantText
3434
let i = 0
3535
while (i < 3) {
3636
const reply = yield* Effect
3737
.gen(function*() {
3838
yield* L.user`Please reply to the last message on my behalf.`
39-
return yield* L.assistant()
39+
return yield* L.assistantText
4040
})
4141
.pipe(Effect.provide(Strand.layer()))
4242
yield* L.user(reply)
43-
yield* L.assistant()
43+
yield* L.assistantText
4444
i++
4545
}
4646
yield* L.user`Please summarize the key points from our conversation.`
47-
return yield* L.assistant()
47+
return yield* L.assistantText
4848
}).pipe(
4949
Effect.provide(Strand.layer({
5050
system: `

examples/activity_suggestions.ts

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

examples/chaining.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { common } from "./_common.ts"
66

77
await Effect.gen(function*() {
88
yield* L.user`Please generate the first draft.`
9-
let copy = yield* L.assistant()
9+
let copy = yield* L.assistantText
1010
yield* L.user`
1111
Now evaluate this marketing copy for:
1212
@@ -16,7 +16,7 @@ await Effect.gen(function*() {
1616
1717
Copy to evaluate: ${copy}
1818
`
19-
const qualityMetrics = yield* L.assistant(Schema.Struct({
19+
const qualityMetrics = yield* L.assistantStruct(Schema.Struct({
2020
hasCallToAction: Schema.Boolean,
2121
emotionalAppeal: Schema.Number,
2222
clarity: Schema.Number,
@@ -31,7 +31,7 @@ await Effect.gen(function*() {
3131
3232
Original copy: ${copy}
3333
`
34-
copy = yield* L.assistant()
34+
copy = yield* L.assistantText
3535
}
3636
return { copy, qualityMetrics }
3737
}).pipe(

examples/compare_models.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { common } from "./_common.ts"
77

88
await Effect.gen(function*() {
99
yield* L.user`Write a rap about type-level programming in TypeScript`
10-
yield* L.assistant()
10+
yield* L.assistantText
1111
yield* L.user`Rewrite it in whatever way you think best.`
1212
const variants = yield* Effect.all({
13-
a: L.assistant().pipe(Effect.provide(Strand.layer())),
14-
b: L.assistant().pipe(
13+
a: L.assistantText.pipe(Effect.provide(Strand.layer())),
14+
b: L.assistantText.pipe(
1515
Effect.provide(Strand.layer()),
1616
Effect.provide(OpenAiLanguageModel.model("gpt-4-turbo")),
1717
),
18-
c: L.assistant().pipe(
18+
c: L.assistantText.pipe(
1919
Effect.provide(Strand.layer()),
2020
Effect.provide(OpenAiLanguageModel.model("gpt-3.5-turbo")),
2121
),
@@ -26,7 +26,9 @@ await Effect.gen(function*() {
2626
2727
${JSON.stringify(variants)}
2828
`
29-
return yield* L.assistant(Schema.Literal("a", "b", "c"))
29+
return yield* L.assistantStruct(Schema.Struct({
30+
inner: Schema.Literal("a", "b", "c"),
31+
})).pipe(Effect.map(({ inner }) => inner))
3032
})
3133
return variants[key]
3234
}).pipe(

examples/optimizer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TEXT = "..."
99
Effect.gen(function*() {
1010
yield* L.user`Target language: typescript`
1111
yield* L.user`Text:\n\n${TEXT}`
12-
let currentTranslation = yield* L.assistant()
12+
let currentTranslation = yield* L.assistantText
1313
let iterations = 0
1414
const MAX_ITERATIONS = 3
1515
while (iterations < MAX_ITERATIONS) {
@@ -25,7 +25,7 @@ Effect.gen(function*() {
2525
3. Preservation of nuance
2626
4. Cultural accuracy
2727
`
28-
const evaluation = yield* L.assistant(Schema.Struct({
28+
const evaluation = yield* L.assistantStruct(Schema.Struct({
2929
qualityScore: Schema.Int,
3030
preservesTone: Schema.Boolean,
3131
preservesNuance: Schema.Boolean,
@@ -50,7 +50,7 @@ Effect.gen(function*() {
5050
Original: ${TEXT}
5151
Current Translation: ${currentTranslation}
5252
`
53-
currentTranslation = yield* L.assistant()
53+
currentTranslation = yield* L.assistantText
5454
iterations += 1
5555
}
5656
return {

examples/parallel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { common } from "./_common.ts"
88

99
const Lmh = Schema.Literal("lower", "medium", "high")
1010

11-
const security = L.assistant(Schema.Struct({
11+
const security = L.assistantStruct(Schema.Struct({
1212
type: Schema.Literal("security"),
1313
vulnerabilities: Schema.Array(Schema.String),
1414
riskLevel: Lmh,
@@ -19,7 +19,7 @@ const security = L.assistant(Schema.Struct({
1919
messages: undefined,
2020
})))
2121

22-
const performance = L.assistant(Schema.Struct({
22+
const performance = L.assistantStruct(Schema.Struct({
2323
type: Schema.Literal("performance"),
2424
issues: Schema.Array(Schema.String),
2525
impact: Lmh,
@@ -30,7 +30,7 @@ const performance = L.assistant(Schema.Struct({
3030
messages: undefined,
3131
})))
3232

33-
const maintainability = L.assistant(Schema.Struct({
33+
const maintainability = L.assistantStruct(Schema.Struct({
3434
type: Schema.Literal("maintainability"),
3535
concerns: Schema.Array(Schema.String),
3636
qualityScore: Schema.Int,
@@ -51,7 +51,7 @@ Effect.gen(function*() {
5151
})
5252
yield* L.user(JSON.stringify(Object.values(reviews), null, 2))
5353
yield* L.user`You are a technical lead summarizing multiple code reviews.`
54-
const summary = yield* L.assistant()
54+
const summary = yield* L.assistantText
5555
return { reviews, summary }
5656
}).pipe(
5757
Effect.provide(Strand.layer({

examples/routing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const USE_CLASSIFICATION_PROMPTS = {
1616
await Effect.gen(function*() {
1717
const classification = yield* Effect.gen(function*() {
1818
yield* L.user`I'd like a refund please.`
19-
return yield* L.assistant(Schema.Struct({
19+
return yield* L.assistantStruct(Schema.Struct({
2020
reasoning: Schema.String,
2121
type: Schema.Literal("general", "refund", "technical"),
2222
complexity: Schema.Literal("simple", "complex"),
@@ -32,7 +32,7 @@ await Effect.gen(function*() {
3232
3. Brief reasoning for classification
3333
`,
3434
})))
35-
const response = L.assistant().pipe(
35+
const response = L.assistantText.pipe(
3636
Effect.provide(Strand.layer({
3737
system: USE_CLASSIFICATION_PROMPTS[classification.type],
3838
})),

examples/self_talk.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import { common } from "./_common.ts"
66
await Effect
77
.gen(function*() {
88
yield* L.user`Decide on a subtopic for us to discuss within the domain of technological futurism.`
9-
yield* L.assistant()
9+
yield* L.assistantText
1010
yield* L.user`Great, please teach something interesting about this choice of subtopic.`
11-
yield* L.assistant()
11+
yield* L.assistantText
1212
let i = 0
1313
while (i < 3) {
1414
const reply = yield* Effect
1515
.gen(function*() {
1616
yield* L.user`Please reply to the last message on my behalf.`
17-
return yield* L.assistant()
17+
return yield* L.assistantText
1818
})
1919
.pipe(Effect.provide(Strand.layer()))
2020
yield* L.user(reply)
21-
yield* L.assistant()
21+
yield* L.assistantText
2222
i++
2323
}
2424
yield* L.user`Please summarize the key points from our conversation.`
25-
return yield* L.assistant()
25+
return yield* L.assistantText
2626
})
2727
.pipe(
2828
Effect.provide(Strand.layer({

examples/trip_planner.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ await Effect.gen(function*() {
1313
I want to plan a weekend trip leaving from ${DEPARTURE_LOCATION}. I don't know where to go.
1414
Suggest some follow-up questions that will help you narrow down the possible destination.
1515
`
16-
const { questions } = yield* L.assistant(Schema.Struct({
17-
questions: Schema.Array(Schema.String),
18-
}))
16+
const { questions } = yield* L.assistantStruct(
17+
Schema.Struct({
18+
questions: Schema.Array(Schema.String),
19+
}),
20+
)
1921
yield* L.user`Here are my answers to those questions:`
2022
const terminal = yield* Terminal.Terminal
2123
for (const question of questions) {
@@ -27,9 +29,9 @@ await Effect.gen(function*() {
2729
`
2830
}
2931
yield* L.user`Now that we've refined the destination criteria, please provide a single recommendation.`
30-
yield* L.assistant()
32+
yield* L.assistantText
3133
yield* L.user`Where can I stay there, what can I do there, how do I get there?`
32-
return yield* L.assistant()
34+
return yield* L.assistantText
3335
}).pipe(
3436
Effect.provide(Strand.layer({
3537
onMessage: Console.log,

0 commit comments

Comments
 (0)