xai.ts 661 B

12345678910111213141516171819202122
  1. import { Effect } from "effect"
  2. import { define } from "../internal"
  3. import { ProviderV2 } from "../../provider"
  4. export const XAIPlugin = define({
  5. id: "xai",
  6. effect: Effect.fn(function* (ctx) {
  7. yield* ctx.aisdk.sdk(
  8. Effect.fn(function* (evt) {
  9. if (evt.package !== "@ai-sdk/xai") return
  10. const mod = yield* Effect.promise(() => import("@ai-sdk/xai"))
  11. evt.sdk = mod.createXai(evt.options)
  12. }),
  13. )
  14. yield* ctx.aisdk.language(
  15. Effect.fn(function* (evt) {
  16. if (evt.model.providerID !== ProviderV2.ID.make("xai")) return
  17. evt.language = evt.sdk.responses(evt.model.api.id)
  18. }),
  19. )
  20. }),
  21. })