Skip to content

Commit 85d5e9f

Browse files
authored
docs(js): Improvements and small fixes. (#1894)
1 parent dd633c7 commit 85d5e9f

File tree

3 files changed

+49
-51
lines changed

3 files changed

+49
-51
lines changed

docs/index.md

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Genkit is a framework designed to help you build AI-powered applications and fea
1818

1919
This documentation covers Genkit for Node.js. If you're a Go developer, see the [Genkit Go documentation](/docs/genkit-go/get-started-go).
2020

21-
You can deploy and run Genkit libraries anywhere Node.js is supported. It's designed to work with any generative AI model API or vector database. While we offer integrations for Firebase and Google Cloud, you can use Genkit independently of any Google services.
21+
You can deploy and run Genkit libraries anywhere Node.js is supported. It's designed to work with many AI model providers and vector databases. While we offer integrations for Firebase and Google Cloud, you can use Genkit independently of any Google services.
2222

2323
[Get started](/docs/genkit/get-started){: .button}
2424

@@ -65,19 +65,19 @@ See the following code samples for a concrete idea of how to use these capabilit
6565

6666
```javascript
6767
import { genkit } from 'genkit';
68-
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
68+
import { googleAI, gemini20Flash } from '@genkit-ai/googleai';
6969

7070
const ai = genkit({
7171
plugins: [googleAI()],
72-
model: gemini15Flash, // Set default model
72+
model: gemini20Flash, // Set default model
7373
});
7474

7575
// Simple generation
7676
const { text } = await ai.generate('Why is AI awesome?');
7777
console.log(text);
7878

7979
// Streamed generation
80-
const { stream } = await ai.generateStream('Tell me a story');
80+
const { stream } = ai.generateStream('Tell me a story');
8181
for await (const chunk of stream) {
8282
console.log(chunk.text);
8383
}
@@ -87,11 +87,11 @@ See the following code samples for a concrete idea of how to use these capabilit
8787

8888
```javascript
8989
import { genkit, z } from 'genkit';
90-
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
90+
import { googleAI, gemini20Flash } from '@genkit-ai/googleai';
9191

9292
const ai = genkit({
9393
plugins: [googleAI()],
94-
model: gemini15Flash,
94+
model: gemini20Flash,
9595
});
9696

9797
const { output } = await ai.generate({
@@ -110,15 +110,15 @@ See the following code samples for a concrete idea of how to use these capabilit
110110
console.log(output);
111111
```
112112

113-
- {Function calling}
113+
- {Tool calling}
114114

115115
```javascript
116116
import { genkit, z } from 'genkit';
117-
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
117+
import { googleAI, gemini20Flash } from '@genkit-ai/googleai';
118118

119119
const ai = genkit({
120120
plugins: [googleAI()],
121-
model: gemini15Flash,
121+
model: gemini20Flash,
122122
});
123123

124124
// Define tool to get current weather for a given location
@@ -129,7 +129,9 @@ See the following code samples for a concrete idea of how to use these capabilit
129129
inputSchema: z.object({
130130
location: z.string().describe('The location to get the current weather for')
131131
}),
132-
outputSchema: z.string(),
132+
outputSchema: z.object({
133+
weatherReport: z.string().describe('Weather report of a particular location')
134+
}),
133135
},
134136
async (input) => {
135137
// Here, we would typically make an API call or database query. For this
@@ -149,12 +151,12 @@ See the following code samples for a concrete idea of how to use these capabilit
149151
- {Chat}
150152

151153
```javascript
152-
import { genkit, z } from 'genkit';
153-
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
154+
import { genkit, z } from 'genkit/beta';
155+
import { googleAI, gemini20Flash } from '@genkit-ai/googleai';
154156

155157
const ai = genkit({
156158
plugins: [googleAI()],
157-
model: gemini15Flash,
159+
model: gemini20Flash,
158160
});
159161

160162
const chat = ai.chat({ system: 'Talk like a pirate' });
@@ -169,52 +171,51 @@ See the following code samples for a concrete idea of how to use these capabilit
169171
- {Agents}
170172

171173
```javascript
172-
import { genkit, z } from 'genkit';
173-
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
174+
import { genkit, z } from 'genkit/beta';
175+
import { googleAI, gemini20Flash } from '@genkit-ai/googleai';
174176

175177
const ai = genkit({
176178
plugins: [googleAI()],
177-
model: gemini15Flash,
179+
model: gemini20Flash,
178180
});
179181

180-
// Define prompts that represent specialist agents
181-
const reservationAgent = ai.definePrompt(
182-
{
183-
name: 'reservationAgent',
184-
description: 'Reservation Agent can help manage guest reservations',
185-
tools: [reservationTool, reservationCancelationTool, reservationListTool],
186-
187-
},
188-
`{% verbatim %}{{role "system"}}{% endverbatim %} Help guests make and manage reservations`
189-
);
182+
// Define tools for your agents to use
183+
const reservationTool = ai.defineTool( ... );
184+
const reservationCancelationTool = ai.defineTool( ... );
185+
const reservationListTool = ai.defineTool( ... );
190186

191-
const menuInfoAgent = ...
192-
const complaintAgent = ...
187+
// Define prompts that represent specialist agents
188+
const reservationAgent = ai.definePrompt({
189+
name: 'reservationAgent',
190+
description: 'Reservation Agent can help manage guest reservations',
191+
tools: [reservationTool, reservationCancelationTool, reservationListTool],
192+
system: `Help guests make and manage reservations`
193+
});
194+
const menuInfoAgent = ai.definePrompt( ... );
195+
const complaintAgent = ai.definePrompt( ... );
193196

194197
// Define a triage agent that routes to the proper specialist agent
195-
const triageAgent = ai.definePrompt(
196-
{
197-
name: 'triageAgent',
198-
description: 'Triage Agent',
199-
tools: [reservationAgent, menuInfoAgent, complaintAgent],
200-
},
201-
`{% verbatim %}{{role "system"}}{% endverbatim %} You are an AI customer service agent for Pavel's Cafe.
202-
Greet the user and ask them how you can help. If appropriate, transfer to an
203-
agent that can better handle the request. If you cannot help the customer with
204-
the available tools, politely explain so.`
205-
);
198+
const triageAgent = ai.definePrompt({
199+
name: 'triageAgent',
200+
description: 'Triage Agent',
201+
tools: [reservationAgent, menuInfoAgent, complaintAgent],
202+
system: `You are an AI customer service agent for Pavel's Cafe.
203+
Greet the user and ask them how you can help. If appropriate, transfer to an
204+
agent that can better handle the request. If you cannot help the customer with
205+
the available tools, politely explain so.`
206+
});
206207

207-
// Create a chat to enable multi-turn agent interactions
208+
// Create a chat to enable conversational agent interactions
208209
const chat = ai.chat(triageAgent);
209210

210-
chat.send('I want a reservation at Pavel\'s Cafe for noon on Tuesday.' );
211+
chat.send('I want a reservation at Pavel\'s Cafe for noon on Tuesday.');
211212
```
212213

213214
- {Data retrieval}
214215

215216
```javascript
216217
import { genkit } from 'genkit';
217-
import { googleAI, gemini15Flash, textEmbedding004 } from '@genkit-ai/googleai';
218+
import { googleAI, gemini20Flash, textEmbedding004 } from '@genkit-ai/googleai';
218219
import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore';
219220

220221
const ai = genkit({
@@ -227,7 +228,7 @@ See the following code samples for a concrete idea of how to use these capabilit
227228
},
228229
]),
229230
],
230-
model: gemini15Flash,
231+
model: gemini20Flash,
231232
});
232233

233234
// Reference to a local vector database storing Genkit documentation

docs/migrating-from-0.9.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ export const simpleFlow = ai.defineFlow(
250250
},
251251
async (input, { context }) => {
252252
if (!context.auth) {
253-
throw new Error('Authorization required.');
253+
throw new UserFacingError("UNAUTHORIZED", "Authorization required.");
254254
}
255255
if (input.uid !== context.auth.uid) {
256-
throw new Error('You may only summarize your own profile data.');
256+
throw new UserFacingError("UNAUTHORIZED", "You may only summarize your own profile data.");
257257
}
258258
// Flow logic here...
259259
}

docs/nextjs.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ For example:
6464
```ts
6565
'use server';
6666
67-
import { gemini15Flash, googleAI } from "@genkit-ai/googleai";
67+
import { gemini20Flash, googleAI } from "@genkit-ai/googleai";
6868
import { genkit, z } from "genkit";
6969
7070
const ai = genkit({
7171
plugins: [googleAI()],
72-
model: gemini15Flash,
72+
model: gemini20Flash,
7373
});
7474
7575
export const menuSuggestionFlow = ai.defineFlow(
@@ -79,10 +79,7 @@ export const menuSuggestionFlow = ai.defineFlow(
7979
outputSchema: z.string(),
8080
},
8181
async (restaurantTheme) => {
82-
const { text } = await ai.generate({
83-
model: gemini15Flash,
84-
prompt: `Invent a menu item for a ${restaurantTheme} themed restaurant.`,
85-
});
82+
const { text } = await ai.generate('Invent a menu item for a ${restaurantTheme} themed restaurant.');
8683
return text;
8784
}
8885
);

0 commit comments

Comments
 (0)