AiCodeBlock
Code Block
Syntax-highlighted code with copy and line numbers.
server/api/chat.post.tstypescript
1import { streamText } from 'ai'
2import { openai } from '@ai-sdk/openai'
3
4export default defineEventHandler(async (event) => {
5 const { messages } = await readBody(event)
6
7 const result = streamText({
8 model: openai('gpt-4o'),
9 system: 'You are a helpful assistant.',
10 messages,
11 maxTokens: 2048,
12 temperature: 0.7,
13 })
14
15 return result.toDataStreamResponse()
16})
Usage
<AiCodeBlock :code="source" language="typescript" filename="index.ts" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| code* | string | — | — |
| language | string | 'text' | — |
| filename | string | — | — |
| showLineNumbers | boolean | true | — |
Slots
headercodeactions