provider-groq.test.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { AISDK } from "@opencode-ai/core/aisdk"
  2. import { describe, expect } from "bun:test"
  3. import { createGroq } from "@ai-sdk/groq"
  4. import { Effect } from "effect"
  5. import { ModelV2 } from "@opencode-ai/core/model"
  6. import { PluginV2 } from "@opencode-ai/core/plugin"
  7. import { PluginHost } from "@opencode-ai/core/plugin/host"
  8. import { GroqPlugin } from "@opencode-ai/core/plugin/provider/groq"
  9. import { ProviderV2 } from "@opencode-ai/core/provider"
  10. import { testEffect } from "../lib/effect"
  11. import { PluginTestLayer } from "./fixture"
  12. const it = testEffect(PluginTestLayer)
  13. const addPlugin = Effect.fn(function* () {
  14. const plugin = yield* PluginV2.Service
  15. const aisdk = yield* AISDK.Service
  16. const host = yield* PluginHost.make(plugin)
  17. yield* GroqPlugin.effect(host)
  18. })
  19. describe("GroqPlugin", () => {
  20. it.effect("creates a Groq SDK for @ai-sdk/groq", () =>
  21. Effect.gen(function* () {
  22. const plugin = yield* PluginV2.Service
  23. const aisdk = yield* AISDK.Service
  24. yield* addPlugin()
  25. const result = yield* aisdk.runSDK({
  26. model: ModelV2.Info.make({
  27. ...ModelV2.Info.empty(ProviderV2.ID.make("groq"), ModelV2.ID.make("llama")),
  28. api: { id: ModelV2.ID.make("llama"), type: "aisdk", package: "@ai-sdk/groq" },
  29. }),
  30. package: "@ai-sdk/groq",
  31. options: { name: "groq" },
  32. })
  33. expect(result.sdk).toBeDefined()
  34. }),
  35. )
  36. it.effect("ignores non-Groq SDK packages", () =>
  37. Effect.gen(function* () {
  38. const plugin = yield* PluginV2.Service
  39. const aisdk = yield* AISDK.Service
  40. yield* addPlugin()
  41. const result = yield* aisdk.runSDK({
  42. model: ModelV2.Info.make({
  43. ...ModelV2.Info.empty(ProviderV2.ID.make("groq"), ModelV2.ID.make("llama")),
  44. api: { id: ModelV2.ID.make("llama"), type: "aisdk", package: "@ai-sdk/groq" },
  45. }),
  46. package: "@ai-sdk/openai-compatible",
  47. options: { name: "groq" },
  48. })
  49. expect(result.sdk).toBeUndefined()
  50. }),
  51. )
  52. it.effect("only matches the bundled @ai-sdk/groq package exactly", () =>
  53. Effect.gen(function* () {
  54. const plugin = yield* PluginV2.Service
  55. const aisdk = yield* AISDK.Service
  56. yield* addPlugin()
  57. const result = yield* aisdk.runSDK({
  58. model: ModelV2.Info.make({
  59. ...ModelV2.Info.empty(ProviderV2.ID.make("groq"), ModelV2.ID.make("llama")),
  60. api: { id: ModelV2.ID.make("llama"), type: "aisdk", package: "@ai-sdk/groq" },
  61. }),
  62. package: "@ai-sdk/groq/compat",
  63. options: { name: "groq" },
  64. })
  65. expect(result.sdk).toBeUndefined()
  66. }),
  67. )
  68. it.effect("matches the old bundled Groq SDK provider naming", () =>
  69. Effect.gen(function* () {
  70. const plugin = yield* PluginV2.Service
  71. const aisdk = yield* AISDK.Service
  72. yield* addPlugin()
  73. const result = yield* aisdk.runSDK({
  74. model: ModelV2.Info.make({
  75. ...ModelV2.Info.empty(ProviderV2.ID.make("custom-groq"), ModelV2.ID.make("llama")),
  76. api: { id: ModelV2.ID.make("llama"), type: "aisdk", package: "@ai-sdk/groq" },
  77. }),
  78. package: "@ai-sdk/groq",
  79. options: { name: "custom-groq", apiKey: "test" },
  80. })
  81. const expected = createGroq({ name: "custom-groq", apiKey: "test" } as Parameters<typeof createGroq>[0] & {
  82. name: string
  83. }).languageModel("llama")
  84. const actual = result.sdk?.languageModel("llama")
  85. expect(actual?.provider).toBe(expected.provider)
  86. expect(actual?.modelId).toBe(expected.modelId)
  87. }),
  88. )
  89. it.effect("uses the default languageModel(api.id) behavior", () =>
  90. Effect.gen(function* () {
  91. const plugin = yield* PluginV2.Service
  92. const aisdk = yield* AISDK.Service
  93. yield* addPlugin()
  94. const sdk = createGroq({ name: "groq", apiKey: "test" } as Parameters<typeof createGroq>[0] & {
  95. name: string
  96. })
  97. const result = yield* aisdk.runLanguage({
  98. model: ModelV2.Info.make({
  99. ...ModelV2.Info.empty(ProviderV2.ID.make("groq"), ModelV2.ID.make("alias")),
  100. api: {
  101. id: ModelV2.ID.make("llama-api"),
  102. type: "aisdk",
  103. package: "@ai-sdk/groq",
  104. },
  105. }),
  106. sdk,
  107. options: { name: "groq", apiKey: "test" },
  108. })
  109. const language = result.language ?? sdk.languageModel(result.model.api.id)
  110. expect(language.modelId).toBe("llama-api")
  111. expect(language.provider).toBe("groq.chat")
  112. }),
  113. )
  114. })