Skip to content

Commit

Permalink
Expose a type that lists the AiAdapter for each format (#756)
Browse files Browse the repository at this point in the history
## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

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
<!-- Tick these items off as you progress. -->
<!-- If an item isn't applicable, ideally please strikeout the item by
wrapping it in "~~"" and suffix it with "N/A My reason for skipping
this." -->
<!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" -->

- [ ] ~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
  • Loading branch information
jpwilliams authored Nov 25, 2024
1 parent 36b61f0 commit 7916c06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-cameras-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Expose a type that lists the `AiAdapter` for each format
16 changes: 15 additions & 1 deletion packages/inngest/src/components/ai/adapter.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<AiAdapter.Format, AiAdapter>;

/**
* All AI adapters available for use.
*/
export type AiAdapters = typeof adapters;
2 changes: 1 addition & 1 deletion packages/inngest/src/components/ai/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type { AiAdapter } from "./adapter.js";
export type { AiAdapter, AiAdapters } from "./adapter.js";

// Adapters
export * from "./adapters/openai.js";
Expand Down

0 comments on commit 7916c06

Please sign in to comment.