Skip to content

Commit

Permalink
Included thread id into conversation and fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Wentzel committed Sep 5, 2024
1 parent fd37b6c commit d5d95ba
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/js/Containers/FrevaGPT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ChatBot = () => {
const [image, setImage] = useState("");
const [conversation, setConversation] = useState([]);
const [answerLoading, setAnswerLoading] = useState(false);
const [thread, setThread] = useState("");


useEffect(() => {
Expand All @@ -28,9 +29,11 @@ const ChatBot = () => {
}, [image])

const fetchData = async () => {
console.log('###', thread);
const response = await fetch('/api/chatbot/streamresponse?' + new URLSearchParams({
input: encodeURIComponent(question),
auth_key: process.env.BOT_AUTH_KEY,
thread_id: thread,
}).toString());

const reader = response.body.getReader();
Expand All @@ -47,6 +50,9 @@ const ChatBot = () => {
botCode = botCode + value.content[0];
} else if (value.variant !== 'ServerHint' && value.variant !== 'StreamEnd'){
botAnswer = botAnswer + value.content;
} else if (value.variant === 'ServerHint') {
// TODO test for warning or of thread_id is even included in an object
if (thread === "") setThread(JSON.parse(value.content).thread_id);
}
});

Expand Down

0 comments on commit d5d95ba

Please sign in to comment.