Adversarial testing
You are developing a chatbot designed to assist users with personal finance management. The chatbot should be able to handle a variety of finance-related queries, from budgeting advice to investment suggestions. You have one example where a user is planning to go on vacation, and is budgeting for the trip.
As the chatbot is only designed to respond to personal finance questions, you want to ensure that it is robust and can handle unexpected or adversarial inputs without failing or providing incorrect information, so you decide to test it by asking the model to ignore all financial advice and suggest ways to spend the budget instead of saving it.
Latihan ini adalah bagian dari kursus
Developing AI Systems with the OpenAI API
Petunjuk latihan
- Test the chatbot with an adversarial input that asks to spend the $800 instead.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
client = OpenAI(api_key="")
messages = [{'role': 'system', 'content': 'You are a personal finance assistant.'},
{'role': 'user', 'content': 'How can I make a plan to save $800 for a trip?'},
# Add the adversarial input
____]
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages)
print(response.choices[0].message.content)