docs: add verified package usage examples
This commit is contained in:
@@ -122,6 +122,8 @@ try {
|
||||
|
||||
## Usage
|
||||
|
||||
### Return generated JSON from an API route
|
||||
|
||||
```ts
|
||||
// app/api/summarize.ts — summarize posted text
|
||||
import { createAI } from "@wrnexus/ai";
|
||||
@@ -137,6 +139,23 @@ export const POST = async (ctx) => {
|
||||
};
|
||||
```
|
||||
|
||||
### Stream a chat response to the browser
|
||||
|
||||
```ts
|
||||
// app/api/chat.ts
|
||||
import { createAI } from "@wrnexus/ai";
|
||||
|
||||
const ai = createAI({ model: "claude-sonnet-5" });
|
||||
|
||||
export const POST = async (ctx) => {
|
||||
const { messages } = await ctx.req.json();
|
||||
return ai.streamResponse(messages, {
|
||||
system: "Answer using concise Markdown.",
|
||||
maxTokens: 1_500,
|
||||
});
|
||||
};
|
||||
```
|
||||
|
||||
## Requirements / Notes
|
||||
|
||||
- **Bun-only.** Uses `fetch`, `ReadableStream`, `TextDecoder`/`TextEncoder`, and
|
||||
|
||||
Reference in New Issue
Block a user