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

Update dev-ui gallery to use the latest in prompt technology #1146

Merged
merged 1 commit into from
Oct 30, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
model: googleai/gemini-1.5-flash-latest
model: googleai/gemini-1.5-flash
input:
schema:
firstName: string
Expand Down
2 changes: 1 addition & 1 deletion js/testapps/dev-ui-gallery/prompts/hello.history.prompt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
model: googleai/gemini-1.5-flash-latest
model: googleai/gemini-1.5-flash
config:
maxOutputTokens: 2048
temperature: 0.6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
model: googleai/gemini-1.5-flash-latest
model: googleai/gemini-1.5-flash
input:
schema:
name: string
Expand Down
2 changes: 1 addition & 1 deletion js/testapps/dev-ui-gallery/prompts/hello.prompt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
model: googleai/gemini-1.5-flash-latest
model: googleai/gemini-1.5-flash
config:
maxOutputTokens: 2048
temperature: 0.6
Expand Down
2 changes: 1 addition & 1 deletion js/testapps/dev-ui-gallery/prompts/hello.system.prompt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
model: googleai/gemini-1.5-flash-latest
model: googleai/gemini-1.5-flash
config:
maxOutputTokens: 2048
temperature: 0.6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
model: googleai/gemini-1.5-flash-latest
model: googleai/gemini-1.5-flash
config:
maxOutputTokens: 2048
temperature: 0.6
Expand Down
7 changes: 4 additions & 3 deletions js/testapps/dev-ui-gallery/src/genkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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' },
Expand Down
75 changes: 60 additions & 15 deletions js/testapps/dev-ui-gallery/src/main/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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;
}
);

Expand All @@ -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;
}
);

Expand All @@ -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;
}
);

Expand All @@ -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;
}
);

Expand All @@ -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;
}
);

Expand Down
5 changes: 1 addition & 4 deletions js/testapps/dev-ui-gallery/src/main/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Loading