Skip to content

Commit

Permalink
Using query-string instead of custom function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Wentzel committed Dec 16, 2024
1 parent 1ea7b93 commit 0e5c3fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
20 changes: 10 additions & 10 deletions assets/js/Containers/FrevaGPT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import { isEmpty } from "lodash";

import { FaStop, FaPlay } from "react-icons/fa";

import queryString from 'query-string';

import Spinner from "../../Components/Spinner";

import ChatBlock from "./components/ChatBlock";
import SidePanel from "./components/SidePanel";
import PendingAnswerComponent from "./components/PendingAnswerComponent";

import { objectToQueryString, truncate } from "./utils";
import { truncate } from "./utils";

import { setThread, setConversation, addElement } from "./actions";

Expand Down Expand Up @@ -164,7 +166,7 @@ class FrevaGPT extends React.Component {

// response of a new bot request is streamed
const response = await fetch(
`/api/chatbot/streamresponse?` + objectToQueryString(queryObject)
`/api/chatbot/streamresponse?` + queryString.stringify(queryObject)
); //, signal);

const reader = response.body.getReader();
Expand Down Expand Up @@ -272,11 +274,10 @@ class FrevaGPT extends React.Component {
}

async getOldThread(thread) {

const queryObject = { "thread_id": thread };
const response = await fetch(
`/api/chatbot/getthread?` +
new URLSearchParams({
thread_id: thread,
}).toString()
`/api/chatbot/getthread?` + queryString.stringify(queryObject)
);

const variantArray = await response.json();
Expand All @@ -285,12 +286,11 @@ class FrevaGPT extends React.Component {

async handleStop() {
// stop of thread only possible if a thread id is given

const queryObject = { thread_id: this.props.frevaGPT.thread }
if (this.props.frevaGPT.thread) {
await fetch(
`/api/chatbot/stop?` +
new URLSearchParams({
thread_id: this.props.frevaGPT.thread,
}).toString()
`/api/chatbot/stop?` + queryString.stringify(queryObject)
);
}

Expand Down
9 changes: 0 additions & 9 deletions assets/js/Containers/FrevaGPT/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ export function formatCode(mode, data) {
return codeSnippets;
}

export const objectToQueryString = (obj) => {
return Object.entries(obj)
.map(
([key, value]) =>
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
)
.join("&");
};

export const truncate = (value) => {
const trunc = value.substring(0, 32) + "\u2026";
return trunc;
Expand Down

0 comments on commit 0e5c3fd

Please sign in to comment.