GitXplorerGitXplorer
l

tsx-ai

public
8 stars
2 forks
0 issues

Commits

List of commits on branch main.
Verified
73e7a7a823b948ce2f303bcb1065bea6f94bdf88

Update README.md

llgrammel committed 3 months ago
Unverified
44cbda3d84c0b1af58b998544bf5f668c5d11fd8

add guide

llgrammel committed 3 months ago
Verified
1ef79e08c7b766a1b80d4aaf6a48723ad27b966a

Initial commit

llgrammel committed 3 months ago

README

The README file for this repository.

tsx-ai

Quick guide how to use the Vercel AI SDK with TSX to create executable Node.js scripts that use AI.

  1. Install tsx globally
    npm install -g tsx
  2. Install node modules
    npm i ai @ai-sdk/openai dotenv @types/node
  3. Add OpenAI API key to .env (OPENAI_API_KEY)
  4. Write a .mts script (e.g. hello-world.mts)
    #!/usr/bin/env tsx
    
    import { openai } from "@ai-sdk/openai";
    import { streamText } from "ai";
    import { configDotenv } from "dotenv";
    
    configDotenv();
    
    const { textStream } = await streamText({
      model: openai("gpt-4o"),
      prompt: "How can I list files in bash?",
    });
    
    for await (const textPart of textStream) {
      process.stdout.write(textPart);
    }
  5. Make executable: chmod +x hello-world.mts
  6. Run: ./hello-world.mts