Lesson

Generating Text with a Local AI Model Based on File Content

Access
Included
Transcript
Needs source

Once your script can understand a user's command and identify a target file, the next step is to perform an action. This lesson shows you how to use the Vercel AI SDK's generateText function to process a file's content and produce a relevant, AI-generated response.

You'll learn how to read the content from the file path you've already identified, combine it with the inferred command into a new, more detailed prompt, and then pass it back to your local AI model to generate a final text output, such as a summary or a review.

Workflow demonstrated in this lesson:

  • Import the generateText function from the ai SDK.
  • Read the file content from the filePath returned by generateObject.
  • Construct a new, structured prompt that includes the original command (e.g., "summarize") and the full content of the file.
  • Pass this new prompt to the generateText function.
  • Log the resulting AI-generated text to the console.
  • Run the script with commands like "Summarize our TypeScript config" or "Review my package file" to see the full, context-aware output.

This lesson completes the core cycle of your AI script: understanding a command, reading the relevant context, and generating a useful, text-based result, all on your local machine.