diff --git a/js/ai/src/generate.ts b/js/ai/src/generate.ts index 8d9a1766f..c609b4860 100755 --- a/js/ai/src/generate.ts +++ b/js/ai/src/generate.ts @@ -377,6 +377,10 @@ export async function generate< returnToolRequests: resolvedOptions.returnToolRequests, maxTurns: resolvedOptions.maxTurns, }; + // if config is empty and it was not explicitly passed in, we delete it, don't want {} + if (Object.keys(params.config).length === 0 && !resolvedOptions.config) { + delete params.config; + } return await runWithStreamingCallback( registry, diff --git a/js/ai/src/generate/action.ts b/js/ai/src/generate/action.ts index 2dc71bf8a..7e8065c42 100644 --- a/js/ai/src/generate/action.ts +++ b/js/ai/src/generate/action.ts @@ -218,6 +218,7 @@ function applyTransferPreamble( ], toolChoice: transferPreamble.toolChoice || rawRequest.toolChoice, tools: transferPreamble.tools || rawRequest.tools, + config: transferPreamble.config || rawRequest.config, }); } diff --git a/js/ai/src/prompt.ts b/js/ai/src/prompt.ts index 58efc1ad7..c49e51f9b 100644 --- a/js/ai/src/prompt.ts +++ b/js/ai/src/prompt.ts @@ -293,7 +293,7 @@ function definePromptAsync< docs = resolvedOptions.docs; } - return stripUndefinedProps({ + const opts: GenerateOptions = stripUndefinedProps({ model: resolvedOptions.model, maxTurns: resolvedOptions.maxTurns, messages, @@ -310,6 +310,11 @@ function definePromptAsync< ...renderOptions?.config, }, }); + // if config is empty and it was not explicitly passed in, we delete it, don't want {} + if (Object.keys(opts.config).length === 0 && !renderOptions?.config) { + delete opts.config; + } + return opts; }; const rendererActionConfig = lazy(() => optionsPromise.then((options: PromptConfig) => { diff --git a/js/core/src/reflection.ts b/js/core/src/reflection.ts index 5cbb4ae61..feb1f39a6 100644 --- a/js/core/src/reflection.ts +++ b/js/core/src/reflection.ts @@ -20,7 +20,11 @@ import getPort, { makeRange } from 'get-port'; import { Server } from 'http'; import path from 'path'; import * as z from 'zod'; -import { Status, StatusCodes, runWithStreamingCallback } from './action.js'; +import { + StatusCodes, + runWithStreamingCallback, + type Status, +} from './action.js'; import { GENKIT_REFLECTION_API_SPEC_VERSION, GENKIT_VERSION } from './index.js'; import { logger } from './logging.js'; import { Registry } from './registry.js'; diff --git a/js/genkit/tests/chat_test.ts b/js/genkit/tests/chat_test.ts index 501ede1b3..7be76ded7 100644 --- a/js/genkit/tests/chat_test.ts +++ b/js/genkit/tests/chat_test.ts @@ -290,8 +290,7 @@ describe('preamble', () => { assert.deepStrictEqual(text, 'hi from agent b (toolChoice: required)'); assert.deepStrictEqual(pm.lastRequest, { config: { - // TODO: figure out if config should be swapped out as well... - temperature: 2, + temperature: 1, }, messages: [ { diff --git a/js/genkit/tests/prompts_test.ts b/js/genkit/tests/prompts_test.ts index 3f4ea276e..14f4dbf83 100644 --- a/js/genkit/tests/prompts_test.ts +++ b/js/genkit/tests/prompts_test.ts @@ -676,7 +676,6 @@ describe('definePrompt', () => { const response = await hi.render({ name: 'Genkit' }); delete response.model; // ignore assert.deepStrictEqual(response, { - config: {}, messages: [{ content: [{ text: 'hi Genkit' }], role: 'user' }], }); }); @@ -978,7 +977,6 @@ describe('definePrompt', () => { const response = await hi.render({ name: 'Genkit' }); delete response.model; // ignore assert.deepStrictEqual(response, { - config: {}, messages: [ { content: [ @@ -1369,8 +1367,8 @@ describe('asTool', () => { assert.deepStrictEqual(text, 'hi from agent b'); assert.deepStrictEqual(pm.lastRequest, { + // Original config, toolPrompt has no config. config: { - // TODO: figure out if config should be swapped out as well... temperature: 2, }, messages: [