setOpen(false)}>
-
+
@@ -444,7 +470,7 @@ export const DocsGPTWidget = ({
}
)
})
- :
+ :
}
@@ -460,6 +486,6 @@ export const DocsGPTWidget = ({
}
- >
+
)
}
\ No newline at end of file
diff --git a/extensions/react-widget/src/requests/streamingApi.ts b/extensions/react-widget/src/requests/streamingApi.ts
index a0a671de..cea339b9 100644
--- a/extensions/react-widget/src/requests/streamingApi.ts
+++ b/extensions/react-widget/src/requests/streamingApi.ts
@@ -1,92 +1,83 @@
interface HistoryItem {
- prompt: string;
- response?: string;
- }
+ prompt: string;
+ response?: string;
+}
interface FetchAnswerStreamingProps {
- question?: string;
- apiKey?: string;
- selectedDocs?: string;
- history?: HistoryItem[];
- conversationId?: string | null;
- apiHost?: string;
- onEvent?: (event: MessageEvent) => void;
- }
+ question?: string;
+ apiKey?: string;
+ selectedDocs?: string;
+ history?: HistoryItem[];
+ conversationId?: string | null;
+ apiHost?: string;
+ onEvent?: (event: MessageEvent) => void;
+}
export function fetchAnswerStreaming({
- question = '',
- apiKey = '',
- selectedDocs = '',
- history = [],
- conversationId = null,
- apiHost = '',
- onEvent = () => {console.log("Event triggered, but no handler provided.");}
- }: FetchAnswerStreamingProps): Promise {
- let docPath = 'default';
- if (selectedDocs) {
- docPath = selectedDocs;
- }
-
- return new Promise((resolve, reject) => {
- const body = {
- question: question,
- api_key: apiKey,
- embeddings_key: apiKey,
- active_docs: docPath,
- history: JSON.stringify(history),
- conversation_id: conversationId,
- model: 'default'
- };
-
- fetch(apiHost + '/stream', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(body),
- })
- .then((response) => {
- if (!response.body) throw Error('No response body');
-
- const reader = response.body.getReader();
- const decoder = new TextDecoder('utf-8');
- let counterrr = 0;
- const processStream = ({
- done,
- value,
- }: ReadableStreamReadResult) => {
- if (done) {
- resolve();
- return;
+ question = '',
+ apiKey = '',
+ history = [],
+ conversationId = null,
+ apiHost = '',
+ onEvent = () => { console.log("Event triggered, but no handler provided."); }
+}: FetchAnswerStreamingProps): Promise {
+ return new Promise((resolve, reject) => {
+ const body= {
+ question: question,
+ history: JSON.stringify(history),
+ conversation_id: conversationId,
+ model: 'default',
+ apiKey:apiKey
+ };
+ fetch(apiHost + '/stream', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(body),
+ })
+ .then((response) => {
+ if (!response.body) throw Error('No response body');
+
+ const reader = response.body.getReader();
+ const decoder = new TextDecoder('utf-8');
+ let counterrr = 0;
+ const processStream = ({
+ done,
+ value,
+ }: ReadableStreamReadResult) => {
+ if (done) {
+ resolve();
+ return;
+ }
+
+ counterrr += 1;
+
+ const chunk = decoder.decode(value);
+
+ const lines = chunk.split('\n');
+
+ for (let line of lines) {
+ if (line.trim() == '') {
+ continue;
}
-
- counterrr += 1;
-
- const chunk = decoder.decode(value);
-
- const lines = chunk.split('\n');
-
- for (let line of lines) {
- if (line.trim() == '') {
- continue;
- }
- if (line.startsWith('data:')) {
- line = line.substring(5);
- }
-
- const messageEvent = new MessageEvent('message', {
- data: line,
- });
-
- onEvent(messageEvent); // handle each message
+ if (line.startsWith('data:')) {
+ line = line.substring(5);
}
-
- reader.read().then(processStream).catch(reject);
- };
-
+
+ const messageEvent = new MessageEvent('message', {
+ data: line,
+ });
+
+ onEvent(messageEvent); // handle each message
+ }
+
reader.read().then(processStream).catch(reject);
- })
- .catch((error) => {
- console.error('Connection failed:', error);
- reject(error);
- });
- });
- }
\ No newline at end of file
+ };
+
+ reader.read().then(processStream).catch(reject);
+ })
+ .catch((error) => {
+ console.error('Connection failed:', error);
+ reject(error);
+ });
+ });
+}
\ No newline at end of file
diff --git a/extensions/react-widget/src/types/index.ts b/extensions/react-widget/src/types/index.ts
index 6810dd90..9c49063f 100644
--- a/extensions/react-widget/src/types/index.ts
+++ b/extensions/react-widget/src/types/index.ts
@@ -1,11 +1,7 @@
export type MESSAGE_TYPE = 'QUESTION' | 'ANSWER' | 'ERROR';
export type Status = 'idle' | 'loading' | 'failed';
export type FEEDBACK = 'LIKE' | 'DISLIKE';
-export type DIMENSION = {
- width: string,
- height: string
-}
-
+export type THEME = 'light' | 'dark';
export interface Query {
prompt: string;
response?: string;
@@ -17,7 +13,6 @@ export interface Query {
}
export interface WidgetProps {
apiHost?: string;
- selectDocs?: string;
apiKey?: string;
avatar?: string;
title?: string;
@@ -25,4 +20,7 @@ export interface WidgetProps {
heroTitle?: string;
heroDescription?: string;
size?: 'small' | 'medium';
+ theme?:THEME,
+ buttonIcon?:string;
+ buttonBg?:string;
}
\ No newline at end of file