Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 38 additions & 47 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,50 +71,41 @@ Node.js 18 or later.
1. Choose default answers to the rest of the questions, which will
initialize your project folder with some sample code.

The `genkit init` command created two sample source files:

- `genkit.config.ts`: this is where you configure Genkit for your project,
and select and configure the plugins you want to load. The sample config
loads a plugin to support the model provider you chose earlier.

```js
export default configureGenkit({
plugins: [googleAI()],
logLevel: 'debug',
enableTracingAndMetrics: true,
});
```

- `index.ts`: this is your project's entry point, where you export your AI
flows and other resources you've defined. The sample file contains a
single flow, `jokeFlow`, that simply calls the model provider's API with a
simple prompt and returns the result.

```js
export const jokeFlow = defineFlow(
{
name: 'jokeFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
const llmResponse = await generate({
prompt: `Tell me a long joke about ${subject}`,
model: geminiPro,
config: {
temperature: 1,
},
});

return llmResponse.text();
}
);
```

As you build out your app's AI features with Genkit, you will likely
create flows with multiple steps such as input preprocessing, more
sophisticated prompt construction, integrating external information
sources for retrieval-augmented generation (RAG), and more.
The `genkit init` command creates a sample source file, `index.ts`. This is your project's entry point, where you configure Genkit for your project, configure the plugins you want to load and export your AI flows and other resources you've defined. The sample file contains a config that loads a plugin to support the model provider you chose earlier. It also contains a single flow, `menuSuggestionFlow`, that prompts an LLM to suggest an item for a restaurant with a given theme.

```js
configureGenkit({
plugins: [googleAI()],
logLevel: 'debug',
enableTracingAndMetrics: true,
});

export const menuSuggestionFlow = defineFlow(
{
name: 'menuSuggestionFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
const llmResponse = await generate({
prompt: `Suggest an item for the menu of a {subject} themed restaurant`,
model: $GENKIT_MODEL,
config: {
temperature: 1,
},
});

return llmResponse.text();
}
);

startFlowsServer();
```

As you build out your app's AI features with Genkit, you will likely
create flows with multiple steps such as input preprocessing, more
sophisticated prompt construction, integrating external information
sources for retrieval-augmented generation (RAG), and more.

1. Now you can run and explore Genkit features and the sample project locally
on your machine. Download and start the Genkit Developer UI:
Expand Down Expand Up @@ -144,9 +135,9 @@ Node.js 18 or later.
- On the **Run** tab, you will see a list of all of the flows that you have
defined and any models that have been configured by plugins.

Click **jokeFlow** and try running it with some input text (for example,
`"manatees"`). If all goes well, you'll be rewarded with a joke about
manatees. Run it a few more times and you might get one that's funny.
Click **menuSuggestionFlow** and try running it with some input text (for example,
`"cat"`). If all goes well, you'll be rewarded with a menu suggestion for a cat
themed restaurant.

- On the **Inspect** tab, you'll see a history of flow executions. For each
flow, you can see the parameters that were passed to the flow and a
Expand Down
9 changes: 6 additions & 3 deletions genkit-tools/config/firebase.index.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ $GENKIT_CONFIG_PLUGINS
enableTracingAndMetrics: true,
});

export const jokeFlow = onFlow(
export const menuSuggestionFlow = onFlow(
{
name: "jokeFlow",
name: 'menuSuggestionFlow',
inputSchema: z.string(),
outputSchema: z.string(),
authPolicy: firebaseAuth((user) => {
Expand All @@ -26,11 +26,14 @@ export const jokeFlow = onFlow(
}),
},
async (subject) => {
const prompt = `Tell me a joke about ${subject}`;
const prompt = `Suggest an item for the menu of a ${subject} themed restaurant`;

const llmResponse = await generate({
model: $GENKIT_MODEL,
prompt: prompt,
config: {
temperature: 1,
},
});

return llmResponse.text();
Expand Down
6 changes: 3 additions & 3 deletions genkit-tools/config/googleCloud.index.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ $GENKIT_CONFIG_PLUGINS
enableTracingAndMetrics: true,
});

export const jokeFlow = defineFlow(
export const menuSuggestionFlow = defineFlow(
{
name: 'jokeFlow',
name: 'menuSuggestionFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
const llmResponse = await generate({
prompt: `Tell me a long joke about ${subject}`,
prompt: `Suggest an item for the menu of a ${subject} themed restaurant`,
model: $GENKIT_MODEL,
config: {
temperature: 1,
Expand Down
16 changes: 8 additions & 8 deletions genkit-tools/config/nextjs.genkit.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ $GENKIT_CONFIG_PLUGINS
enableTracingAndMetrics: true,
});

export async function callJokeFlow() {
const joke = await runFlow(jokeFlow, 'banana');
console.log(joke)
}

const jokeFlow = defineFlow(
const menuSuggestionFlow = defineFlow(
{
name: 'jokeFlow',
name: 'menuSuggestionFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (subject) => {
const llmResponse = await generate({
prompt: `Tell me a long joke about ${subject}`,
prompt: `Suggest an item for the menu of a ${subject} themed restaurant`,
model: $GENKIT_MODEL,
config: {
temperature: 1,
Expand All @@ -38,3 +33,8 @@ const jokeFlow = defineFlow(
return llmResponse.text();
}
);

export async function callMenuSuggestionFlow() {
const flowResponse = await runFlow(menuSuggestionFlow, 'banana');
console.log(flowResponse);
}