Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-1106· OpenAIHugging Face Arena Human Preference 55K

puoi convertirmi questa funzione da jqyery a vanilla js? function actiontrigger() { //…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-2-70b-chat’s answer.
  1. User

    puoi convertirmi questa funzione da jqyery a vanilla js? function action_trigger() { // send an event to the bot, so that bot can start the conversation by greeting the user .ajax({ url: `http://localhost:5005/conversations/{user_id}/execute`, type: "POST", contentType: "application/json", data: JSON.stringify({ "name": action_name, "policy": "MappingPolicy", "confidence": "0.98" }), success: function (botResponse, status) { console.log("Response from Rasa: ", botResponse, "\nStatus: ", status);

    		if (botResponse.hasOwnProperty("messages")) {
    			setBotResponse(botResponse.messages);
    		}
    		$("#userInput").prop('disabled', false);
    	},
    	error: function (xhr, textStatus, errorThrown) {
    
    		// if there is no response from rasa server
    		setBotResponse("");
    		console.log("Error from bot end: ", textStatus);
    		$("#userInput").prop('disabled', false);
    	}
    });
    

    }

  2. Assistant

    Ecco la funzione convertita da jQuery a Vanilla JavaScript:

    function action_trigger() {
      var xhr = new XMLHttpRequest();
      xhr.open("POST", `http://localhost:5005/conversations/${user_id}/execute`, true);
      xhr.setRequestHeader("Content-Type", "application/json");
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            var botResponse = JSON.parse(xhr.responseText);
            console.log("Response from Rasa: ", botResponse, "\nStatus: ", xhr.status);
    
            if (botResponse.hasOwnProperty("messages")) {
              setBotResponse(botResponse.messages);
            }
            document.getElementById("userInput").disabled = false;
          } else {
            setBotResponse("");
            console.log("Error from bot end: ", xhr.statusText);
            document.getElementById("userInput").disabled = false;
          }
        }
      };
      xhr.send(JSON.stringify({ "name": action_name, "policy": "MappingPolicy", "confidence": "0.98" }));
    }
    
  3. User

    puoi convertire questo codice da jqyery a javascript? function setBotResponse(response) {

    //display bot response after 500 milliseconds
    setTimeout(function () {
    	hideBotTyping();
    	if (response.length < 1) {
    		//if there is no response from Rasa, send  fallback message to the user
    		var fallbackMsg = "I am facing some issues, please try again later!!!";
    
    		var BotResponse = '<img class="botAvatar" src="./static/img/botAvatar.png"/><p class="botMsg">' + fallbackMsg + '</p><div class="clearfix"></div>';
    
    		$(BotResponse).appendTo(".chats").hide().fadeIn(1000);
    		scrollToBottomOfResults();
    	}
    	else {
    
    		//if we get response from Rasa
    		for (i = 0; i < response.length; i++) {
    
    			//check if the response contains "text"
    			if (response[i].hasOwnProperty("text")) {
    				var BotResponse = '<img class="botAvatar" src="./static/img/botAvatar.png"/><p class="botMsg">' + response[i].text + '</p><div class="clearfix"></div>';
    				$(BotResponse).appendTo(".chats").hide().fadeIn(1000);
    			}
    
    			//check if the response contains "images"
    			if (response[i].hasOwnProperty("image")) {
    				var BotResponse = '<div class="singleCard">' + '<img class="imgcard" src="' + response[i].image + '">' + '</div><div class="clearfix">';
    				$(BotResponse).appendTo(".chats").hide().fadeIn(1000);
    			}
    
    
    			//check if the response contains "buttons" 
    			if (response[i].hasOwnProperty("buttons")) {
    				addSuggestion(response[i].buttons);
    			}
    
    			//check if the response contains "custom" message  
    			if (response[i].hasOwnProperty("custom")) {
    
    				//check of the custom payload type is "quickReplies"
    				if (response[i].custom.payload == "quickReplies") {
    					quickRepliesData = response[i].custom.data;
    					showQuickReplies(quickRepliesData);
    					return;
    				}
    
    				//check of the custom payload type is "location"
    				if (response[i].custom.payload == "location") {
    					$("#userInput").prop('disabled', true);
    					getLocation();
    					scrollToBottomOfResults();
    					return;
    				}
    
    				//check of the custom payload type is "cardsCarousel"
    				if (response[i].custom.payload == "cardsCarousel") {
    					restaurantsData = (response[i].custom.data)
    					showCardsCarousel(restaurantsData);
    					return;
    				}
    			}
    		}
    		scrollToBottomOfResults();
    
    	}
    }, 500);
    
  4. Assistant

    Ecco la funzione convertita da jQuery a Vanilla JavaScript:

    function setBotResponse(response) {
      setTimeout(function () {
        hideBotTyping();
        if (response.length < 1) {
          var fallbackMsg = "I am facing some issues, please try again later!!!";
          var BotResponse = '<img class="botAvatar" src="./static/img/botAvatar.png"/><p class="botMsg">' + fallbackMsg + '</p><div class="clearfix"></div>';
          document.querySelector(".chats").insertAdjacentHTML('beforeend', BotResponse);
          scrollToBottomOfResults();
        } else {
          for (var i = 0; i < response.length; i++) {
            if (response[i].hasOwnProperty("text")) {
              var BotResponse = '<img class="botAvatar" src="./static/img/botAvatar.png"/><p class="botMsg">' + response[i].text + '</p><div class="clearfix"></div>';
              document.querySelector(".chats").insertAdjacentHTML('beforeend', BotResponse);
            }
            if (response[i].hasOwnProperty("image")) {
              var BotResponse = '<div class="singleCard">' + '<img class="imgcard" src="' + response[i].image + '">' + '</div><div class="clearfix">';
              document.querySelector(".chats").insertAdjacentHTML('beforeend', BotResponse);
            }
            if (response[i].hasOwnProperty("buttons")) {
              addSuggestion(response[i].buttons);
            }
            if (response[i].hasOwnProperty("custom")) {
              if (response[i].custom.payload == "quickReplies") {
                quickRepliesData = response[i].custom.data;
                showQuickReplies(quickRepliesData);
                return;
              }
              if (response[i].custom.payload == "location") {
                document.getElementById("userInput").disabled = true;
                getLocation();
                scrollToBottomOfResults();
                return;
              }
              if (response[i].custom.payload == "cardsCarousel") {
                restaurantsData = (response[i].custom.data);
                showCardsCarousel(restaurantsData);
                return;
              }
            }
          }
          scrollToBottomOfResults();
        }
      }, 500);
    }
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.