I am trying to use Firebase Genkit.
I see here that I can use:
import { generate } from '@genkit-ai/ai';
generate({
model: 'googleai/gemini-1.5-flash-latest',
prompt: 'You are a helpful AI assistant named Walt. Say hello.',
});
Great, it works.
Now, I want to use a chat history.
As mentioned here, I use:
const result = await multiTurnPrompt.generate({
model: llama3x70b,
history: [
{ role: 'user', content: [{ text: 'Hello.' }] },
{ role: 'model', content: [{ text: 'Hi there!' }] },
],
});
Here is my code:
import {dotprompt, promptRef } from "@genkit-ai/dotprompt";
....
const multiTurnPrompt = dotprompt();
const result = await multiTurnPrompt.generate({
model: llama3x70b,
history: [
{ role: 'user', content: [{ text: 'Hello.' }] },
{ role: 'model', content: [{ text: 'Hi there!' }] },
],
});
console.log(await result.text());
I get error:
TypeError: multiTurnPrompt.generate is not a function
How to solve this issue ?
UPDATE
Modified code following @Michael Doyle answer:
const multiTurnPrompt = promptRef('nameOfPrompt');
const result = await multiTurnPrompt.generate({
model: llama3x70b,
history: [
{ role: 'user', content: [{ text: 'Hello.' }] },
{ role: 'model', content: [{ text: 'Hi there!' }] },
],
});
I get the error:
"GenkitError: dotprompt: NOT_FOUND: Could not find 'nameOfPrompt.prompt' in the prompts folder."
I don’t want to use a chat described in a chat file, I want to define the chat in my JS code as mentioned in the doc. How to do that ? Thanks.
2
Answers
Generally speaking, you are getting errors, because you are mixing and matching calls to
generate(...)
, which let’s you prompt models in an adhoc way, anddotprompt
, which has prompt management features, as well as a shortcut to "run" a prompt (i.e.prompt.generate(...)
.If you want to use chat history, we can stick to
generate
and modify your original code as follows:You can save the results from
generate(...)
to a variable, and calltoHistory()
on it, and then pass that history in to the next request. For example:The Genkit docs describe in more detail: https://firebase.google.com/docs/genkit/models#recording_message_history
You should try the new chat capabilities with genkit 0.9: https://firebase.google.com/docs/genkit/chat