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

feat: expose defineFormat on Genkit instance, allowing to define custom formats #1365

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Nov 21, 2024

    ai.defineFormat(
      {
        name: 'banana',
        format: 'banana',
      },
      (schema) => {
        let instructions: string | undefined;

        if (schema) {
          instructions = `Output should be in banana format`;
        }

        return {
          parseChunk: (chunk) => {
            return `banana: ${chunk.content[0].text}`;
          },

          parseMessage: (message) => {
            return `banana: ${message.content[0].text}`;
          },

          instructions,
        };
      }
    );

@pavelgj pavelgj changed the title feat: expose defineFormat on Genkit instance, allowing to define custom format feat: expose defineFormat on Genkit instance, allowing to define custom formats Nov 21, 2024
@pavelgj pavelgj requested review from apascal07 and mbleigh and removed request for apascal07 November 21, 2024 15:31
@@ -247,6 +251,18 @@ export class Genkit {
return defineSchema(this.registry, name, schema);
}

/**
* Defines and registers a custom model output formatter.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a little bit more here explaining how it's used like some of the other define methods do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants