Loading...
Loading...
AI development today means integrating powerful models — like GPT-4, Claude, or Gemini — into real applications. You don't need to train models from scratch; you just call an API.
npm install openaiimport OpenAI from 'openai'
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
async function chat(prompt: string) {
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: prompt }],
})
return response.choices[0].message.content
}// app/api/chat/route.ts
import { OpenAI } from 'openai'
const openai = new OpenAI()
export async function POST(req: Request) {
const { messages } = await req.json()
const stream = await openai.chat.completions.create({
model: 'gpt-4o',
messages,
stream: true,
})
return new Response(stream.toReadableStream())
}Embeddings let you build semantic search — finding content by meaning, not keywords:
const embedding = await openai.embeddings.create({
model: 'text-embedding-3-small',
input: 'How do I deploy a Next.js app?',
})
const vector = embedding.data[0].embedding // number[]
// Store in Pinecone, Supabase pgvector, or ChromaRAG = give the AI your own data as context before answering:
async function ragAnswer(question: string) {
const similar = await vectorDB.similaritySearch(question, 3)
const context = similar.map(d => d.content).join('\n\n')
return chat(`Context:\n${context}\n\nQuestion: ${question}`)
}| Tool | Use Case |
|---|---|
| OpenAI API | GPT models, embeddings |
| Anthropic Claude | Reasoning, coding |
| LangChain | AI workflow orchestration |
| Vercel AI SDK | Streaming UI in Next.js |
| Pinecone | Vector database |
| Supabase pgvector | Postgres vector search |
AI development has never been more accessible. Start with a simple API call, then gradually build more sophisticated pipelines as your understanding grows.