provider-togetherai.test.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { PluginV2 } from "@opencode-ai/core/plugin"
  4. import { TogetherAIPlugin } from "@opencode-ai/core/plugin/provider/togetherai"
  5. import { fakeSelectorSdk, it, model } from "./provider-helper"
  6. describe("TogetherAIPlugin", () => {
  7. it.effect("creates a TogetherAI SDK for @ai-sdk/togetherai", () =>
  8. Effect.gen(function* () {
  9. const plugin = yield* PluginV2.Service
  10. yield* plugin.add(TogetherAIPlugin)
  11. const result = yield* plugin.trigger(
  12. "aisdk.sdk",
  13. { model: model("togetherai", "model"), package: "@ai-sdk/togetherai", options: { name: "togetherai" } },
  14. {},
  15. )
  16. expect(result.sdk).toBeDefined()
  17. }),
  18. )
  19. it.effect("matches the old bundled provider package exactly", () =>
  20. Effect.gen(function* () {
  21. const plugin = yield* PluginV2.Service
  22. yield* plugin.add(TogetherAIPlugin)
  23. const ignored = yield* plugin.trigger(
  24. "aisdk.sdk",
  25. {
  26. model: model("togetherai", "model"),
  27. package: "file:///tmp/@ai-sdk/togetherai-provider.js",
  28. options: { name: "togetherai" },
  29. },
  30. {},
  31. )
  32. expect(ignored.sdk).toBeUndefined()
  33. const result = yield* plugin.trigger(
  34. "aisdk.sdk",
  35. { model: model("togetherai", "model"), package: "@ai-sdk/togetherai", options: { name: "togetherai" } },
  36. {},
  37. )
  38. expect(result.sdk).toBeDefined()
  39. }),
  40. )
  41. it.effect("creates bundled TogetherAI SDKs for custom provider IDs", () =>
  42. Effect.gen(function* () {
  43. const plugin = yield* PluginV2.Service
  44. const observed: string[] = []
  45. yield* plugin.add(TogetherAIPlugin)
  46. yield* plugin.add({
  47. id: PluginV2.ID.make("inspector"),
  48. effect: Effect.succeed({
  49. "aisdk.sdk": (evt) =>
  50. Effect.sync(() => {
  51. observed.push(evt.sdk.languageModel("model").provider)
  52. }),
  53. }),
  54. })
  55. yield* plugin.trigger(
  56. "aisdk.sdk",
  57. {
  58. model: model("custom-togetherai", "model"),
  59. package: "@ai-sdk/togetherai",
  60. options: { name: "custom-togetherai" },
  61. },
  62. {},
  63. )
  64. expect(observed).toEqual(["togetherai.chat"])
  65. }),
  66. )
  67. it.effect("defaults language selection to sdk.languageModel with the model API ID", () =>
  68. Effect.gen(function* () {
  69. const plugin = yield* PluginV2.Service
  70. const calls: string[] = []
  71. yield* plugin.add(TogetherAIPlugin)
  72. const result = yield* plugin.trigger(
  73. "aisdk.language",
  74. {
  75. model: model("togetherai", "meta-llama/Llama-3.3-70B-Instruct-Turbo"),
  76. sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
  77. options: {},
  78. },
  79. {},
  80. )
  81. expect(result.language).toBeUndefined()
  82. expect(calls).toEqual([])
  83. expect(result.language ?? fakeSelectorSdk(calls).languageModel(result.model.apiID)).toBeDefined()
  84. expect(calls).toEqual(["languageModel:meta-llama/Llama-3.3-70B-Instruct-Turbo"])
  85. }),
  86. )
  87. })