Skip to content

Instantly share code, notes, and snippets.

@kiritocode1
Created August 16, 2025 18:50
Show Gist options
  • Save kiritocode1/47bc136e2aa31a17213357821929e9f8 to your computer and use it in GitHub Desktop.
Save kiritocode1/47bc136e2aa31a17213357821929e9f8 to your computer and use it in GitHub Desktop.
somehowitworks.ts
import { Config, Console, Effect, Layer, Schema } from "effect";
import { Prompt } from "@effect/cli";
import { AiChat, AiTool, AiToolkit } from "@effect/ai";
import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic";
import { BunContext, BunRuntime } from "@effect/platform-bun";
import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
import {OpenAiClient, OpenAiLanguageModel} from "@effect/ai-openai"
const ListToolInput = Schema.Struct({
path: Schema.String.annotations({description: "the absolute path to the file", default: process.cwd()})
})
const ListToolOutput = Schema.Struct({
files: Schema.Array(Schema.String),
directories: Schema.Array(Schema.String),
})
const ListTool = AiTool.make("List", {
description: "List the contents of a directory",
}).setParameters(ListToolInput)
.setSuccess(ListToolOutput)
const ToolKit = AiToolkit.make(ListTool)
const ToolKitLayer = ToolKit.toLayer({
List:({path})=> Effect.succeed({
files: ["index.ts"],
directories: ["node_modules"],
})
})
const main = Effect.gen(function* () {
const chat = yield* AiChat.fromPrompt({
prompt: [],
system: `
You are a helpful assistant that can answer questions and help with tasks.
You live in my terminal at ${process.cwd()}
You are made by Blank(https://aryank.space) , and u end messages with a :3`,
});
while (true) {
const input = yield* Prompt.text({
message: "What u want :3 ",
});
const response = yield* chat.generateText({
prompt: input,
toolkit: ToolKit,
});
yield* Console.log(response.text);
while (response.toolCalls.length > 0) {
const response =
yield *
chat.generateText({
prompt: input,
toolkit: ToolKit,
});
yield * Console.log(response.text);
}
}
});
const OpenAiLayer = OpenAiClient.layerConfig({
apiKey: Config.redacted("OPENAI_API_KEY"),
}).pipe(Layer.provide(FetchHttpClient.layer));
const OpenAiLayerAIResolver = OpenAiLanguageModel.model("gpt-4o-mini").pipe(Layer.provide(OpenAiLayer));
const AnthropicLayer = AnthropicClient.layerConfig({
apiKey: Config.redacted("ANTHROPIC_API_KEY"),
}).pipe(Layer.provide(FetchHttpClient.layer));
const ClaudeLayerAIResolver = AnthropicLanguageModel.model("claude-2.0").pipe(Layer.provide(AnthropicLayer));
const AiLayer = Layer.mergeAll(BunContext.layer, OpenAiLayerAIResolver, ToolKitLayer);
main.pipe(Effect.provide(AiLayer), BunRuntime.runMain);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment