Skip to content

Commit c4df873

Browse files
committed
feat: module 4
1 parent 78d2d7a commit c4df873

File tree

18 files changed

+12014
-17
lines changed

18 files changed

+12014
-17
lines changed
485 KB
Loading

content/assets/module3/tools.png

386 KB
Loading

content/code/module2/functions/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const myFlow = onFlow(
3333
},
3434
async (toProcess) => {
3535
const prompt =
36-
`Tell me ajoke about ${toProcess.text}`;
36+
`Tell me a joke about ${toProcess.text}`;
3737

3838
const llmResponse = await generate({
3939
model: gpt4o,

content/code/module3/functions/prompts/joke.prompt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ output:
88
text: string
99
---
1010

11-
Tell me ajoke about {{text}}
11+
Tell me a joke about {{text}}

content/code/module3/functions/src/index.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { onFlow, noAuth } from "@genkit-ai/firebase/functions";
1212

1313
import * as z from "zod";
1414
import { firebase } from "@genkit-ai/firebase";
15-
import { openAI } from "genkitx-openai";
16-
import { dotprompt, promptRef } from "@genkit-ai/dotprompt";
15+
import { gpt4o, openAI } from "genkitx-openai";
16+
import { dotprompt } from "@genkit-ai/dotprompt";
17+
import { defineTool, generate } from "@genkit-ai/ai";
1718

1819
configureGenkit({
1920
plugins: [firebase(), dotprompt(), openAI(
@@ -24,6 +25,21 @@ configureGenkit({
2425
logLevel: "debug",
2526
});
2627

28+
const getJoke = defineTool(
29+
{
30+
name: "getJoke",
31+
description:
32+
"Get a randome joke about a specific topic",
33+
inputSchema: z.object({ jokeTopic: z.string() }),
34+
outputSchema: z.object({ joke: z.string() }),
35+
},
36+
async ({ jokeTopic }) => {
37+
const response = await fetch(`https://v2.jokeapi.dev/joke/Any?contains=${jokeTopic}`);
38+
const joke = await response.json();
39+
return {"joke": joke.joke};
40+
},
41+
);
42+
2743
export const myFlow = onFlow(
2844
{
2945
name: "myFlow",
@@ -33,14 +49,15 @@ export const myFlow = onFlow(
3349
},
3450
async (toProcess) => {
3551

36-
const nluPrompt = promptRef("joke");
52+
const prompt =
53+
`Tell me a joke about ${toProcess.text}`;
3754

38-
const result = await nluPrompt.generate({
39-
input: {
40-
text: toProcess.text,
41-
},
55+
const result = await generate({
56+
model: gpt4o,
57+
prompt,
58+
tools: [getJoke]
4259
});
4360

44-
return result.output();
61+
return result.text();
4562
},
4663
);

content/code/module4/.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "action-helloworld"
4+
}
5+
}

content/code/module4/.gitignore

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
67+
68+
# dataconnect generated files
69+
.dataconnect

content/code/module4/firebase.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"functions": [
3+
{
4+
"source": "functions",
5+
"codebase": "default",
6+
"predeploy": [
7+
"npm --prefix \"$RESOURCE_DIR\" run lint",
8+
"npm --prefix \"$RESOURCE_DIR\" run build"
9+
]
10+
}
11+
]
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
"eslint:recommended",
9+
"plugin:import/errors",
10+
"plugin:import/warnings",
11+
"plugin:import/typescript",
12+
"google",
13+
"plugin:@typescript-eslint/recommended",
14+
],
15+
parser: "@typescript-eslint/parser",
16+
parserOptions: {
17+
project: ["tsconfig.json", "tsconfig.dev.json"],
18+
sourceType: "module",
19+
},
20+
ignorePatterns: [
21+
"/lib/**/*", // Ignore built files.
22+
"/generated/**/*", // Ignore generated files.
23+
],
24+
plugins: [
25+
"@typescript-eslint",
26+
"import",
27+
],
28+
rules: {
29+
"quotes": ["error", "double"],
30+
"import/no-unresolved": 0,
31+
"indent": ["error", 2],
32+
},
33+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Compiled JavaScript files
2+
lib/**/*.js
3+
lib/**/*.js.map
4+
5+
# TypeScript v1 declaration files
6+
typings/
7+
8+
# Node.js dependency directory
9+
node_modules/
10+
*.local

0 commit comments

Comments
 (0)