Generate text with Vercel's AI SDK
Now that we know how to get a response from OpenAI (or other) LLM models, let's work on the CLI interface.
We will use a popular library Commander.js - there may be other, smaller libraries to explore, but since there's a lof of good documentation and examples for this library for further exploration, we will use it.
We can start with simple initialization of Commander.js. Provide basic information about then command. Don't forget to
call the parse() method!
Changing the model or provider as as simple as replacing the model passed to the generateText() call.
Let's look at the complete example.
1const program = new Command()23program.name('ai-chat').description('CLI tool for chatting with AI using different personas').version('1.0.0')45program.parse()
Now try to run the script using the following command. How nice! Github contains the whole example.
In this lesson, we integrated Commander.js into our AI SDK example. Let's continue to make this work as a real chat!