## Overview The Web Service feature in Qualtrics is used in this template to make API calls to OpenRouter for summarizing the user's initial conspiracy theory input. This method provides a user-friendly, low-code approach to integrating external APIs within a Qualtrics survey. ## Request If you use our template (.QSF) to set up your research, we would appreciate it if you cite our paper when describing your method: > [Durably reducing conspiracy beliefs through dialogues with AI](https://osf.io/preprints/psyarxiv/xcwdn) ## Web Service Configuration The Web Service is configured in the Survey Flow, typically in the first interaction with the LLM. Here's a breakdown of its setup: 1. **Location**: Found in the "Questions (answers placed into prompt)" block of the Survey Flow. 2. **Purpose**: To summarize the user's conspiracy theory input using the LLM. ## Key Components ### 1. URL ``` https://openrouter.ai/api/v1/chat/completions ``` This is the endpoint for OpenRouter's chat completions API. ### 2. Method Set to `POST` for sending data to the API. ### 3. Body Parameters The body is sent as JSON and includes: - `model`: Uses the `${e://Field/setModel}` embedded data field to specify the LLM. - `messages`: An array containing the system prompt and user input. - `max_tokens`: Set to 150, limiting the length of the response. Example: ```json { "model": "${e://Field/setModel}", "messages": [ { "role": "system", "content": "Summarize the following passage, which describes a conspiratorial belief, in a single sentence. Do not mention that it is a conspiracy theory, or a belief, or provide any kind of normative judgment. Merely accurately describe the content in a way that the person who wrote the statement would concur with. Frame it as an assertion." }, { "role": "user", "content": "Question 1 Response: ${e://Field/UserConspiracy_Part1}, Question 2 Response: ${e://Field/UserConspiracy_Part2}" } ], "max_tokens": 150 } ``` ### 4. Headers Includes the Authorization header with the OpenRouter API key: ``` Authorization: ${e://Field/OpenRouterAPIKey} ``` ### 5. Response Mapping Maps the API response to an embedded data field: ``` choices.0.message.content -> SummarizedConspiracy ``` This extracts the content of the LLM's response and saves it as `SummarizedConspiracy`. ## Advantages of Web Service 1. **User-Friendly**: Provides a graphical interface for setting up API calls. 2. **Built-in Error Handling**: Qualtrics manages timeouts and basic error responses. 3. **Easy Integration**: Seamlessly fits into the Survey Flow. 4. **Dynamic Input**: Can use embedded data and piped text as inputs. ## Limitations 1. **Timeout Issues**: May encounter problems with longer API calls. 2. **Limited Flexibility**: Less control over the API call process compared to custom JavaScript. 3. **Debugging Challenges**: Error messages may be less detailed than in custom code. ## When to Use Web Service vs. Custom JavaScript - **Use Web Service when**: - Making simple, quick API calls - You prefer a visual setup to coding - The API call doesn't require complex pre-processing or post-processing - **Use Custom JavaScript when**: - You need more control over the API call process - Handling complex scenarios or multiple API calls - Implementing custom error handling or retries - Performing extensive data manipulation before or after the API call By understanding and effectively utilizing the Web Service feature, you can enhance your Qualtrics surveys with powerful LLM capabilities while maintaining a relatively simple setup process.