Skip to main content

Command Palette

Search for a command to run...

Basics of GenAi

Published
8 min readView as Markdown
Basics of GenAi

1. Key Full Forms

AcronymFull FormShort MeaningExample Use
LLMLarge Language ModelAI model trained on massive text data to understand and generate languageChatGPT answering your questions
GPTGenerative Pre-trained TransformerType of LLM trained in two steps — first learns language patterns from huge data, then fine-tuned for tasksGPT-4 writing a blog post
RAGRetrieval-Augmented GenerationTechnique where an LLM fetches extra data from an external source before answering, so it’s more accurateAn AI that searches a company database before replying

2. LLMs (Large Language Models)

  • Definition: AI models trained on huge amounts of text data to understand and generate human-like language.

  • Example: ChatGPT, Claude, Gemini — they can answer questions, write essays, or even generate code.

  • Analogy: Like a super well-read friend who has read millions of books and can talk about almost anything.


3. GPT vs Reasoning Apps

FeatureGPT (General Purpose)Reasoning App
Main GoalBroad knowledge & natural conversationDeep logical problem solving
StrengthsCreativity, language understanding, knowledge recallStep-by-step reasoning, decision making
ExampleGPT can write a poem or explain a science topicA reasoning app can solve a complex math puzzle or plan a multi-step project

4. Few LLMs & Their Capabilities

LLM NameKey StrengthsExample Use
GPT-4 / GPT-5Language understanding, creativity, codingWriting blogs, solving coding problems
ClaudeLong context handling, polite toneAnalyzing 100+ page documents
GeminiGoogle search integrationReal-time updated answers
LLaMAOpen-source flexibilityCustom AI projects
Gemma 2 InstructSupports tool calling (can call APIs, databases, or other functions directly from responses)Automating workflows — e.g., getting live stock prices, booking flights, or triggering scripts

5. Tokens & Tokenizers

  • Tokens: Small pieces of text (words or subwords) that an LLM reads and processes.

  • Key Point: Models understand tokens, not whole words.

  • Tokenizer: Breaks a sentence into tokens; different models use different tokenizers.

    • Example: “I love cats” → "I", " love", " cats"

    • "unbelievable""un", "believ", "able"

  • Tiktoken: Example tokenizer used by OpenAI models.

  • Billing: You pay for tokens, not words.


6. Context

  • Definition: The combined information the model uses to generate a response.

  • Made up of:

    1. User Inputs — Latest prompt

    2. Instructions — Rules or roles for the AI

    3. Additional Information — Facts, uploaded files, retrieved documents

    4. Message History — Previous conversation turns

  • Example: Asking "Summarize this report" includes the report, your request, prior clarifications, and assigned roles.


7. Context Window

  • Definition: Maximum number of tokens the model can remember at once.

  • Examples:

    • GPT-3: ~2,048 tokens (~1,500 words)

    • GPT-4.1: Up to 1 million tokens (~750,000 words)


8. Knowledge Cutoff

  • Definition: Latest date up to which the model has been trained.

  • Why it matters: Model won’t know events after this date unless connected to real-time tools.


9. Attention Is All You Need

  • Definition: Research paper introducing Transformer architecture, which powers modern LLMs.

  • Key idea: Uses attention to focus on important words rather than reading sequentially.


10. Distilled LLMs

  • Definition: Smaller, faster versions of big LLMs via knowledge distillation.

  • Benefits: Faster, cheaper, lighter.

  • Trade-off: Slightly less depth in answers.


11. GroqCloud

  • Definition: Cloud platform providing ultra-fast inference using Groq chips.

12. Inference

  • Definition: Time it takes for a model to process input and produce output.

  • Factors: Model size, hardware, task complexity.


13. Prompt Engineering

  • Definition: Crafting prompts to improve answer quality, accuracy, and consistency. Good prompt engineering ensures the model outputs what you want in a clear, reliable way.

Types of Prompting & When to Use

Prompt TypeWhen to UseProsConsNotes
Zero-shotSimple tasks, when no examples are availableQuick, no setup`Can be inconsistent, prone to hallucinationWorks for general questions but less reliable for complex or multi-step tasks
Few-shotComplex tasks, when accuracy and consistency matterMore reliable, reduces hallucination, guides styleRequires examples, slightly more setupPreferred for multi-step tasks or specific formats
Chain-of-Thought (CoT)Reasoning or multi-step problems, explaining logicProduces step-by-step reasoning, helps debuggingSlower, verboseNot needed if using reasoning-focused models (they handle steps internally)
Negative PromptingAvoiding unwanted outputs (e.g., “Do not include…” instructions)Can steer model away from errorsCan confuse model if overusedUse sparingly, combine with clear positive instructions

Elements of a Prompt

ElementDescriptionExample
InstructionsWhat the model should do“Write a formal email”
Input DataContent or question to process“Client request: …”
ContextExtra guidance“You are an expert in project management”
Output IndicatorHow answer should be formatted“Use bullet points, max 150 words”

When to Use Each Prompt

  • Zero-shot: Quick answers, testing ideas, or general questions.

  • Few-shot: When style, accuracy, or specific formatting matters.

  • CoT: Multi-step reasoning or tasks needing logic explanations.

  • Negative prompting: Only to steer away from specific unwanted behaviors; combine with positive instructions.


Types of Prompting with Examples

1. Zero-shot Prompting

(No examples are given; just instructions and input.)

Example 1:

Prompt:

“Translate the following sentence into French: I love learning new things.

Output:

“J’aime apprendre de nouvelles choses.”

Example 2:

Prompt:

“Write a tweet about coffee in less than 15 words.”

Output:

“Coffee: the fuel that turns thoughts into action. ☕🔥”


2. Few-shot Prompting

(A few examples are provided before asking the model to generate new outputs.)

Example 1:

Prompt:

“Classify the sentiment of the following reviews as Positive, Neutral, or Negative.

  • ‘The food was delicious and service was amazing!’ → Positive

  • ‘The movie was okay, nothing special.’ → Neutral

  • ‘The product broke the first day I used it.’ → Negative

    Now classify: ‘The delivery was quick but packaging was bad.’”

    Output:

    “Neutral”

Example 2:

Prompt:

“Convert numbers to words.

  • 42 → forty-two

  • 103 → one hundred three

  • 999 → nine hundred ninety-nine

    Now convert: 275”

    Output:

    “two hundred seventy-five”


3. Chain-of-Thought (CoT) Prompting

(Ask model to “think step by step” for reasoning tasks.)

Example 1:

Prompt:

“If a train travels 60 km in 1 hour, how far will it travel in 4.5 hours? Think step by step.”

Output (CoT):

  • Speed = 60 km/h

  • Time = 4.5 hours

  • Distance = 60 × 4.5 = 270 km

    Final Answer: 270 km

Example 2:

Prompt:

“A shopkeeper bought 50 apples at ₹20 each. He sold them at ₹25 each. What is his profit? Think step by step.”

Output (CoT):

  • Cost price per apple = ₹20

  • Selling price per apple = ₹25

  • Profit per apple = 25 – 20 = ₹5

  • Total apples = 50

  • Total profit = 50 × 5 = ₹250

    Final Answer: ₹250


4. Negative Prompting

(Steer the model away from unwanted behavior.)

Example 1:

Prompt:

“Write a professional email to a client about project delay. Do not use any casual words like ‘hey,’ ‘buddy,’ or emojis.”

Output:

“Dear Client,

We regret to inform you that the project will be delayed by two weeks…”

Example 2:

Prompt:

“Summarize this article in 100 words. Do not add your own opinions or analysis.”

Output:

“A summary of the article without extra interpretation.”


General Tips for Effective Prompting

  1. Start simple and iterate

    • Test a basic prompt first, then refine.

    • Example: “Summarize this article”“Summarize in 100 words with bullet points.”

  2. Clearly state instructions

    • Avoid ambiguous language.

    • Example: “Write a professional email to a client summarizing the update in three bullet points.”

  3. Use separators

    • Helps model distinguish instructions, data, and expected output.

    • Examples: """ or ###

  4. Be specific and detailed

    • Include style, tone, format, and length.

    • Example: “Write a 150-word summary in a casual tone suitable for teenagers.”

  5. Provide examples of desired output

    • Guides the model on style and content.

    • Example: Show one sample summary before asking for another.

  6. Avoid negative instructions when possible

    • Instead of “Do not include slang,” say “Use professional language.”
  7. Move from simple to complex

    • Break tasks into steps.

    • Example: First list key points, then expand each into paragraphs.

  8. Reduce fluff

    • Avoid vague or overly descriptive language; keep prompts concise but clear.
  9. Leverage leading words for code generation

    • Words like Write, Generate, Create help the model understand intent for code tasks.

    • Example: “Generate a Python function that sorts a list of numbers in ascending order.”

More from this blog