diff --git a/js/testapps/dev-ui-gallery/prompts/hello.first-last-name.prompt b/js/testapps/dev-ui-gallery/prompts/hello.first-last-name.prompt index c37451853..a88163bb5 100644 --- a/js/testapps/dev-ui-gallery/prompts/hello.first-last-name.prompt +++ b/js/testapps/dev-ui-gallery/prompts/hello.first-last-name.prompt @@ -1,5 +1,5 @@ --- -model: googleai/gemini-1.5-flash-latest +model: googleai/gemini-1.5-flash input: schema: firstName: string diff --git a/js/testapps/dev-ui-gallery/prompts/hello.history.prompt b/js/testapps/dev-ui-gallery/prompts/hello.history.prompt index bde301049..31f7468b2 100644 --- a/js/testapps/dev-ui-gallery/prompts/hello.history.prompt +++ b/js/testapps/dev-ui-gallery/prompts/hello.history.prompt @@ -1,5 +1,5 @@ --- -model: googleai/gemini-1.5-flash-latest +model: googleai/gemini-1.5-flash config: maxOutputTokens: 2048 temperature: 0.6 diff --git a/js/testapps/dev-ui-gallery/prompts/hello.json-output.prompt b/js/testapps/dev-ui-gallery/prompts/hello.json-output.prompt index 05010f946..60483c339 100644 --- a/js/testapps/dev-ui-gallery/prompts/hello.json-output.prompt +++ b/js/testapps/dev-ui-gallery/prompts/hello.json-output.prompt @@ -1,5 +1,5 @@ --- -model: googleai/gemini-1.5-flash-latest +model: googleai/gemini-1.5-flash input: schema: name: string diff --git a/js/testapps/dev-ui-gallery/prompts/hello.prompt b/js/testapps/dev-ui-gallery/prompts/hello.prompt index afc651931..6e0c4631a 100644 --- a/js/testapps/dev-ui-gallery/prompts/hello.prompt +++ b/js/testapps/dev-ui-gallery/prompts/hello.prompt @@ -1,5 +1,5 @@ --- -model: googleai/gemini-1.5-flash-latest +model: googleai/gemini-1.5-flash config: maxOutputTokens: 2048 temperature: 0.6 diff --git a/js/testapps/dev-ui-gallery/prompts/hello.system.prompt b/js/testapps/dev-ui-gallery/prompts/hello.system.prompt index 074dfed2b..daf1ef1d5 100644 --- a/js/testapps/dev-ui-gallery/prompts/hello.system.prompt +++ b/js/testapps/dev-ui-gallery/prompts/hello.system.prompt @@ -1,5 +1,5 @@ --- -model: googleai/gemini-1.5-flash-latest +model: googleai/gemini-1.5-flash config: maxOutputTokens: 2048 temperature: 0.6 diff --git a/js/testapps/dev-ui-gallery/prompts/imagen3.prompt b/js/testapps/dev-ui-gallery/prompts/media/imagen3.prompt similarity index 100% rename from js/testapps/dev-ui-gallery/prompts/imagen3.prompt rename to js/testapps/dev-ui-gallery/prompts/media/imagen3.prompt diff --git a/js/testapps/dev-ui-gallery/prompts/tools.prompt b/js/testapps/dev-ui-gallery/prompts/tools/weather.prompt similarity index 93% rename from js/testapps/dev-ui-gallery/prompts/tools.prompt rename to js/testapps/dev-ui-gallery/prompts/tools/weather.prompt index cf4c22c85..4a55dac66 100644 --- a/js/testapps/dev-ui-gallery/prompts/tools.prompt +++ b/js/testapps/dev-ui-gallery/prompts/tools/weather.prompt @@ -1,5 +1,5 @@ --- -model: googleai/gemini-1.5-flash-latest +model: googleai/gemini-1.5-flash config: maxOutputTokens: 2048 temperature: 0.6 diff --git a/js/testapps/dev-ui-gallery/src/genkit.ts b/js/testapps/dev-ui-gallery/src/genkit.ts index 3a1e9aa97..e73c01830 100644 --- a/js/testapps/dev-ui-gallery/src/genkit.ts +++ b/js/testapps/dev-ui-gallery/src/genkit.ts @@ -26,10 +26,13 @@ import { VertexAIEvaluationMetricType, } from '@genkit-ai/vertexai'; import { genkit } from 'genkit'; +import { logger } from 'genkit/logging'; import { chroma } from 'genkitx-chromadb'; import { ollama } from 'genkitx-ollama'; import { pinecone } from 'genkitx-pinecone'; +logger.setLogLevel('info'); + // Turn off safety checks for evaluation so that the LLM as an evaluator can // respond appropriately to potentially harmful content without error. export const PERMISSIVE_SAFETY_SETTINGS: any = { @@ -57,9 +60,7 @@ export const ai = genkit({ // load at least one plugin representing each action type plugins: [ // model providers - googleAI({ - apiVersion: ['v1', 'v1beta'], - }), + googleAI(), ollama({ models: [ { name: 'llama2' }, diff --git a/js/testapps/dev-ui-gallery/src/main/prompts.ts b/js/testapps/dev-ui-gallery/src/main/prompts.ts index 25dd180af..a05ad674d 100644 --- a/js/testapps/dev-ui-gallery/src/main/prompts.ts +++ b/js/testapps/dev-ui-gallery/src/main/prompts.ts @@ -96,15 +96,52 @@ ai.defineStreamingFlow( outputSchema: z.string(), }, async (input) => { - const prompt = await ai.prompt('codeDefinedPrompt'); - const response = await prompt.generate({ - input, - }); - + const response = await codeDefinedPrompt(input); return response.text; } ); +// +// Function(al) prompts +// + +export const promptFn = ai.definePrompt( + { + name: 'functionalPrompt', + input: { + schema: HelloSchema, + default: { + persona: 'Space Pirate', + }, + }, + model: gemini15Flash, + }, + async (input) => ({ + messages: [ + { + role: 'user', + content: [ + { + text: `say hello to ${input.name} in the voice of ${input.persona}`, + }, + ], + }, + ], + }) +); + +ai.defineFlow( + { + name: 'flowFunctionalPrompt', + inputSchema: HelloSchema, + outputSchema: z.string(), + }, + async (input) => { + const hello = await ai.prompt('functionalPrompt'); + return (await hello(input)).text; + } +); + // // Dotprompt file - text output // @@ -116,8 +153,8 @@ ai.defineFlow( outputSchema: z.string(), }, async (input) => { - const prompt = await ai.prompt('hello'); - return (await prompt.generate({ input })).text; + const hello = await ai.prompt('hello'); + return (await hello(input)).text; } ); @@ -132,8 +169,10 @@ ai.defineFlow( outputSchema: z.string(), }, async (input) => { - const prompt = await ai.prompt('hello', { variant: 'first-last-name' }); - return (await prompt.generate({ input })).text; + const hello = await ai.prompt('hello', { + variant: 'first-last-name', + }); + return (await hello(input)).text; } ); @@ -148,8 +187,10 @@ ai.defineFlow( outputSchema: z.any(), }, async (input) => { - const prompt = await ai.prompt('hello', { variant: 'json-output' }); - return (await prompt.generate({ input })).output; + const hello = await ai.prompt('hello', { + variant: 'json-output', + }); + return (await hello(input)).output; } ); @@ -164,8 +205,10 @@ ai.defineFlow( outputSchema: z.any(), }, async (input) => { - const prompt = await ai.prompt('hello', { variant: 'system' }); - return (await prompt.generate({ input })).text; + const hello = await ai.prompt('hello', { + variant: 'system', + }); + return (await hello(input)).text; } ); @@ -180,8 +223,10 @@ ai.defineFlow( outputSchema: z.any(), }, async (input) => { - const prompt = await ai.prompt('hello', { variant: 'history' }); - return (await prompt.generate({ input })).text; + const hello = await ai.prompt('hello', { + variant: 'history', + }); + return (await hello(input)).text; } ); diff --git a/js/testapps/dev-ui-gallery/src/main/tools.ts b/js/testapps/dev-ui-gallery/src/main/tools.ts index 71316f5ee..21a42f8ad 100644 --- a/js/testapps/dev-ui-gallery/src/main/tools.ts +++ b/js/testapps/dev-ui-gallery/src/main/tools.ts @@ -92,8 +92,5 @@ ai.defineFlow( inputSchema: WeatherSchema, outputSchema: z.string(), }, - async (input) => { - const { text } = await weatherPrompt(input); - return text; - } + async (input) => (await weatherPrompt(input)).text );