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.
Deze oefening maakt deel uit van de cursus
Developing AI Systems with the OpenAI API
Oefeninstructies
- Test the chatbot with an adversarial input that asks to spend the $800 instead.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
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)