|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Integrating an LLM-Based Chatbot into a reVISit Study" |
| 4 | +authors: |
| 5 | + - he |
| 6 | + - lex |
| 7 | +--- |
| 8 | + |
| 9 | +Studying how people interact with AI is increasingly relevant, and when that AI is embedded in an interactive system, such as a data visualization, the questions get even more interesting. With reVISit, you can now integrate an LLM-based chatbot directly into your study workflow. In this post, we walk through a working demo and show you how to adapt it for your own research. |
| 10 | + |
| 11 | +<!-- truncate --> |
| 12 | + |
| 13 | +Take a look at our [demo study](https://revisit.dev/study/example-llm-chatbot/). The goal of this scenario was to help people learn about a chart. In this context, the chatbot should do more than simply generate answers. It should understand the study context, respond based on relevant materials, maintain continuity across turns, and make every interaction traceable for later analysis. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +Below, we describe why this chatbot is useful for studies, highlight its core features, and explain how to customize it. |
| 18 | + |
| 19 | + |
| 20 | +## What does this chatbot enable in our demo study? |
| 21 | + |
| 22 | +In the demo study, participants can ask questions about a clustered heatmap, and the chatbot responds with streaming text. When a question requires exact data values or visual details, the chatbot can request the dataset or chart image. All inputs and outputs are tracked by [Trrack, our provenance library](https://apps.vdl.sci.utah.edu/trrackjs/), making it possible to analyze how participants interact with the chatbot and what information they request. |
| 23 | + |
| 24 | +Our example uses the [OpenAI Responses API](https://developers.openai.com/api/reference/resources/responses) and is implemented with the following features: |
| 25 | + |
| 26 | +- **Conversation memory:** keeps the model aware of prior turns |
| 27 | +- **Streaming responses:** reduce perceived latency and make the interface feel more responsive |
| 28 | +- **Sending the chart image and dataset only when needed:** gives the chatbot access to study materials only when required |
| 29 | +- **Recording provenance and conversation history:** makes interactions traceable for later analysis |
| 30 | + |
| 31 | +## How can you use and customize it? |
| 32 | + |
| 33 | +The demo is designed to be flexible (check out the [code](https://github.com/revisit-studies/study/tree/main/src/public/example-llm-chatbot/assets)). Most settings live in `ChatInterface.tsx`, where you can customize the chatbot’s behavior and study materials. |
| 34 | + |
| 35 | +### Set up the API key |
| 36 | + |
| 37 | +One challenge with LLM-based interfaces is keeping API keys secure in a (mostly) serverless environment such as a reVISit study. Our demo uses a proxy server to get around this problem. We created a simple proxy server for you, which you can find at [https://github.com/visdesignlab/openai-api-proxy](https://github.com/visdesignlab/openai-api-proxy). |
| 38 | + |
| 39 | +After deploying the proxy, set `VITE_OPENAI_API_URL` in your `.env` file for either local development or production. |
| 40 | + |
| 41 | +### Adjust the Chatbot Behavior |
| 42 | + |
| 43 | +All key settings live in `ChatInterface.tsx`. The most relevant parameters are: |
| 44 | + |
| 45 | +**Change the assistant behavior (system prompt)** |
| 46 | +Edit `prePrompt` and `toolPolicy` to control how the assistant responds and when it should use tools. |
| 47 | + |
| 48 | +Learn more: [System instructions](https://platform.openai.com/docs/guides/responses#system-instructions) |
| 49 | + |
| 50 | +**Change the model** |
| 51 | +Update `model` in both the tool-selection request and the streaming request. |
| 52 | + |
| 53 | +Learn more: [Model list](https://platform.openai.com/docs/models) |
| 54 | + |
| 55 | +**Change response length and style** |
| 56 | + |
| 57 | +- `max_output_tokens`: maximum reply length |
| 58 | +- `temperature`: creativity level |
| 59 | + |
| 60 | +Learn more: [Responses API parameters](https://platform.openai.com/docs/api-reference/responses) |
| 61 | + |
| 62 | +### Replace the study materials |
| 63 | + |
| 64 | +You can also swap in your own resources: |
| 65 | + |
| 66 | +- Replace `assets/data/clustered-heatmap.csv` with your dataset |
| 67 | +- Replace the chart image file ID with your own uploaded chart image |
| 68 | + |
| 69 | +Learn more: [Files API](https://platform.openai.com/docs/api-reference/files) |
| 70 | + |
| 71 | +This makes it straightforward to adapt the demo to different tasks, datasets, and visualizations. |
| 72 | + |
| 73 | +### Get the results |
| 74 | + |
| 75 | +You can review participants’ interactions in the replay interface. The chat history is also included in the downloaded results in CSV or JSON format. |
| 76 | + |
| 77 | +## Next steps |
| 78 | + |
| 79 | +Of course, you can also build wildly different intelligent interfaces to study, using our simple example here as a launching point! |
| 80 | + |
| 81 | +This setup can also be combined with [audio recording](https://revisit.dev/docs/designing-studies/think-aloud/) or [screen recording](https://revisit.dev/docs/designing-studies/record-screen/) for remote unmoderated studies. |
| 82 | + |
| 83 | +If you have questions or want to share what you build, come find us in the [reVISit Slack](https://revisit-nsf.slack.com/join/shared_invite/zt-25mrh5ppi-6sDAL6HqcWJh_uvt2~~DMQ). We’d be excited to see how you apply these ideas in your own prototypes. |
| 84 | + |
| 85 | + |
| 86 | +## Relevant Links |
| 87 | + |
| 88 | +* [Demo study](https://revisit.dev/study/example-llm-chatbot/) |
| 89 | +* [The Study Config](https://github.com/revisit-studies/study/blob/main/public/example-llm-chatbot/config.json) |
| 90 | +* [The React Component Sources](https://github.com/revisit-studies/study/tree/main/src/public/example-llm-chatbot) |
| 91 | + |
0 commit comments