#llm
20 snippets tagged with #llm
OpenAI Chat Completion with Streaming
Stream GPT responses token-by-token using the OpenAI SDK with async iteration.
Best for: chatbot UI
RAG Pipeline (Retrieve + Augment + Generate)
Minimal RAG implementation: embed a query, retrieve top-k chunks, inject into prompt.
Best for: document Q&A
Claude Messages API (Anthropic SDK)
Send messages to Claude using the official Anthropic SDK with system prompt and user turn.
Best for: AI assistant
LangChain Prompt Chain (Python)
Build a simple LLMChain with a prompt template and ChatOpenAI in LangChain.
Best for: prompt chaining
LangChain RAG Chain Pipeline
Build a retrieval-augmented generation chain with LangChain using vector store retrieval and prompt templates.
Best for: Document Q&A
Few-Shot Prompt Template
Build structured few-shot prompts with examples, system instructions, and output format constraints.
Best for: Consistent AI outputs
AI Agent Loop with Tool Calling
Implement an autonomous agent loop that plans, selects tools, executes actions, and observes results.
Best for: Research assistants
AI Guardrails & Safety Pattern
Implement input/output guardrails for LLM applications with content filtering and response validation.
Best for: User-facing chatbots
Google Gemini API Integration
Call the Google Gemini API for text generation with streaming, safety settings, and system prompts.
Best for: Google AI-powered code generation
LLM JSON Output Parser
Parse and validate JSON responses from LLMs with retry logic and schema enforcement using Zod.
Best for: Extracting structured data from LLM responses
AI Prompt Chaining Pattern
Chain multiple LLM calls sequentially where each step's output feeds into the next for complex tasks.
Best for: Complex multi-step AI workflows
Semantic Caching Layer for LLM Calls
Cache LLM responses by semantic similarity of prompts to reduce API costs and improve latency.
Best for: Reducing LLM API costs for repeated queries
RAG Pipeline Implementation
Build a retrieval-augmented generation pipeline that grounds LLM answers in your own documents.
Best for: Grounding LLM answers in private documents
Prompt Template Engineering Patterns
Design reusable, parameterized prompt templates for consistent LLM outputs.
Best for: Consistent LLM outputs
Mistral AI API Client in Python
Make chat and embedding requests to Mistral AI using the official Python SDK.
Best for: European AI compliance
Jinja2 Prompt Templates for AI
Manage complex AI prompt templates with Jinja2 for reusable, parameterised prompt generation.
Best for: prompt management
NeMo Guardrails for Safe LLM
Apply NVIDIA NeMo Guardrails to enforce topic boundaries and prevent prompt injection in LLM apps.
Best for: LLM safety
LLM Prompt Testing Framework
Write automated tests for LLM prompts using Python assertions to detect regressions.
Best for: prompt regression testing
Async AI Inference with Celery
Offload slow LLM inference to Celery background workers with Redis as broker and result backend.
Best for: async AI processing
LLM Testing with DeepEval
Write unit tests for LLM outputs using the DeepEval framework for correctness and hallucination detection.
Best for: LLM testing