AI2025년 12월 13일2분 읽기

Vercel AI SDK — AI 기능을 웹앱에 쉽게 통합

YS
YoungSam
조회 331

AI SDK 시작하기

import { generateText, streamText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

// 스트리밍 텍스트 생성
const result = streamText({
  model: anthropic("claude-sonnet-4-20250514"),
  prompt: "TypeScript의 장점을 설명해주세요",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

React Hook

"use client";
import { useChat } from "ai/react";

export function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useChat();
  return (
    <form onSubmit={handleSubmit}>
      {messages.map(m => <div key={m.id}>{m.content}</div>)}
      <input value={input} onChange={handleInputChange} />
    </form>
  );
}
VercelAI SDKStreaming

댓글 0

아직 댓글이 없습니다.