Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,6 @@ const createChatElement = (content, className) => {
return chatDiv;
}

const extractMessageText = (message) => {
if (message.content) {
if (typeof message.content === 'string') {
// openai style
return message.content
}
else if (Array.isArray(message.content) && message.content.length > 0) {
// AWS bedrock style
return message.content[message.content.length-1].text
}
}

return "no answer, please try another question"
}

const getChatResponse = async (incomingChatDiv) => {
const pElement = document.createElement("div");
Expand Down Expand Up @@ -189,7 +175,7 @@ const getChatResponse = async (incomingChatDiv) => {
})
} else {
if (config.DEBUG) {
console.log('messages prepared for the request:', messagesBotBuffer.getBuffer())
console.log('messages prepared for the request:', messagesBotBuffer.fullReply)
}
if (langMessage) {
recognition.lang = findClosestMatch(userText)
Expand All @@ -216,7 +202,7 @@ const getChatResponse = async (incomingChatDiv) => {
runBot(
{
question: userText,
messages: messagesBotBuffer.getBuffer() || [],
messages: messagesBotBuffer.fullReply || [],
openAIModel: config.openAIModel || 'gpt-3.5-turbo-1106'
}
)
Expand All @@ -228,7 +214,7 @@ const getChatResponse = async (incomingChatDiv) => {
messagesBotBuffer.push(response.rawData.messages[response.rawData.messages.length - 1])
messagesBotBuffer.fullReply = response.rawData.messages
}
messagesBotBuffer.lastReplyMessage = extractMessageText(messagesBotBuffer.getLatestValue())
messagesBotBuffer.lastReplyMessage = response.rawData.response.content || "Something went wrong, missing response! Please retry!"
if (config.DEBUG) {
console.log('message: last reply', messagesBotBuffer.lastReplyMessage)
}
Expand Down