Skip to content

Commit b0f02de

Browse files
authored
Remove references to initializeGenkit() in samples (#89)
1 parent d64cc80 commit b0f02de

File tree

32 files changed

+560
-867
lines changed

32 files changed

+560
-867
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export const URL_REGEX =
18+
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/i;
19+
20+
export const US_PHONE_REGEX =
21+
/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4}$/i;
22+
23+
// Turn off safety checks for evaluation so that the LLM as an evaluator can
24+
// respond appropriately to potentially harmful content without error.
25+
export const PERMISSIVE_SAFETY_SETTINGS: any = {
26+
safetySettings: [
27+
{
28+
category: 'HARM_CATEGORY_HATE_SPEECH',
29+
threshold: 'BLOCK_NONE',
30+
},
31+
{
32+
category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
33+
threshold: 'BLOCK_NONE',
34+
},
35+
{
36+
category: 'HARM_CATEGORY_HARASSMENT',
37+
threshold: 'BLOCK_NONE',
38+
},
39+
{
40+
category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
41+
threshold: 'BLOCK_NONE',
42+
},
43+
],
44+
};

js/samples/byo-evaluator/src/genkit.config.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

js/samples/byo-evaluator/src/index.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,56 @@
1515
*/
1616
import { EvaluatorAction } from '@genkit-ai/ai';
1717
import { ModelReference } from '@genkit-ai/ai/model';
18-
import { PluginProvider, genkitPlugin } from '@genkit-ai/core';
18+
import { configureGenkit, genkitPlugin, PluginProvider } from '@genkit-ai/core';
19+
import { firebase } from '@genkit-ai/firebase';
20+
import { geminiPro, googleAI } from '@genkit-ai/googleai';
1921
import * as z from 'zod';
2022
import {
21-
DELICIOUSNESS,
23+
PERMISSIVE_SAFETY_SETTINGS,
24+
URL_REGEX,
25+
US_PHONE_REGEX,
26+
} from './constants.js';
27+
import {
2228
createDeliciousnessEvaluator,
29+
DELICIOUSNESS,
2330
} from './deliciousness/deliciousness_evaluator.js';
2431
import {
25-
FUNNINESS,
2632
createFunninessEvaluator,
33+
FUNNINESS,
2734
} from './funniness/funniness_evaluator.js';
28-
import { PII_DETECTION, createPiiEvaluator } from './pii/pii_evaluator.js';
35+
import { createPiiEvaluator, PII_DETECTION } from './pii/pii_evaluator.js';
2936
import {
30-
RegexMetric,
3137
createRegexEvaluators,
3238
isRegexMetric,
39+
regexMatcher,
40+
RegexMetric,
3341
} from './regex/regex_evaluator.js';
3442

43+
configureGenkit({
44+
plugins: [
45+
firebase(),
46+
googleAI({ apiVersion: ['v1', 'v1beta'] }),
47+
byoEval({
48+
judge: geminiPro,
49+
judgeConfig: PERMISSIVE_SAFETY_SETTINGS,
50+
metrics: [
51+
// regexMatcher will register an evaluator with a name in the format
52+
// byo/regex_match_{suffix}. In this case, byo/regex_match_url
53+
regexMatcher('url', URL_REGEX),
54+
// byo/regex_match_us_phone
55+
regexMatcher('us_phone', US_PHONE_REGEX),
56+
PII_DETECTION,
57+
DELICIOUSNESS,
58+
FUNNINESS,
59+
],
60+
}),
61+
],
62+
flowStateStore: 'firebase',
63+
traceStore: 'firebase',
64+
enableTracingAndMetrics: true,
65+
logLevel: 'debug',
66+
});
67+
3568
/**
3669
* Generic metric definition with flexible configuration.
3770
*/
@@ -92,6 +125,5 @@ export function byoEval<ModelCustomOptions extends z.ZodTypeAny>(
92125
// create the plugin with the passed params
93126
return plugin(params);
94127
}
95-
export default byoEval;
96128

97-
export * from './genkit.config.js';
129+
export default byoEval;

js/samples/cat-eval/src/genkit.config.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

js/samples/cat-eval/src/index.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,61 @@
1414
* limitations under the License.
1515
*/
1616

17-
export * from './genkit.config.js';
17+
import { configureGenkit } from '@genkit-ai/core';
18+
import { devLocalVectorstore } from '@genkit-ai/dev-local-vectorstore';
19+
import { genkitEval, GenkitMetric } from '@genkit-ai/evaluator';
20+
import { firebase } from '@genkit-ai/firebase';
21+
import { geminiPro, googleAI } from '@genkit-ai/googleai';
22+
import { textEmbeddingGecko, vertexAI } from '@genkit-ai/vertexai';
23+
24+
// Turn off safety checks for evaluation so that the LLM as an evaluator can
25+
// respond appropriately to potentially harmful content without error.
26+
export const PERMISSIVE_SAFETY_SETTINGS: any = {
27+
safetySettings: [
28+
{
29+
category: 'HARM_CATEGORY_HATE_SPEECH',
30+
threshold: 'BLOCK_NONE',
31+
},
32+
{
33+
category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
34+
threshold: 'BLOCK_NONE',
35+
},
36+
{
37+
category: 'HARM_CATEGORY_HARASSMENT',
38+
threshold: 'BLOCK_NONE',
39+
},
40+
{
41+
category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
42+
threshold: 'BLOCK_NONE',
43+
},
44+
],
45+
};
46+
47+
configureGenkit({
48+
plugins: [
49+
firebase(),
50+
googleAI(),
51+
genkitEval({
52+
judge: geminiPro,
53+
judgeConfig: PERMISSIVE_SAFETY_SETTINGS,
54+
metrics: [GenkitMetric.MALICIOUSNESS],
55+
embedder: textEmbeddingGecko,
56+
}),
57+
vertexAI({
58+
location: 'us-central1',
59+
}),
60+
devLocalVectorstore([
61+
{
62+
indexName: 'pdfQA',
63+
embedder: textEmbeddingGecko,
64+
},
65+
]),
66+
],
67+
flowStateStore: 'firebase',
68+
traceStore: 'firebase',
69+
enableTracingAndMetrics: true,
70+
logLevel: 'debug',
71+
});
72+
1873
export * from './pdf_rag.js';
1974
export * from './setup.js';

0 commit comments

Comments
 (0)