Skip to content

Commit

Permalink
Update JSDoc for object mode. (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed May 6, 2024
1 parent 65ae681 commit 4d458df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/core/core/generate-object/generate-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ The schema of the object that the model should generate.
schema: z.Schema<T>;

/**
The mode to use for object generation. Not all models support all modes.
The mode to use for object generation.
The Zod schema is converted in a JSON schema and used in one of the following ways
- 'auto': The provider will choose the best mode for the model.
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
- 'json': The JSON schema and a instruction is injected into the prompt. If the provider supports JSON mode, it is enabled.
- 'grammar': The provider is instructed to converted the JSON schema into a provider specific grammar and use it to select the output tokens.
Please note that most providers do not support all modes.
Default and recommended: 'auto' (best mode for the model).
*/
Expand Down
13 changes: 11 additions & 2 deletions packages/core/core/generate-object/stream-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,19 @@ The schema of the object that the model should generate.
schema: z.Schema<T>;

/**
The mode to use for object generation. Not all models support all modes.
The mode to use for object generation.
The Zod schema is converted in a JSON schema and used in one of the following ways
- 'auto': The provider will choose the best mode for the model.
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
- 'json': The JSON schema and a instruction is injected into the prompt. If the provider supports JSON mode, it is enabled.
- 'grammar': The provider is instructed to converted the JSON schema into a provider specific grammar and use it to select the output tokens.
Please note that most providers do not support all modes.
Default and recommended: 'auto' (best mode for the model).
*/
*/
mode?: 'auto' | 'json' | 'tool' | 'grammar';
}): Promise<StreamObjectResult<T>> {
const retry = retryWithExponentialBackoff({ maxRetries });
Expand Down

0 comments on commit 4d458df

Please sign in to comment.