Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
APP_URL=
CLERK_SECRET=
OPENAI_API_KEY=
VITE_CLERK_PUBLISHABLE_KEY=
VITE_SERVER_URL=
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- run: bun install
- uses: dprint/check@v2.2
- run: bun run build
- run: bun test
- run: bun run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
.env
dist
liminal.land/.vitepress/cache
liminal.land/.vitepress/dist
node_modules
repomix-output.xml
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"[typescriptreact]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[vue]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[yaml]": {
"editor.defaultFormatter": "dprint.dprint"
},
Expand Down
30 changes: 27 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,46 @@
{
"label": "tsc",
"type": "shell",
"command": "tsc -b -w",
"command": "bun build:watch",
"problemMatcher": []
},
{
"label": "vite",
"label": "vitest",
"type": "shell",
"command": "bun test:watch",
"problemMatcher": []
},
{
"label": "docs",
"type": "shell",
"command": "bunx vitepress",
"options": {
"cwd": "liminal.land"
},
"problemMatcher": []
},
{
"label": "client",
"type": "shell",
"command": "bunx vite",
"options": {
"cwd": "liminal.im/client"
},
"problemMatcher": []
},
{
"label": "server",
"type": "shell",
"command": "bun --env-file '../../.env' main",
"options": {
"cwd": "liminal.im/server"
},
"problemMatcher": []
},
{
"label": "dev",
"type": "shell",
"dependsOn": ["tsc", "vite"],
"dependsOn": ["tsc", "vitest", "docs", "server", "client"],
"problemMatcher": []
}
]
Expand Down
10 changes: 10 additions & 0 deletions alchemy.run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import alchemy from "alchemy"
import { CloudflareStateStore } from "alchemy/state"

const app = await alchemy("liminal", {
stateStore: (scope) => new CloudflareStateStore(scope),
})

// TODO

await app.finalize()
1,229 changes: 1,171 additions & 58 deletions bun.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"semiColons": "asi"
},
"plugins": [
"https://plugins.dprint.dev/g-plane/markup_fmt-v0.19.0.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm",
"https://plugins.dprint.dev/markdown-0.18.0.wasm",
"https://plugins.dprint.dev/g-plane/markup_fmt-v0.23.1.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm",
"https://plugins.dprint.dev/markdown-0.19.0.wasm",
"https://plugins.dprint.dev/exec-0.5.1.json@492414e39dea4dccc07b4af796d2f4efdb89e84bae2bd4e1e924c0cc050855bf",
"https://plugins.dprint.dev/typescript-0.94.0.wasm",
"https://plugins.dprint.dev/typescript-0.95.9.wasm",
"https://plugins.dprint.dev/json-0.20.0.wasm",
"https://plugins.dprint.dev/g-plane/malva-v0.11.2.wasm"
"https://plugins.dprint.dev/g-plane/malva-v0.14.1.wasm"
],
"excludes": [".changeset/*.md", "CHANGELOG.md"]
}
6 changes: 3 additions & 3 deletions examples/_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai"
import { FetchHttpClient } from "@effect/platform"
import { Config, Layer } from "effect"

export const client = OpenAiClient.layerConfig({
export const ClientLive = OpenAiClient.layerConfig({
apiKey: Config.redacted("OPENAI_API_KEY"),
}).pipe(
Layer.provide(FetchHttpClient.layer),
)

export const model = OpenAiLanguageModel.model("gpt-4o-mini").pipe(
Layer.provide(client),
export const ModelLive = OpenAiLanguageModel.model("gpt-4o-mini").pipe(
Layer.provide(ClientLive),
)
4 changes: 2 additions & 2 deletions examples/_logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Console, Effect, flow, Stream } from "effect"
import { L, pretty } from "liminal"
import { L, LPretty } from "liminal"

export const logger = L.events.pipe(
Stream.runForEach(
flow(
pretty,
LPretty.event,
Console.log,
Effect.andThen(Console.log()),
),
Expand Down
6 changes: 3 additions & 3 deletions examples/activity_suggestions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect, Schema } from "effect"
import { L } from "liminal"
import { model } from "./_layers.ts"
import { ModelLive } from "./_layers.ts"
import { logger } from "./_logger.ts"

const Activity = Schema.Struct({
Expand All @@ -24,6 +24,6 @@ Effect.gen(function*() {
}
}).pipe(
L.strand,
Effect.provide(model),
Effect.runPromise,
Effect.provide(ModelLive),
Effect.runFork,
)
6 changes: 3 additions & 3 deletions examples/chaining.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect, Schema } from "effect"
import { L } from "liminal"
import { model } from "./_layers.ts"
import { ModelLive } from "./_layers.ts"
import { logger } from "./_logger.ts"

Effect.gen(function*() {
Expand Down Expand Up @@ -37,6 +37,6 @@ Effect.gen(function*() {
return { copy, qualityMetrics }
}).pipe(
L.strand,
Effect.provide(model),
Effect.runPromise,
Effect.provide(ModelLive),
Effect.runFork,
)
10 changes: 4 additions & 6 deletions examples/compare_models.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAiLanguageModel } from "@effect/ai-openai"
import { Effect, Layer, Schema } from "effect"
import { Effect, Schema } from "effect"
import { L } from "liminal"
import { client, model } from "./_layers.ts"
import { ClientLive, ModelLive } from "./_layers.ts"
import { logger } from "./_logger.ts"

Effect.gen(function*() {
Expand Down Expand Up @@ -32,8 +32,6 @@ Effect.gen(function*() {
return variants[key]
}).pipe(
L.strand,
Effect.provide(
Layer.merge(model, client),
),
Effect.runPromise,
Effect.provide([ModelLive, ClientLive]),
Effect.runFork,
)
55 changes: 55 additions & 0 deletions examples/documentation_qa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Command, FileSystem } from "@effect/platform"
import { BunContext } from "@effect/platform-bun"
import { Effect, flow, Schema } from "effect"
import * as Console from "effect/Console"
import { L } from "liminal"
import { ModelLive } from "./_layers.ts"

declare const LIB_DIR: string
declare const DOCS_DIR: string

const Suggestions = Schema.Struct({
suggestions: Schema.Option(
Schema.Array(
Schema.String.pipe(Schema.annotations({
description: "Improvements to be made to the document.",
})),
),
),
})

Effect.gen(function*() {
yield* L.user`I'm about to provide you with a repomix summary of the current codebase.`

yield* Command.string(Command.make("bunx", "repomix", LIB_DIR))
const fs = yield* FileSystem.FileSystem
yield* L.user(fs.readFileString("repomix-output.xml"))

const docPaths = yield* fs.readDirectory(DOCS_DIR)
const suggestions = yield* Effect.all(docPaths.map(flow(
Effect.fn(function*(docPath) {
yield* L.user`
Based on this provided repomix overview, please consider the document's
effectiveness and potentially suggest improvements.

Specifically I'd like to know:

A. Is the document sufficient for the purposes of this library?
B. If not, what suggestions do you have for improvement?

The document:

${fs.readFileString(docPath)}
`
const maybeChanges = yield* L.assistantStruct(Suggestions)
return [docPath, maybeChanges] as const
}),
L.branch,
)))

yield* Console.log(suggestions)
}).pipe(
L.strand,
Effect.provide([ModelLive, BunContext.layer]),
Effect.runFork,
)
21 changes: 21 additions & 0 deletions examples/jsonc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Array, Console, Effect, Schema } from "effect"
import { L, LPretty } from "liminal"

const ExampleSchema = Schema.Struct({
inner: Schema.String.pipe(
Schema.annotations({
jsonSchema: {
description: "Some description for the LLM.",
},
}),
),
})

Effect.gen(function*() {
yield* L.userJson({ inner: "value" }, ExampleSchema)
const message = yield* yield* L.messages.pipe(Effect.map(Array.head))
yield* Console.log(LPretty.message(message))
}).pipe(
L.strand,
Effect.runFork,
)
11 changes: 7 additions & 4 deletions examples/optimizer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Terminal } from "@effect/platform"
import { BunContext } from "@effect/platform-bun"
import { Effect, Schema } from "effect"
import { L } from "liminal"
import { model } from "./_layers.ts"
import { ModelLive } from "./_layers.ts"
import { logger } from "./_logger.ts"

const TEXT = "..."
Expand All @@ -13,7 +15,8 @@ Effect.gen(function*() {
specified target language, preserving tone and cultural nuances.
`
yield* L.user`Target language: typescript`
yield* L.user`Text:\n\n${TEXT}`
const term = yield* Terminal.Terminal
yield* L.user`Text:\n\n${term.readLine}`
let currentTranslation = yield* L.assistant
let iterations = 0
const MAX_ITERATIONS = 3
Expand Down Expand Up @@ -64,6 +67,6 @@ Effect.gen(function*() {
}
}).pipe(
L.strand,
Effect.provide(model),
Effect.runPromise,
Effect.provide([ModelLive, BunContext.layer]),
Effect.runFork,
)
9 changes: 4 additions & 5 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"private": true,
"type": "module",
"dependencies": {
"@effect/ai": "^0.18.2",
"@effect/ai-openai": "^0.21.2",
"@effect/platform-bun": "^0.67.3",
"@effect/platform-node": "^0.84.2",
"effect": "^3.17.4",
"@effect/ai": "^0.25.0",
"@effect/ai-openai": "^0.21.16",
"@effect/platform-bun": "^0.77.0",
"effect": "^3.17.5",
"liminal": "workspace:*"
}
}
14 changes: 6 additions & 8 deletions examples/parallel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FileSystem, Path } from "@effect/platform"
import { BunContext } from "@effect/platform-bun"
import { Effect, Layer, Schema } from "effect"
import { Console, Effect, Schema } from "effect"
import { L } from "liminal"
import { model } from "./_layers.ts"
import { ModelLive } from "./_layers.ts"

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

Expand Down Expand Up @@ -70,10 +70,8 @@ Effect.gen(function*() {
L.assistant,
)

return { reviews, summary }
yield* Console.log({ reviews, summary })
}).pipe(
Effect.provide(
Layer.merge(BunContext.layer, model),
),
Effect.runPromise,
).then(console.log)
Effect.provide([ModelLive, BunContext.layer]),
Effect.runFork,
)
24 changes: 9 additions & 15 deletions examples/reducing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect } from "effect"
import { L } from "liminal"
import { model } from "./_layers.ts"
import { ModelLive } from "./_layers.ts"
import { logger } from "./_logger.ts"

Effect.gen(function*() {
Expand All @@ -19,23 +19,17 @@ Effect.gen(function*() {
yield* L.user`Any advice for me as I further-explore this project?`
yield* L.assistant

yield* Effect.gen(function*() {
const summary = yield* L.strand(
L.user`Please summarize our conversation.`,
L.assistant,
)

// @effect-diagnostics-next-line returnEffectInGen:off
return Effect.gen(function*() {
yield* L.user`Let's resume our discussion from the following summary`
yield* L.user(summary)
})
}).pipe(L.reduce)
const summary = yield* L.strand(
L.user`Please summarize our conversation.`,
L.assistant,
)
yield* L.clear
yield* L.user`Let's resume our discussion from the following summary: ${summary}`

yield* L.user`So please reiterate your thoughts on this creative journey.`
yield* L.assistant
}).pipe(
L.strand,
Effect.provide(model),
Effect.runPromise,
Effect.provide(ModelLive),
Effect.runFork,
)
Loading