Do not expose answer API as a chat type in chat web interface or API

Answer does not rely on past conversations, just the knowledge base.
It is meant for one off interactions, like search rather than a
continuing conversation like chat

For now it is only exposed via API. Later it will be expose in the
interfaces as well

Remove ability to select different chat types from the chat web
interface as there is only a single chat type

Stop appending answers to the conversation logs
This commit is contained in:
Debanjum Singh Solanky 2023-03-05 17:34:09 -06:00
parent 7f994274bb
commit b6cdc5c7cb
3 changed files with 5 additions and 33 deletions

View file

@ -9,12 +9,6 @@
<link rel="manifest" href="/static/khoj.webmanifest"> <link rel="manifest" href="/static/khoj.webmanifest">
</head> </head>
<script> <script>
function setTypeFieldInUrl(type) {
let url = new URL(window.location.href);
url.searchParams.set("t", type.value);
window.history.pushState({}, "", url.href);
}
function formatDate(date) { function formatDate(date) {
// Format date in HH:MM, DD MMM YYYY format // Format date in HH:MM, DD MMM YYYY format
let time_string = date.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit', hour12: false }); let time_string = date.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit', hour12: false });
@ -31,15 +25,14 @@
<div class="chat-message-text ${by}">${message}</div> <div class="chat-message-text ${by}">${message}</div>
</div> </div>
`; `;
// Scroll to bottom of input-body element // Scroll to bottom of chat-body element
document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight; document.getElementById("chat-body").scrollTop = document.getElementById("chat-body").scrollHeight;
} }
function chat() { function chat() {
// Extract required fields for search from form // Extract required fields for search from form
query = document.getElementById("chat-input").value.trim(); query = document.getElementById("chat-input").value.trim();
type_ = document.getElementById("chat-type").value; console.log(`Query: ${query}`);
console.log(`Query: ${query}, Type: ${type_}`);
// Short circuit on empty query // Short circuit on empty query
if (query.length === 0) if (query.length === 0)
@ -50,7 +43,7 @@
document.getElementById("chat-input").value = ""; document.getElementById("chat-input").value = "";
// Generate backend API URL to execute query // Generate backend API URL to execute query
url = `/api/beta/${type_}?q=${encodeURIComponent(query)}`; url = `/api/beta/chat?q=${encodeURIComponent(query)}`;
// Call specified Khoj API // Call specified Khoj API
fetch(url) fetch(url)
@ -71,11 +64,6 @@
} }
window.onload = function () { window.onload = function () {
// Fill type field with value passed in URL query parameters, if any.
var type_via_url = new URLSearchParams(window.location.search).get("t");
if (type_via_url)
document.getElementById("chat-type").value = type_via_url;
fetch('/api/beta/chat') fetch('/api/beta/chat')
.then(response => response.json()) .then(response => response.json())
.then(data => data.response) .then(data => data.response)
@ -107,12 +95,6 @@
<!-- Chat Footer --> <!-- Chat Footer -->
<div id="chat-footer"> <div id="chat-footer">
<input type="text" id="chat-input" class="option" onkeyup=incrementalChat(event) autofocus="autofocus" placeholder="What is the meaning of life?"> <input type="text" id="chat-input" class="option" onkeyup=incrementalChat(event) autofocus="autofocus" placeholder="What is the meaning of life?">
<!--Select Chat Type from: Chat, Summarize -->
<select id="chat-type" class="option" onchange="setTypeFieldInUrl(this)">
<option value="answer">Answer</option>
<option value="chat">Chat</option>
</select>
</div> </div>
</body> </body>
@ -215,7 +197,7 @@
#chat-footer { #chat-footer {
padding: 0; padding: 0;
display: grid; display: grid;
grid-template-columns: minmax(70px, 85%) auto; grid-template-columns: minmax(70px, 100%);
grid-column-gap: 10px; grid-column-gap: 10px;
grid-row-gap: 10px; grid-row-gap: 10px;
} }

View file

@ -54,10 +54,6 @@ def answer_beta(q: str):
model = state.processor_config.conversation.model model = state.processor_config.conversation.model
api_key = state.processor_config.conversation.openai_api_key api_key = state.processor_config.conversation.openai_api_key
# Load Conversation History
chat_session = state.processor_config.conversation.chat_session
meta_log = state.processor_config.conversation.meta_log
# Collate context for GPT # Collate context for GPT
result_list = search(q, n=2, r=True) result_list = search(q, n=2, r=True)
collated_result = "\n\n".join([f"# {item.additional['compiled']}" for item in result_list]) collated_result = "\n\n".join([f"# {item.additional['compiled']}" for item in result_list])
@ -71,12 +67,6 @@ def answer_beta(q: str):
gpt_response = str(e) gpt_response = str(e)
status = "error" status = "error"
# Update Conversation History
state.processor_config.conversation.chat_session = message_to_prompt(q, chat_session, gpt_message=gpt_response)
state.processor_config.conversation.meta_log["chat"] = message_to_log(
q, gpt_response, conversation_log=meta_log.get("chat", [])
)
return {"status": status, "response": gpt_response} return {"status": status, "response": gpt_response}

View file

@ -2,7 +2,7 @@
import pytest import pytest
# Internal Packages # Internal Packages
from khoj.processor.conversation.gpt import converse, understand, message_to_prompt from khoj.processor.conversation.gpt import converse, message_to_prompt
# Initialize variables for tests # Initialize variables for tests