From 7916c066296a858e3b65cfddd0af4ba51689a3ef Mon Sep 17 00:00:00 2001 From: Jack Williams Date: Mon, 25 Nov 2024 13:37:35 +0000 Subject: [PATCH] Expose a type that lists the `AiAdapter` for each format (#756) ## Summary Exposes an `AiAdapter` for each `AiAdapter.Format` such that downstream packages can understand if parsers and typing is available and strictly adhere to the latest definitions in this package. ## Checklist - [ ] ~Added a [docs PR](https://github.com/inngest/website) that references this PR~ N/A Internal - [ ] ~Added unit/integration tests~ N/A Internal typing - [x] Added changesets if applicable --- .changeset/warm-cameras-yell.md | 5 +++++ packages/inngest/src/components/ai/adapter.ts | 16 +++++++++++++++- packages/inngest/src/components/ai/index.ts | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/warm-cameras-yell.md diff --git a/.changeset/warm-cameras-yell.md b/.changeset/warm-cameras-yell.md new file mode 100644 index 00000000..2d793b1a --- /dev/null +++ b/.changeset/warm-cameras-yell.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Expose a type that lists the `AiAdapter` for each format diff --git a/packages/inngest/src/components/ai/adapter.ts b/packages/inngest/src/components/ai/adapter.ts index eca939e1..ab195425 100644 --- a/packages/inngest/src/components/ai/adapter.ts +++ b/packages/inngest/src/components/ai/adapter.ts @@ -1,3 +1,5 @@ +import { type OpenAiAiAdapter } from "./adapters/openai.js"; + /** * A symbol used internally to define the types for a model whilst keeping * generics clean. Must not be exported outside of this module. @@ -60,7 +62,7 @@ export interface AiAdapter { /** * The model to use for the inference. */ - model: this, + model: AiAdapter, /** * The input to pass to the model. @@ -100,3 +102,15 @@ export namespace AiAdapter { TOutput extends AiAdapter, > = (...args: TInput) => TOutput; } + +/** + * A cheeky hack to ensure we account for all AI adapters. + */ +const adapters = { + "openai-chat": null as unknown as OpenAiAiAdapter, +} satisfies Record; + +/** + * All AI adapters available for use. + */ +export type AiAdapters = typeof adapters; diff --git a/packages/inngest/src/components/ai/index.ts b/packages/inngest/src/components/ai/index.ts index 0ad47c01..97f9e7c8 100644 --- a/packages/inngest/src/components/ai/index.ts +++ b/packages/inngest/src/components/ai/index.ts @@ -1,4 +1,4 @@ -export type { AiAdapter } from "./adapter.js"; +export type { AiAdapter, AiAdapters } from "./adapter.js"; // Adapters export * from "./adapters/openai.js";