Skip to content

Commit

Permalink
Merge branch 'main' into ktlo/ts-5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jpwilliams committed Nov 25, 2024
2 parents 7eb442f + 7916c06 commit 0f7ee98
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-jobs-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Fix OpenAI `tools` types - not properly scoped
5 changes: 5 additions & 0 deletions .changeset/sharp-donuts-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Fix false indeterminate function warning
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
22 changes: 22 additions & 0 deletions packages/inngest/src/components/InngestStepTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,29 @@ export interface FoundStep extends HashedOp {
hashedId: string;
fn?: (...args: unknown[]) => unknown;
rawArgs: unknown[];

/**
* A boolean representing whether the step has been fulfilled, either
* resolving or rejecting the `Promise` returned to userland code.
*
* Note that this is distinct from {@link hasStepState}, which instead tracks
* whether the step has been given some state from the Executor. State from
* the Executor could be data other than a resolution or rejection, such as
* inputs.
*/
fulfilled: boolean;

/**
* A boolean representing whether the step has been given some state from the
* Executor. State from the Executor could be data other than a resolution or
* rejection, such as inputs.
*
* This is distinct from {@link fulfilled}, which instead tracks whether the
* step has been fulfilled, either resolving or rejecting the `Promise`
* returned to userland code.
*/
hasStepState: boolean;

handled: boolean;

/**
Expand Down
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;
67 changes: 37 additions & 30 deletions packages/inngest/src/components/ai/adapters/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,40 +270,47 @@ export interface OpenAiAiAdapter extends AiAdapter {
*/
tools?: {
/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or
* contain underscores and dashes, with a maximum length of 64.
* The type of the tool.
*/
name: string;
type: "function";

/**
* A description of what the function does, used by the model to choose
* when and how to call the function.
*/
description?: string;
function: {
/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or
* contain underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema
* object. See the
* [guide](https://platform.openai.com/docs/guides/function-calling) for
* examples, and the [JSON Schema
* reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* Omitting `parameters` defines a function with an empty parameter
* list.
*/
parameters?: Record<string, unknown>;
/**
* A description of what the function does, used by the model to choose
* when and how to call the function.
*/
description?: string;

/**
* Whether to enable strict schema adherence when generating the
* function call. If set to true, the model will follow the exact schema
* defined in the `parameters field`. Only a subset of JSON Schema is
* supported when `strict` is `true`. Learn more about Structured
* Outputs in the function calling guide.
*
* @default false
*/
strict?: boolean;
/**
* The parameters the functions accepts, described as a JSON Schema
* object. See the
* [guide](https://platform.openai.com/docs/guides/function-calling) for
* examples, and the [JSON Schema
* reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* Omitting `parameters` defines a function with an empty parameter
* list.
*/
parameters?: Record<string, unknown>;

/**
* Whether to enable strict schema adherence when generating the
* function call. If set to true, the model will follow the exact schema
* defined in the `parameters field`. Only a subset of JSON Schema is
* supported when `strict` is `true`. Learn more about Structured
* Outputs in the function calling guide.
*
* @default false
*/
strict?: boolean;
};
}[];

/**
Expand Down
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.ts";
export type { AiAdapter, AiAdapters } from "./adapter.ts";

// Adapters
export * from "./adapters/openai.ts";
Expand Down
9 changes: 5 additions & 4 deletions packages/inngest/src/components/execution/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class V1InngestExecution extends InngestExecution implements IInngestExecution {
}

private async filterNewSteps(
steps: FoundStep[]
foundSteps: FoundStep[]
): Promise<[OutgoingOp, ...OutgoingOp[]] | void> {
if (this.options.requestedRunStep) {
return;
Expand All @@ -292,7 +292,7 @@ class V1InngestExecution extends InngestExecution implements IInngestExecution {
/**
* Gather any steps that aren't memoized and report them.
*/
const newSteps = steps.filter((step) => !step.fulfilled);
const newSteps = foundSteps.filter((step) => !step.fulfilled);

if (!newSteps.length) {
return;
Expand All @@ -303,8 +303,8 @@ class V1InngestExecution extends InngestExecution implements IInngestExecution {
* steps. This may indicate that step presence isn't determinate.
*/
const stepsToFulfil = Object.keys(this.state.stepState).length;
const fulfilledSteps = steps.filter((step) => step.fulfilled).length;
const foundAllCompletedSteps = stepsToFulfil === fulfilledSteps;
const knownSteps = foundSteps.filter((step) => step.hasStepState).length;
const foundAllCompletedSteps = stepsToFulfil === knownSteps;

if (!foundAllCompletedSteps) {
// TODO Tag
Expand Down Expand Up @@ -908,6 +908,7 @@ class V1InngestExecution extends InngestExecution implements IInngestExecution {
fn: opts?.fn ? () => opts.fn?.(...fnArgs) : undefined,
promise,
fulfilled: isFulfilled,
hasStepState: Boolean(stepState),
displayName: opId.displayName ?? opId.id,
handled: false,
handle: async () => {
Expand Down

0 comments on commit 0f7ee98

Please sign in to comment.