When using GenAI APIs for the first time, the key metric to focus on is response relevance. This means how well the AI's answers match what you asked. Since GenAI often generates text, measuring exact correctness is tricky. Instead, you look at how useful and accurate the responses feel. Another important metric is latency, or how fast the API responds, because quick answers improve user experience.
First interaction with GenAI APIs - Model Metrics & Evaluation
Start learning this pattern below
Jump into concepts and practice - no test required
For GenAI text generation, a confusion matrix is not typical. Instead, you can think of evaluation like this:
User Query: "What is the capital of France?"
Possible AI Responses:
- Correct: "Paris"
- Incorrect: "Berlin"
Evaluation:
- True Positive (TP): AI gives "Paris" when asked about France's capital.
- False Positive (FP): AI gives "Paris" when asked about Germany's capital.
- False Negative (FN): AI fails to say "Paris" when asked about France.
- True Negative (TN): AI correctly does not say "Paris" for unrelated questions.
This helps understand when the AI is right or wrong in context.
In GenAI APIs, precision means how often the AI's answers are correct when it gives an answer. Recall means how often the AI provides an answer when it should.
Example: If you ask many questions, and the AI only answers some, it might have high precision (answers are mostly right) but low recall (misses many questions).
For a chatbot, you want a balance: good precision so answers are reliable, and good recall so it answers most questions.
Good: The AI answers 90% of questions correctly (high precision) and responds to 85% of questions asked (high recall). Response time is under 1 second.
Bad: The AI answers only 50% of questions correctly and skips many questions (low recall). Responses take over 5 seconds, frustrating users.
- Accuracy paradox: If most questions are easy, a model that always answers "I don't know" might seem accurate but is useless.
- Data leakage: Testing on questions the AI was trained on can inflate performance.
- Overfitting: AI might memorize answers instead of understanding, failing on new questions.
- Ignoring latency: Fast but wrong answers are worse than slower, correct ones.
Your GenAI model answers 98% of questions with 98% accuracy but only responds to 12% of questions asked. Is it good for production? Why or why not?
Answer: No, because the model rarely answers questions (low recall). Even if answers are mostly correct, users will be frustrated by many unanswered queries.
Practice
Solution
Step 1: Understand what GenAI APIs do
GenAI APIs let you send a prompt (a question or task) to an AI model.Step 2: Identify the response from the API
The API returns a text response generated by the AI based on your prompt.Final Answer:
To send a prompt and receive a text response from the AI model -> Option DQuick Check:
GenAI API = prompt in, text out [OK]
- Thinking you train the AI on first use
- Believing you write AI code manually
- Confusing API with data storage
Solution
Step 1: Check the correct parameter name for prompt
The GenAI API expects the prompt to be passed with the keyword 'prompt'.Step 2: Verify the syntax for calling the API
Using named argument prompt='Hello AI!' matches the expected syntax.Final Answer:
response = genai.ask(prompt='Hello AI!') -> Option CQuick Check:
Use prompt= keyword to send text [OK]
- Omitting the prompt= keyword
- Using wrong parameter name like input=
- Passing variable without quotes when string needed
response = genai.ask(prompt='What is 2 + 2?') print(response.text)
Solution
Step 1: Understand the prompt sent to the AI
The prompt asks the AI a simple math question: 'What is 2 + 2?'.Step 2: Predict the AI's text response
The AI will respond with the answer '4' as text, accessible via response.text.Final Answer:
'4' -> Option AQuick Check:
Simple math prompt returns answer text [OK]
- Expecting the prompt text to be printed
- Assuming response.text does not exist
- Thinking AI returns full sentence instead of just answer
response = genai.ask('Hello AI!')
print(response.text)
What is the likely cause?Solution
Step 1: Check how the prompt is passed to genai.ask()
The code passes 'Hello AI!' without specifying prompt= keyword.Step 2: Understand the API expects prompt= keyword
Without prompt=, the function may raise an error or not recognize the input.Final Answer:
The prompt argument is missing its keyword name -> Option BQuick Check:
Always use prompt= when calling genai.ask() [OK]
- Passing prompt as positional argument
- Assuming print statement causes error
- Thinking response.text is invalid
Solution
Step 1: Identify the prompt that clearly states the task
Send prompt='Write a short story about a cat in 3 sentences.' specifies the topic (cat), the type (short story), and length (3 sentences).Step 2: Compare other prompts for clarity
Options B, C, and D are vague and may produce unrelated or too long responses.Final Answer:
Send prompt='Write a short story about a cat in 3 sentences.' -> Option AQuick Check:
Clear, detailed prompts get better AI answers [OK]
- Using too short or vague prompts
- Not specifying length or topic clearly
- Expecting AI to guess details
