Context
When using a pre-trained large language model, several inputs influence user experience, including the prompts used, the “inference parameters” given to the model, often including parameters like temperature, length penalties and repetition penalties, and even the exact model selected. Tools like Statsig can streamline the process of assigning users to various experiments, such as modifying these inputs, and can automatically identify when changes have a statistically significant impact on user experience metrics. This enables efficient iteration and optimization of user experience by tweaking model choices, prompts, and inference parameters. In this case we show how you can log both implicit indicators of user feedback (like response time) and more explicit ones, like self-reported satisfaction.Introduction
The included Python code offers an example of the simple but powerful interaction between OpenAI’s GPT and Statsig to experiment with model inputs and log user events. This example uses OpenAI’s ChatCompletion feature to answer questions, plus a Statsig integration to experiment with model versions and log user feedback to the changes. This example assumes you have a funded OpenAI account, plus a Statsig experiment that varies the model selected between “gpt-3.5-turbo” and “gpt-4”. For more info on setting up a Statsig experiment, see the experiments page.Code Breakdown
Initial Configuration
Of course, you’ll need to install both the Statsig and OpenAI Python packages before starting:The ask_question Function
The following code all occurs in one function titled ask_question (see the final code)- Get User Input
- Query OpenAI’s GPT
- Display Response & Log Implicit Feedback
- Collect User Feedback & Log to Statsig
Tips for Using Statsig with AI
- Experimentation: You can also test other model parameters like temperature, top_p, or initial prompts.
- Log Useful Data: Consider logging other interesting user interactions or feedback.
- Analyze and Iterate: After collecting enough data, analyze the results on the Statsig dashboard.
- User Identification: Consider integrating a mechanism to uniquely identify each user/session.
Always ensure you’re in compliance with user privacy regulations and that you have user consent where necessary.