Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js/ai): swap out config as part of prompt/agent transfer #1944

Merged
merged 6 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions js/ai/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions js/ai/src/generate/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function applyTransferPreamble(
],
toolChoice: transferPreamble.toolChoice || rawRequest.toolChoice,
tools: transferPreamble.tools || rawRequest.tools,
config: transferPreamble.config || rawRequest.config,
});
}

Expand Down
7 changes: 6 additions & 1 deletion js/ai/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function definePromptAsync<
docs = resolvedOptions.docs;
}

return stripUndefinedProps({
const opts: GenerateOptions = stripUndefinedProps({
model: resolvedOptions.model,
maxTurns: resolvedOptions.maxTurns,
messages,
Expand All @@ -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<I, O, CustomOptions>) => {
Expand Down
6 changes: 5 additions & 1 deletion js/core/src/reflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions js/genkit/tests/chat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
4 changes: 1 addition & 3 deletions js/genkit/tests/prompts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
});
});
Expand Down Expand Up @@ -978,7 +977,6 @@ describe('definePrompt', () => {
const response = await hi.render({ name: 'Genkit' });
delete response.model; // ignore
assert.deepStrictEqual(response, {
config: {},
messages: [
{
content: [
Expand Down Expand Up @@ -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: [
Expand Down
Loading