diff --git a/assets/js/Containers/FrevaGPT/SidePanel.js b/assets/js/Containers/FrevaGPT/SidePanel.js index 1e8f1f9d..451218ef 100644 --- a/assets/js/Containers/FrevaGPT/SidePanel.js +++ b/assets/js/Containers/FrevaGPT/SidePanel.js @@ -52,6 +52,24 @@ function SidePanel() { })} + + +
+ Freva requests +
+
+ {botRequests.freva.map((element, index) => { + return( +
+ changeToThread(element.thread)}> + {element.title} + +
+ + ); + })} +
+
diff --git a/assets/js/Containers/FrevaGPT/actions.js b/assets/js/Containers/FrevaGPT/actions.js index a9a74587..1758bad3 100644 --- a/assets/js/Containers/FrevaGPT/actions.js +++ b/assets/js/Containers/FrevaGPT/actions.js @@ -20,4 +20,4 @@ export const addElement = (element) => (dispatch) => { type: constants.ADD_ELEMENT, payload: element, }) -} \ No newline at end of file +} diff --git a/assets/js/Containers/FrevaGPT/constants.js b/assets/js/Containers/FrevaGPT/constants.js index e9b44927..9965f4c7 100644 --- a/assets/js/Containers/FrevaGPT/constants.js +++ b/assets/js/Containers/FrevaGPT/constants.js @@ -1,4 +1,4 @@ export const ADD_ELEMENT = "ADD_ELEMENT"; export const SET_CONVERSATION = "SET_CONVERSATION"; -export const SET_THREAD = "SET_THREAD"; \ No newline at end of file +export const SET_THREAD = "SET_THREAD"; diff --git a/assets/js/Containers/FrevaGPT/index.js b/assets/js/Containers/FrevaGPT/index.js index be9b88b8..7806724e 100644 --- a/assets/js/Containers/FrevaGPT/index.js +++ b/assets/js/Containers/FrevaGPT/index.js @@ -21,7 +21,7 @@ import Spinner from "../../Components/Spinner"; import CodeBlock from "./CodeBlock"; import SidePanel from "./SidePanel"; -import { replaceLinebreaks } from './utils'; +import { replaceLinebreaks, objectToQueryString } from './utils'; import { setThread, @@ -92,13 +92,16 @@ class FrevaGPT extends React.Component { } async fetchData() { - // response of a new bot request is streamed - const response = await fetch(`/api/chatbot/streamresponse?` + new URLSearchParams({ + + const queryObject = { input: this.state.userInput.content, auth_key: process.env.BOT_AUTH_KEY, thread_id: this.props.frevaGPT.thread, - freva_config: encodeURIComponent("/work/ch1187/clint/freva-dev/freva/evaluation_system.conf"), - }).toString()); // add signal for abortController + freva_config: "/work/ch1187/clint/freva-dev/freva/evaluation_system.conf", + }; + + // response of a new bot request is streamed + const response = await fetch(`/api/chatbot/streamresponse?` + helper.objectToQueryString(queryObject)); //, signal); const reader = response.body.getReader(); const decoder = new TextDecoder('utf-8'); diff --git a/assets/js/Containers/FrevaGPT/utils.js b/assets/js/Containers/FrevaGPT/utils.js index 6124f7b0..c53def84 100644 --- a/assets/js/Containers/FrevaGPT/utils.js +++ b/assets/js/Containers/FrevaGPT/utils.js @@ -21,4 +21,10 @@ export function formatCode(mode, data) { } return codeSnippets; -} \ No newline at end of file +} + +export const objectToQueryString = (obj) => { + return Object.entries(obj) + .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) + .join('&'); + }; \ No newline at end of file