[GenAI] Providing File System Context to Local AI Scripts with Globby and Zod Enums
import { ollama } from "ollama-ai-provider";
import { generateObject } from "ai";
import { z } from "zod";
import { globby } from "globby";
import { parseArgs } from "node:util";
const files = await globby("**/*.json", { gitignore: true });
console.log(files);
const isNonEmpty = (files: string[]): files is [string, ...string[]] => {
return files.length > 0;
};
if (!isNonEmpty(files)) {
console.error("No files found");
process.exit(1);
}
const { positionals } = parseArgs({
allowPositionals: true,
});
const model = ollama("gemma3:latest");
const prompt = positionals[0];
const { object } = await generateObject({
model,
schema: z.object({
command: z
.string()
.describe("The command to execute, e.g. 'summarize' or 'translate'"),
filePath: z.enum(files).describe("The path to the files to prcess"),
}),
prompt,
});
console.log(object);
/**
➜ ollama-vercel-language-scripting bun index.ts
{
command: "concatenate",
}
*/