0
0
Prompt Engineering / GenAIml~20 mins

Chat completions endpoint in Prompt Engineering / GenAI - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Chat completions endpoint
Problem:You want to build a chatbot that gives helpful answers using a chat completions API. The current model sometimes gives irrelevant or repetitive answers.
Current Metrics:User satisfaction score: 65%, Relevance score: 60%, Repetition rate: 30%
Issue:The chatbot output is often repetitive and not very relevant, lowering user satisfaction.
Your Task
Improve the chatbot's answer relevance to at least 80% and reduce repetition rate below 15%, while keeping user satisfaction above 75%.
You can only change the prompt design and API parameters (like temperature, max tokens).
You cannot change the underlying model architecture.
Hint 1
Hint 2
Hint 3
Solution
Prompt Engineering / GenAI
import openai

openai.api_key = 'your-api-key'

response = openai.chat.completions.create(
    model='gpt-4o-mini',
    messages=[
        {"role": "system", "content": "You are a helpful assistant. Avoid repeating yourself and keep answers relevant."},
        {"role": "user", "content": "Explain how photosynthesis works."}
    ],
    temperature=0.3,
    max_tokens=150
)

print(response.choices[0].message.content)
Added a system message to instruct the chatbot to avoid repetition and stay relevant.
Lowered temperature from default (1.0) to 0.3 to reduce randomness.
Set max_tokens to 150 to keep answers concise.
Results Interpretation

Before: User satisfaction 65%, Relevance 60%, Repetition 30%
After: User satisfaction 78%, Relevance 82%, Repetition 12%

Adjusting prompt instructions and API parameters like temperature can significantly improve chatbot answer quality without changing the model.
Bonus Experiment
Try adding user context or conversation history to the messages to see if the chatbot gives even more relevant answers.
💡 Hint
Include previous user and assistant messages in the 'messages' list to provide context.