provider-groq.test.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { describe, expect } from "bun:test"
  2. import { createGroq } from "@ai-sdk/groq"
  3. import { Effect, Layer } from "effect"
  4. import { AISDK } from "@opencode-ai/core/aisdk"
  5. import { EventV2 } from "@opencode-ai/core/event"
  6. import { ModelV2 } from "@opencode-ai/core/model"
  7. import { PluginV2 } from "@opencode-ai/core/plugin"
  8. import { GroqPlugin } from "@opencode-ai/core/plugin/provider/groq"
  9. import { it, model } from "./provider-helper"
  10. import { testEffect } from "../lib/effect"
  11. const aisdkIt = testEffect(
  12. AISDK.layer.pipe(Layer.provideMerge(PluginV2.locationLayer.pipe(Layer.provide(EventV2.defaultLayer)))),
  13. )
  14. describe("GroqPlugin", () => {
  15. it.effect("creates a Groq SDK for @ai-sdk/groq", () =>
  16. Effect.gen(function* () {
  17. const plugin = yield* PluginV2.Service
  18. yield* plugin.add(GroqPlugin)
  19. const result = yield* plugin.trigger(
  20. "aisdk.sdk",
  21. { model: model("groq", "llama"), package: "@ai-sdk/groq", options: { name: "groq" } },
  22. {},
  23. )
  24. expect(result.sdk).toBeDefined()
  25. }),
  26. )
  27. it.effect("ignores non-Groq SDK packages", () =>
  28. Effect.gen(function* () {
  29. const plugin = yield* PluginV2.Service
  30. yield* plugin.add(GroqPlugin)
  31. const result = yield* plugin.trigger(
  32. "aisdk.sdk",
  33. { model: model("groq", "llama"), package: "@ai-sdk/openai-compatible", options: { name: "groq" } },
  34. {},
  35. )
  36. expect(result.sdk).toBeUndefined()
  37. }),
  38. )
  39. it.effect("only matches the bundled @ai-sdk/groq package exactly", () =>
  40. Effect.gen(function* () {
  41. const plugin = yield* PluginV2.Service
  42. yield* plugin.add(GroqPlugin)
  43. const result = yield* plugin.trigger(
  44. "aisdk.sdk",
  45. { model: model("groq", "llama"), package: "@ai-sdk/groq/compat", options: { name: "groq" } },
  46. {},
  47. )
  48. expect(result.sdk).toBeUndefined()
  49. }),
  50. )
  51. it.effect("matches the old bundled Groq SDK provider naming", () =>
  52. Effect.gen(function* () {
  53. const plugin = yield* PluginV2.Service
  54. yield* plugin.add(GroqPlugin)
  55. const result = yield* plugin.trigger(
  56. "aisdk.sdk",
  57. {
  58. model: model("custom-groq", "llama"),
  59. package: "@ai-sdk/groq",
  60. options: { name: "custom-groq", apiKey: "test" },
  61. },
  62. {},
  63. )
  64. const expected = createGroq({ name: "custom-groq", apiKey: "test" } as Parameters<typeof createGroq>[0] & {
  65. name: string
  66. }).languageModel("llama")
  67. const actual = result.sdk?.languageModel("llama")
  68. expect(actual?.provider).toBe(expected.provider)
  69. expect(actual?.modelId).toBe(expected.modelId)
  70. }),
  71. )
  72. aisdkIt.effect("uses the default languageModel(api.id) behavior", () =>
  73. Effect.gen(function* () {
  74. const plugin = yield* PluginV2.Service
  75. const aisdk = yield* AISDK.Service
  76. yield* plugin.add(GroqPlugin)
  77. const result = yield* aisdk.language(
  78. model("groq", "alias", {
  79. api: {
  80. id: ModelV2.ID.make("llama-api"),
  81. type: "aisdk",
  82. package: "@ai-sdk/groq",
  83. },
  84. request: {
  85. headers: {},
  86. body: { apiKey: "test" },
  87. },
  88. }),
  89. )
  90. expect(result.modelId).toBe("llama-api")
  91. expect(result.provider).toBe("groq.chat")
  92. }),
  93. )
  94. })