[JS] TypeError: Cannot read properties of undefined (reading 'input') in `session.chat()` when loading prompt from dotpompt file
Describe the bug Loading a prompt from a dotprompt file and using it as input for a chat session results in the following error:
TypeError: Cannot read properties of undefined (reading 'input')
at AsyncFunction.executablePrompt.render ([..]/node_modules/genkit/src/genkit.ts:273:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async <anonymous> ([..]/node_modules/@genkit-ai/ai/src/chat.ts:167:17)
at async <anonymous> ([..]/node_modules/@genkit-ai/core/src/tracing/instrumentation.ts:115:24)
at async runInNewSpan ([..]/node_modules/@genkit-ai/core/src/tracing/instrumentation.ts:103:10)
at async Timeout.main ([..]/src/terminal.ts:125:20)
To Reproduce
File prompts/helloAgent.prompt:
You are the world's most welcoming AI assistant. Greet the user enthusiastically with a fun fact about flowers.
Typescript code:
const helloAgent = ai.prompt('helloAgent');
const chat = ai
.createSession()
.chat(helloAgent);
const { text } = await chat.send("hello!");
console.log(text);
Workaround
Adding options to the chat call that include an empty input property makes the chat call succeed and work as expected:
const helloAgent = ai.prompt('helloAgent');
const chatOptions = {
input: ''
}
const chat = ai
.createSession()
.chat(helloAgent, chatOptions);
const { text } = await chat.send("hello!");
console.log(text);
Expected behavior Loading a prompt from a dotprompt file should be supported for starting a chat interaction.
Other Notes
Using definePrompt(..) to programmatically define a prompt and using it for a chat interaction also works as expected. The issue appears to be related to how .prompt(..) initializes the prompt.
(I also tried defining input and output options in the dotprompt file without success.)
Runtime (please complete the following information): Firebase Studio (Linux)
Node version Node.js v20.18.1