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: make ai.definePrompt callable as a function #1029

Merged
merged 16 commits into from
Oct 10, 2024
Merged

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Oct 8, 2024

const hi = ai.definePrompt({
    name: 'hi',
    model: gemini15Flash,
    input: {
      schema: z.object({
        name: z.string(),
      }),
    },
  },
  'hi {{ name }}'
);

const response = await hi({ name: 'Genkit' });
console.log(response.text())

// or stream

const { response, stream } = await hi.stream({ name: 'Genkit' });
for await (const chunk of stream) {
  console.log(chunk.text());
}
const responseText = (await response).text();
console.log(response.text())

or

const hi = ai.definePrompt({
    name: 'hi',
    model: 'echoModel',
    input: {
      schema: z.object({
        name: z.string(),
      }),
    },
    config: {
      temperature: 11,
    },
  },
  async (input) => {
    return {
      messages: [
        { role: 'user', content: [{ text: `hi ${input.name}` }] },
      ],
    };
  }
);
      
const response = await hi({ name: 'Genkit' });
console.log(response.text())

// or stream

const { response, stream } = await hi.stream({ name: 'Genkit' });
for await (const chunk of stream) {
  console.log(chunk.text());
}
const responseText = (await response).text();
console.log(response.text())

@pavelgj pavelgj marked this pull request as ready for review October 8, 2024 19:24
@pavelgj pavelgj requested a review from apascal07 October 9, 2024 21:21
js/genkit/src/genkit.ts Show resolved Hide resolved
@pavelgj pavelgj merged commit 91867f1 into next Oct 10, 2024
4 checks passed
@pavelgj pavelgj deleted the pj/functionalPrompts branch October 10, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants