Created
January 30, 2026 14:53
-
-
Save alexanderson1993/65db235eb6fa19f3684dabab3c8209cb to your computer and use it in GitHub Desktop.
A simple programmable AI CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { type ModelMessage, generateText } from 'ai'; | |
| import { intro, log, text, isCancel, outro, spinner } from '@clack/prompts'; | |
| import { anthropic } from '@ai-sdk/anthropic'; | |
| intro(`AI Assistant`); | |
| const systemContent = `You are a helpful AI assistant` | |
| const conversation: ModelMessage[] = [ | |
| { | |
| role: 'system', | |
| content: systemContent | |
| } | |
| ]; | |
| while (true) { | |
| const question = await text({ message: '' }); | |
| if (isCancel(question)) { | |
| break; | |
| } | |
| conversation.push({ role: 'user', content: question }); | |
| await getResponse(); | |
| } | |
| outro('See you later!'); | |
| async function getResponse() { | |
| const s = spinner(); | |
| s.start('Generating response...'); | |
| console.time('Generate'); | |
| const { text } = await generateText({ | |
| model: anthropic('claude-haiku-4-5-20251001'), | |
| // model: openai('gpt-5-mini'), | |
| messages: conversation, | |
| }); | |
| console.timeEnd('Generate'); | |
| s.stop(''); | |
| log.info(text); | |
| conversation.push({ role: 'assistant', content: text }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment