Skip to content

Commit

Permalink
modify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yukinagae committed Sep 25, 2024
1 parent 505c55c commit 1b403f4
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 11 deletions.
81 changes: 80 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,86 @@
# Plugin usage examples

- [Requirements](#requirements)
- [Setup](#setup)
- [Evaluation](#evaluation)
- [Making Changes](#making-changes)

## Requirements

Before you start, make sure you have these installed:

- **Node.js** version 22 or later
- **npm**
- **Genkit**

For Genkit installation, see the [official guide](https://firebase.google.com/docs/genkit/get-started).

Check your installations by running:

```bash
$ node --version # the below version is on my environment
v22.7.0
$ npm --version # the below version is on my environment
10.8.2
$ genkit --version # the below version is on my environment
0.5.10
```

## Setup

1. Install Project Dependencies: Open your terminal, navigate to this project's folder, and run:

```bash
$ npm install
$ export GOOGLE_GENAI_API_KEY=your_gemini_api_key
```

2. Authentication and Google Cloud project configuration. Make sure Vertex AI is enabled on your project.

Follow these steps to login and configure the project:

```bash
$ gcloud auth application-default login
$ gcloud config set core/project [your-project-id]
```

## Evaluation

To evaluate your flow, run the following command:

```bash
$ genkit eval:flow menuSuggestionFlow --input data/testInputs.json
```

To view the evaluation results, run the following command and automatically opens your default web browser to http://localhost:4000.

```bash
$ genkit start -o
```

## Making Changes

### Building the Project

After making changes, you might need to build the project to see your changes in action:

```bash
$ npm run build
```

### Formatting and Linting

To ensure your code follows the project's coding standards, run the formatting and linting tools:

```bash
$ npm run typecheck # type check without modifying files
$ npm run check # scan without modifying files
$ npm run fix # modify files
```

### Kill Existing Processes

Sometimes existing processes are still running, preventing you from running genkit locally because the ports are already in use. In that case, run the following command to kill the processes tied to the ports:

```bash
$ npm run kill
```
29 changes: 29 additions & 0 deletions examples/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedImports": "error"
}
}
},
"formatter": {
"enabled": true,
"indentWidth": 2,
"lineWidth": 80,
"indentStyle": "space"
},
"javascript": {
"formatter": {
"trailingCommas": "es5",
"semicolons": "always",
"quoteStyle": "single",
"bracketSameLine": true
}
}
}
2 changes: 1 addition & 1 deletion examples/data/testInputs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["Japanese"]
["Cheese"]
15 changes: 11 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"name": "examples",
"version": "1.0.0",
"main": "lib/index.js",
"scripts": {
"start": "node lib/index.js",
"engines": {
"node": "22"
},
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch"
"typecheck": "tsc --noEmit",
"check": "biome check ./src",
"fix": "biome check --write ./src",
"kill": "lsof -i:3000,3100,4000,4001,4400,5001,5050,8080,8085,9099,9199 -t | xargs kill"
},
"keywords": [],
"author": "",
Expand All @@ -17,11 +22,13 @@
"@genkit-ai/dotprompt": "^0.5.13",
"@genkit-ai/flow": "^0.5.13",
"@genkit-ai/googleai": "^0.5.13",
"@genkit-ai/vertexai": "^0.5.13",
"express": "^4.21.0",
"genkitx-promptfoo": "^0.1.3",
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2"
"@biomejs/biome": "^1.8.3",
"typescript": "^5.5.4"
}
}
19 changes: 14 additions & 5 deletions examples/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ import * as z from 'zod';
import { generate } from '@genkit-ai/ai';
import { configureGenkit } from '@genkit-ai/core';
import { defineFlow, startFlowsServer } from '@genkit-ai/flow';
import { googleAI } from '@genkit-ai/googleai';

import { gemini15Flash } from '@genkit-ai/googleai';
import { gemini15Flash, vertexAI } from '@genkit-ai/vertexai';

import { promptfooEval } from 'genkitx-promptfoo';

configureGenkit({
plugins: [
googleAI(),
vertexAI(),
promptfooEval({
metrics: [
{
type: 'icontains',
value: 'sushi',
value: 'cheese',
},
{
type: 'similar',
value: 'Aloha, World!',
threshold: 0.8,
provider: 'vertex:embedding:text-embedding-004',
},
{
type: 'llm-rubric',
value: 'It is referring to the ingredients of food.',
provider: 'vertex:gemini-1.5-flash',
},
],
}),
Expand Down

0 comments on commit 1b403f4

Please sign in to comment.