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/genkit): correctly handle function prompt output schema #1395

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Nov 25, 2024

Fixes #1390

import { genkit, z } from 'genkit';
import { googleAI, gemini15Flash } from '@genkit-ai/googleai'

const ai = genkit({
  plugins: [googleAI()],
  model: gemini15Flash,
});

const helloPrompt = ai.definePrompt(
  {
    name: 'helloPrompt',
    input: z.object({
      name: z.string(),
    }),
    output: {
      schema: z.object({
        message: z.string()
      })
    }
  }, async (input) => ({
    messages: [{
      role: 'user',
      content: [{text: `say hello to ${input.name}`}]
    }]
  })
);


export const helloFlow = ai.defineFlow('hello', async () => {
  const { text } = await helloPrompt({name: "Pavel"});
  return text;
});

Checklist (if applicable):

  • Tested (manually, unit tested, etc.)

@MichaelDoyle
Copy link
Member

Thanks! This looks good.

As an aside, since functional prompts return a full generate request, technically the schema and other options can also be provided there. I wasn't sure how to reconcile that. :)

@pavelgj
Copy link
Collaborator Author

pavelgj commented Nov 26, 2024

Thanks! This looks good.

As an aside, since functional prompts return a full generate request, technically the schema and other options can also be provided there. I wasn't sure how to reconcile that. :)

Good callout. I think most/all of these options are handled in wrapPromptActionInExecutablePrompt. I'm hunting down the ones I missed (or mishandled) one by one.

@pavelgj pavelgj merged commit 2b85cb8 into main Nov 26, 2024
4 checks passed
@pavelgj pavelgj deleted the pj/fnPromptOutputSchema branch November 26, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[JS] definePrompt does not respect output schema
3 participants