mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
fix: load sources on shared conversations
This commit is contained in:
@@ -429,7 +429,7 @@ def api_search():
|
|||||||
data_key = get_data_from_api_key(data["api_key"])
|
data_key = get_data_from_api_key(data["api_key"])
|
||||||
chunks = int(data_key["chunks"])
|
chunks = int(data_key["chunks"])
|
||||||
source = {"active_docs":data_key["source"]}
|
source = {"active_docs":data_key["source"]}
|
||||||
user_api_key = data_key["api_key"]
|
user_api_key = data["api_key"]
|
||||||
elif "active_docs" in data:
|
elif "active_docs" in data:
|
||||||
source = {"active_docs":data["active_docs"]}
|
source = {"active_docs":data["active_docs"]}
|
||||||
user_api_key = None
|
user_api_key = None
|
||||||
|
|||||||
@@ -593,8 +593,6 @@ def get_publicly_shared_conversations(identifier: str):
|
|||||||
404,
|
404,
|
||||||
)
|
)
|
||||||
conversation_queries = conversation["queries"][: (shared["first_n_queries"])]
|
conversation_queries = conversation["queries"][: (shared["first_n_queries"])]
|
||||||
for query in conversation_queries:
|
|
||||||
query.pop("sources") ## avoid exposing sources
|
|
||||||
else:
|
else:
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify(
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ export const SharedConversation = () => {
|
|||||||
key={`${index}ANSWER`}
|
key={`${index}ANSWER`}
|
||||||
message={query.response}
|
message={query.response}
|
||||||
type={'ANSWER'}
|
type={'ANSWER'}
|
||||||
|
sources={query.sources ?? []}
|
||||||
></ConversationBubble>
|
></ConversationBubble>
|
||||||
);
|
);
|
||||||
} else if (query.error) {
|
} else if (query.error) {
|
||||||
|
|||||||
@@ -190,6 +190,27 @@ export function handleSearch(
|
|||||||
.catch((err) => console.log(err));
|
.catch((err) => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function handleSearchViaApiKey(
|
||||||
|
question: string,
|
||||||
|
api_key: string,
|
||||||
|
history: Array<any> = [],
|
||||||
|
) {
|
||||||
|
history = history.map((item) => {
|
||||||
|
return { prompt: item.prompt, response: item.response };
|
||||||
|
});
|
||||||
|
return conversationService
|
||||||
|
.search({
|
||||||
|
question: question,
|
||||||
|
history: JSON.stringify(history),
|
||||||
|
api_key: api_key,
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
}
|
||||||
|
|
||||||
export function handleSendFeedback(
|
export function handleSendFeedback(
|
||||||
prompt: string,
|
prompt: string,
|
||||||
response: string,
|
response: string,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { createAsyncThunk } from '@reduxjs/toolkit';
|
|||||||
import {
|
import {
|
||||||
handleFetchSharedAnswer,
|
handleFetchSharedAnswer,
|
||||||
handleFetchSharedAnswerStreaming,
|
handleFetchSharedAnswerStreaming,
|
||||||
|
handleSearchViaApiKey,
|
||||||
} from './conversationHandlers';
|
} from './conversationHandlers';
|
||||||
|
|
||||||
const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
|
const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
|
||||||
@@ -44,6 +45,22 @@ export const fetchSharedAnswer = createAsyncThunk<Answer, { question: string }>(
|
|||||||
// set status to 'idle'
|
// set status to 'idle'
|
||||||
dispatch(sharedConversationSlice.actions.setStatus('idle'));
|
dispatch(sharedConversationSlice.actions.setStatus('idle'));
|
||||||
dispatch(saveToLocalStorage());
|
dispatch(saveToLocalStorage());
|
||||||
|
|
||||||
|
state.sharedConversation.apiKey &&
|
||||||
|
handleSearchViaApiKey(
|
||||||
|
question,
|
||||||
|
state.sharedConversation.apiKey,
|
||||||
|
state.sharedConversation.queries,
|
||||||
|
).then((sources) => {
|
||||||
|
//dispatch streaming sources
|
||||||
|
sources &&
|
||||||
|
dispatch(
|
||||||
|
updateStreamingSource({
|
||||||
|
index: state.sharedConversation.queries.length - 1,
|
||||||
|
query: { sources: sources ?? [] },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
} else if (data.type === 'error') {
|
} else if (data.type === 'error') {
|
||||||
// set status to 'failed'
|
// set status to 'failed'
|
||||||
dispatch(sharedConversationSlice.actions.setStatus('failed'));
|
dispatch(sharedConversationSlice.actions.setStatus('failed'));
|
||||||
@@ -164,6 +181,17 @@ export const sharedConversationSlice = createSlice({
|
|||||||
...query,
|
...query,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
updateStreamingSource(
|
||||||
|
state,
|
||||||
|
action: PayloadAction<{ index: number; query: Partial<Query> }>,
|
||||||
|
) {
|
||||||
|
const { index, query } = action.payload;
|
||||||
|
if (!state.queries[index].sources) {
|
||||||
|
state.queries[index].sources = query?.sources;
|
||||||
|
} else {
|
||||||
|
state.queries[index].sources!.push(query.sources![0]);
|
||||||
|
}
|
||||||
|
},
|
||||||
raiseError(
|
raiseError(
|
||||||
state,
|
state,
|
||||||
action: PayloadAction<{ index: number; message: string }>,
|
action: PayloadAction<{ index: number; message: string }>,
|
||||||
@@ -213,6 +241,7 @@ export const {
|
|||||||
updateStreamingQuery,
|
updateStreamingQuery,
|
||||||
addQuery,
|
addQuery,
|
||||||
saveToLocalStorage,
|
saveToLocalStorage,
|
||||||
|
updateStreamingSource,
|
||||||
} = sharedConversationSlice.actions;
|
} = sharedConversationSlice.actions;
|
||||||
|
|
||||||
export const selectStatus = (state: RootState) => state.conversation.status;
|
export const selectStatus = (state: RootState) => state.conversation.status;
|
||||||
|
|||||||
Reference in New Issue
Block a user