Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/init/features/genkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,23 @@ export async function genkitSetup(
default: true,
}))
) {
generateSampleFile(modelOptions[model].plugin, plugins, projectDir, genkitInfo.templateVersion);
logger.info(
"Telemetry data can be used to monitor and gain insights into your AI features. There may be a cost associated with using this feature. See https://firebase.google.com/docs/genkit/observability/telemetry-collection.",
);
const enableTelemetry =
options.nonInteractive ||
(await confirm({
message: "Would like you to enable telemetry collection?",
default: true,
}));

generateSampleFile(
modelOptions[model].plugin,
plugins,
projectDir,
genkitInfo.templateVersion,
enableTelemetry,
);
}
}

Expand Down Expand Up @@ -507,6 +523,7 @@ function generateSampleFile(
configPlugins: string[],
projectDir: string,
templateVersion: string,
enableTelemetry: boolean,
): void {
let modelImport = "";
if (modelPlugin && pluginToInfo[modelPlugin].model) {
Expand Down Expand Up @@ -534,6 +551,7 @@ function generateSampleFile(
? pluginToInfo[modelPlugin].model || pluginToInfo[modelPlugin].modelStr || ""
: "'' /* TODO: Set a model. */",
),
enableTelemetry,
);
logLabeledBullet("genkit", "Generating sample file");
try {
Expand Down Expand Up @@ -622,7 +640,7 @@ async function updatePackageJson(nonInteractive: boolean, projectDir: string): P
}
}

function renderConfig(pluginNames: string[], template: string): string {
function renderConfig(pluginNames: string[], template: string, enableTelemetry: boolean): string {
const imports = pluginNames
.map((pluginName) => generateImportStatement(pluginToInfo[pluginName].imports, pluginName))
.join("\n");
Expand All @@ -631,7 +649,8 @@ function renderConfig(pluginNames: string[], template: string): string {
" /* Add your plugins here. */";
return template
.replace("$GENKIT_CONFIG_IMPORTS", imports)
.replace("$GENKIT_CONFIG_PLUGINS", plugins);
.replace("$GENKIT_CONFIG_PLUGINS", plugins)
.replaceAll("$TELEMETRY_COMMENT", enableTelemetry ? "" : "// ");
}

function generateImportStatement(imports: string, name: string): string {
Expand Down
5 changes: 5 additions & 0 deletions templates/genkit/firebase.1.0.0.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { onCallGenkit, hasClaim } from "firebase-functions/https";
import { defineSecret } from "firebase-functions/params";
const apiKey = defineSecret("GOOGLE_GENAI_API_KEY");

// The Firebase telemetry plugin exports a combination of metrics, traces, and logs to Google Cloud
// Observability. See https://firebase.google.com/docs/genkit/observability/telemetry-collection.
$TELEMETRY_COMMENTimport {enableFirebaseTelemetry} from "@genkit-ai/firebase";
$TELEMETRY_COMMENTenableFirebaseTelemetry();

const ai = genkit({
plugins: [
$GENKIT_CONFIG_PLUGINS
Expand Down
Loading