provider-groq.test.ts 3.3 KB

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