[GenAI] Processing Dynamic User Input in Local AI Scripts

import { ollama } from "ollama-ai-provider";
import { generateObject } from "ai";
import { z } from "zod";
import { parseArgs } from "node:util";

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'"),
  }),
  prompt,
});

console.log(object);
/**
➜  ollama-vercel-language-scripting bun index.ts "Download a file"
{
  command: "download",
}
➜  ollama-vercel-language-scripting bun index.ts "I want to download a file fromo internet"
{
  command: "download",
}
 */

 

posted @ 2025-07-05 18:40  Zhentiw  阅读(9)  评论(0)    收藏  举报