Skip to content

align AiPlan constructor to fallback #4781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

mikearnaldi
Copy link
Member

@mikearnaldi mikearnaldi commented Apr 23, 2025

import { AiLanguageModel, AiModels, AiPlan } from "@effect/ai"
import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic"
import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai"
import { FetchHttpClient, PlatformConfigProvider } from "@effect/platform"
import { BunContext, BunRuntime } from "@effect/platform-bun"
import { Config, Effect, Layer } from "effect"

const program = Effect.gen(function*() {
  const model = yield* AiLanguageModel.AiLanguageModel

  const response = yield* model.generateText({ prompt: "Tell me something nice about CityJS London!" })

  yield* Effect.log(response.text)
})

const main = Effect.gen(function*() {
  const plan = yield* AiPlan.make({
    model: OpenAiLanguageModel.model("gpt-4"),
    attempts: 1
  }, {
    model: AnthropicLanguageModel.model("claude-3-7-sonnet-latest"),
    attempts: 1
  }, {
    model: AnthropicLanguageModel.model("claude-3-5-sonnet-latest"),
    attempts: 1
  })

  yield* plan.use(program)
})

const layer = Layer.mergeAll(
  AiModels.layer,
  OpenAiClient.layerConfig({ apiKey: Config.redacted("OPENAI_API_KEY") }),
  AnthropicClient.layerConfig({ apiKey: Config.redacted("ANTHROPIC_API_KEY") })
)
  .pipe(Layer.provide(FetchHttpClient.layer))
  .pipe(Layer.provide(PlatformConfigProvider.layerDotEnv("scratchpad/cityjs-london/.env")))
  .pipe(Layer.provide(BunContext.layer))

BunRuntime.runMain(main.pipe(Effect.provide(layer)))

@mikearnaldi mikearnaldi requested a review from IMax153 April 23, 2025 12:54
@mikearnaldi mikearnaldi requested a review from tim-smart as a code owner April 23, 2025 12:54
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Apr 23, 2025
Copy link

changeset-bot bot commented Apr 23, 2025

⚠️ No Changeset found

Latest commit: 09f6555

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@IMax153
Copy link
Member

IMax153 commented Apr 23, 2025

Closing in favor of #4766

@IMax153 IMax153 closed this Apr 23, 2025
@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Done in PR Backlog Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants