From 4d458dfd1806e793b7b14acddb56ff48517b3b41 Mon Sep 17 00:00:00 2001 From: Lars Grammel Date: Mon, 6 May 2024 18:43:26 +0200 Subject: [PATCH] Update JSDoc for object mode. (#1476) --- .../core/core/generate-object/generate-object.ts | 11 ++++++++++- packages/core/core/generate-object/stream-object.ts | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/core/core/generate-object/generate-object.ts b/packages/core/core/generate-object/generate-object.ts index 75e501b49d5..5a0ab7acdbf 100644 --- a/packages/core/core/generate-object/generate-object.ts +++ b/packages/core/core/generate-object/generate-object.ts @@ -71,7 +71,16 @@ The schema of the object that the model should generate. schema: z.Schema; /** -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). */ diff --git a/packages/core/core/generate-object/stream-object.ts b/packages/core/core/generate-object/stream-object.ts index 631ae240135..84c2c3b2220 100644 --- a/packages/core/core/generate-object/stream-object.ts +++ b/packages/core/core/generate-object/stream-object.ts @@ -80,10 +80,19 @@ The schema of the object that the model should generate. schema: z.Schema; /** -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> { const retry = retryWithExponentialBackoff({ maxRetries });