Effect AI SDK
Integrate Linkora using the Effect AI SDK
Effect AI SDK
You can use the Effect AI SDK to integrate Linkora with your Effect applications. To get started, install the following packages:
- effect: the Effect core (if not already installed)
- @effect/ai: the core Effect AI SDK abstractions
- @effect/ai-linkora: the Effect AI provider integration for Linkora
- @effect/platform: platform-agnostic abstractions for Effect
npm install effect @effect/ai @effect/ai-linkora @effect/platformOnce that's done you can use the LanguageModel module to define interactions with a large language model via Linkora.
import { LanguageModel } from "@effect/ai"
import { LinkoraClient, LinkoraLanguageModel } from "@effect/ai-linkora"
import { FetchHttpClient } from "@effect/platform"
import { Config, Effect, Layer, Stream } from "effect"
const Gpt4o = LinkoraLanguageModel.model("openai/gpt-4o")
const program = LanguageModel.streamText({
prompt: [
{ role: "system", content: "You are a comedian with a penchant for groan-inducing puns" },
{ role: "user", content: [{ type: "text", text: "Tell me a dad joke" }] }
]
}).pipe(
Stream.filter((part) => part.type === "text-delta"),
Stream.runForEach((part) => Effect.sync(() => process.stdout.write(part.delta))),
Effect.provide(Gpt4o)
)
const Linkora = LinkoraClient.layerConfig({
apiKey: Config.redacted("LINKORA_API_KEY")
}).pipe(Layer.provide(FetchHttpClient.layer))
program.pipe(
Effect.provide(Linkora),
Effect.runPromise
)