class Scroller { constructor(speed=2000) { this.speed = speed; this.canShowGodown = true; } isAtBottom(){ var h = $("#scrollableDiv").prop('scrollHeight'); return $("#scrollableDiv").scrollTop() + $("#scrollableDiv").height() >= h - 20; } down(){ $("#godown").addClass("hidden"); var h = $("#scrollableDiv").prop('scrollHeight'); $("#scrollableDiv").animate({ scrollTop: h }, this.speed); } bottom(){ var h = $("#scrollableDiv").prop('scrollHeight'); $("#scrollableDiv").scrollTop(h); } } var converter = new showdown.Converter(); var scroller = new Scroller(true, 2000); var question = ""; var xhr; function bubbles(endpoint, reset, references, search, history, callback=undefined){ function load_history(q){ ask = true; var obj = jQuery.parseJSON(JSON.stringify(history)); $.each(obj, function(key,value) { if (value.type == "HumanMessage") question_bubble = $('
', {class: 'box bubble-right', html: decodeURIComponent(value.content)}); $("#conversation").append(question_bubble); if (unescapeHtml(value.content) == q){ ask = false; } if (value.type == "AIMessage"){ bubble = $("
", {'class': "box bubble-left"}).appendTo("#conversation"); chat = $("
").appendTo(bubble) refs = $('
').appendTo(bubble) $.each(value.context, function(ref, value) { lnk = $('',{class: "inline-block text-redis-ink-900 bg-redis-yellow-100 border border-redis-pen-300 no-underline hover:underline rounded-md px-1.5 pt-1 pb-1/2 m-1", text: value.title, title: value.title, href: ref, target: "_blank"}).appendTo(refs); }); chat.html(addCodeCopyButton(sanitizeInput(converter.makeHtml(unescapeHtml(value.content))))); } }); // Once the history is loaded, open all links in a new tab and scroll to bottom $('#conversation').find('a').attr('target', '_blank'); hljs.highlightAll(); } const urlParams = new URLSearchParams(window.location.search); q = urlParams.get('q'); page = urlParams.get('page')==null?1:urlParams.get('page'); load_history(q) scroller.bottom(); if (q != null && q.trim().length){ get_search(q, page); if (ask) { get_references(q); get_chat(q); } } var scrollableDiv = $("#scrollableDiv"); scrollableDiv.scroll(function() { if(!scroller.isAtBottom() && scroller.canShowGodown) { $("#godown").removeClass("hidden"); } else { $("#godown").addClass("hidden"); } }); $(window).on('resize', function() { if(!scroller.isAtBottom() && scroller.canShowGodown) { $("#godown").removeClass("hidden"); } else { $("#godown").addClass("hidden"); } }); $("#chat-search-button").click(function(e){ e.preventDefault(); q = $(".footer-search-bar").val(); $(".footer-search-bar").val(''); $("#chat-search-button").prop("disabled", true); get_chat(q); get_references(q); get_search(q, 1); replaceQueryParam('q', q); }); $("#reset").click(function(e){ e.preventDefault(); $.ajax({ type: "POST", dataType: "json", url: reset, processData: true, success: function(data) { $(".box").fadeOut("slow", function() { $("#container").empty(); }); } }); }); $("#stop-button").click(function(e){ e.preventDefault(); if (xhr) { xhr.abort(); } $("#chat-search-button").removeClass('hidden'); $("#stop-button").addClass('hidden'); $(".dot-flashing").hide(); }) $("input[type='checkbox']").change(function() { get_search(question); }); function addCodeCopyButton(html){ var newHtml = $(html); var htmlWrapped = $('
').append(newHtml); htmlWrapped.find("pre code").each(function(){ var code = $(this).text(); var buttonWrapper = $('
', {class: 'absolute top-0 right-0 group'}); var button = $('