#openai
12 snippets tagged with #openai
OpenAI Chat Completion with Streaming
Stream GPT responses token-by-token using the OpenAI SDK with async iteration.
Generate Text Embeddings with OpenAI
Create vector embeddings for semantic search and similarity matching using text-embedding-3-small.
RAG Pipeline (Retrieve + Augment + Generate)
Minimal RAG implementation: embed a query, retrieve top-k chunks, inject into prompt.
OpenAI Tool Calling (Function Calling)
Define tools for GPT to call, parse the response, execute the function, and return results.
LangChain Prompt Chain (Python)
Build a simple LLMChain with a prompt template and ChatOpenAI in LangChain.
DALL·E 3 Image Generation
Generate images from a text prompt using the OpenAI DALL·E 3 API and return a URL.
OpenAI Structured Output with Zod
Force GPT-4o to return valid JSON matching a Zod schema using response_format structured output.
Content Moderation with OpenAI
Check user input for harmful content using the OpenAI Moderation API before processing.
Next.js AI Streaming Route Handler
Stream OpenAI responses from a Next.js App Router route handler using the Vercel AI SDK.
OpenAI Assistants API with Threads
Create persistent conversation threads with OpenAI Assistants API for stateful multi-turn interactions.
Token Counter with Tiktoken
Count tokens and estimate costs for OpenAI API calls using the tiktoken tokenizer library.
OpenAI Text-to-Speech
Generate natural speech audio from text using OpenAI TTS API with multiple voice options and formats.