Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@beeper/pickle-ai-sdk

Pipe an AI SDK UI message stream straight into a Matrix message via @beeper/pickle-chat-adapter.

npm install @beeper/pickle-ai-sdk

Usage

import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { fromAIStreamResult } from "@beeper/pickle-ai-sdk";

bot.onNewMention(async (thread, message) => {
  await thread.subscribe();

  const result = streamText({ model: openai("gpt-4o"), prompt: message.text });

  await matrix.stream(
    matrix.encodeThreadId({ roomId: message.raw.roomId }),
    fromAIStreamResult(result),
  );
});

The adapter handles debounced edits — or native streaming on Beeper.

API

fromAIStreamResult(result)        // anything with .toUIMessageStream()
fromAIUIMessageStream(stream)     // already have a UI message stream?
isAIUIMessageStreamResult(value)  // type guard

All three return a MatrixStream you hand to matrix.stream(). Split out so the chat adapter doesn't pull the AI SDK in unless you need it.

License

MIT