Skip to content

Commit

Permalink
feat: module 4
Browse files Browse the repository at this point in the history
  • Loading branch information
xavidop committed Nov 10, 2024
1 parent 78d2d7a commit c4df873
Show file tree
Hide file tree
Showing 18 changed files with 12,014 additions and 17 deletions.
Binary file added content/assets/module3/toolexecution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/assets/module3/tools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
2 changes: 1 addition & 1 deletion content/code/module2/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const myFlow = onFlow(
},
async (toProcess) => {
const prompt =
`Tell me ajoke about ${toProcess.text}`;
`Tell me a joke about ${toProcess.text}`;

const llmResponse = await generate({
model: gpt4o,
Expand Down
2 changes: 1 addition & 1 deletion content/code/module3/functions/prompts/joke.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ output:
text: string
---

Tell me ajoke about {{text}}
Tell me a joke about {{text}}
33 changes: 25 additions & 8 deletions content/code/module3/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { onFlow, noAuth } from "@genkit-ai/firebase/functions";

import * as z from "zod";
import { firebase } from "@genkit-ai/firebase";
import { openAI } from "genkitx-openai";
import { dotprompt, promptRef } from "@genkit-ai/dotprompt";
import { gpt4o, openAI } from "genkitx-openai";
import { dotprompt } from "@genkit-ai/dotprompt";
import { defineTool, generate } from "@genkit-ai/ai";

configureGenkit({
plugins: [firebase(), dotprompt(), openAI(
Expand All @@ -24,6 +25,21 @@ configureGenkit({
logLevel: "debug",
});

const getJoke = defineTool(
{
name: "getJoke",
description:
"Get a randome joke about a specific topic",
inputSchema: z.object({ jokeTopic: z.string() }),
outputSchema: z.object({ joke: z.string() }),
},
async ({ jokeTopic }) => {
const response = await fetch(`https://v2.jokeapi.dev/joke/Any?contains=${jokeTopic}`);
const joke = await response.json();
return {"joke": joke.joke};
},
);

export const myFlow = onFlow(
{
name: "myFlow",
Expand All @@ -33,14 +49,15 @@ export const myFlow = onFlow(
},
async (toProcess) => {

const nluPrompt = promptRef("joke");
const prompt =
`Tell me a joke about ${toProcess.text}`;

const result = await nluPrompt.generate({
input: {
text: toProcess.text,
},
const result = await generate({
model: gpt4o,
prompt,
tools: [getJoke]
});

return result.output();
return result.text();
},
);
5 changes: 5 additions & 0 deletions content/code/module4/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "action-helloworld"
}
}
69 changes: 69 additions & 0 deletions content/code/module4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# dataconnect generated files
.dataconnect
12 changes: 12 additions & 0 deletions content/code/module4/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
]
}
33 changes: 33 additions & 0 deletions content/code/module4/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
"/generated/**/*", // Ignore generated files.
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"quotes": ["error", "double"],
"import/no-unresolved": 0,
"indent": ["error", 2],
},
};
10 changes: 10 additions & 0 deletions content/code/module4/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Compiled JavaScript files
lib/**/*.js
lib/**/*.js.map

# TypeScript v1 declaration files
typings/

# Node.js dependency directory
node_modules/
*.local
Loading

0 comments on commit c4df873

Please sign in to comment.