Skip to content

Commit

Permalink
Resolve conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
qcgm1978 committed Aug 13, 2023
1 parent b584ade commit f8e291b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
16 changes: 4 additions & 12 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,32 +317,24 @@ ipcMain.handle("restart-app", async () => {
return "";
});
// Proxy Setting End
ipcMain.handle("upload", async (event, { MongoDB_URL, data }) => {
// eslint-disable-next-line no-debugger
// debugger;
const client = new MongoClient(MongoDB_URL);
ipcMain.handle("upload", async (event, { mongoDbUrl, data }) => {
const client = new MongoClient(mongoDbUrl);
return client
.connect()
.then(() => {
// eslint-disable-next-line no-debugger
// debugger;
const collection = client.db("test").collection("dialogs");
// const chunks = chunkify(data); // 将大对象拆分成块
return collection.insertOne(data);
})
.then(() => {
// eslint-disable-next-line no-debugger
// debugger;
return true;
})
.catch(() => {
return false;
});
});
ipcMain.handle("download", async (event, MongoDB_URL) => {
// eslint-disable-next-line no-debugger
// debugger;
const client = new MongoClient(MongoDB_URL);
ipcMain.handle("download", async (event, mongoDbUrl) => {
const client = new MongoClient(mongoDbUrl);

client.connect();

Expand Down
59 changes: 51 additions & 8 deletions src/components/ChatSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<v-list-item>
<v-list-item-title>{{ $t("chat.MongoDBAtlas") }}</v-list-item-title>
<v-text-field
v-model="MongoDB_URL"
v-model="mongoDbUrl"
:hint="
$t('settings.forExample', {
example:
Expand Down Expand Up @@ -71,13 +71,13 @@ import i18n from "@/i18n";
const electron = window.require("electron");
const ipcRenderer = electron.ipcRenderer;
import ConfirmModal from "@/components/ConfirmModal.vue";
import { get_messages } from "@/utils";
import bots from "@/bots";
const emit = defineEmits(["close-dialog"]);
const confirmModal = ref();
const store = useStore();
const jsonData = ref(null);
const MongoDB_URL = ref(store.state.MongoDB_URL);
const mongoDbUrl = ref(store.state.mongoDbUrl);
const snackbar = reactive({
show: false,
text: "",
Expand All @@ -97,7 +97,7 @@ async function upload() {
// don't know why there's _id prop in localStorage that would lead to duplicate key error
delete data._id;
const is_success = await ipcRenderer.invoke("upload", {
MongoDB_URL: MongoDB_URL.value,
mongoDbUrl: mongoDbUrl.value,
data,
});
if (is_success) {
Expand All @@ -116,10 +116,7 @@ async function download() {
if (result) {
// eslint-disable-next-line
const value = await ipcRenderer.invoke("download", MongoDB_URL.value);
// jsonData.value = value;
// eslint-disable-next-line no-debugger
// debugger;
reload(value[0]);
reload(value.at(-1));
}
}
const readJson = async (event) => {
Expand Down Expand Up @@ -161,6 +158,52 @@ const downloadJson = () => {
const content = "history";
download_by_link(messages, content);
};
function get_messages() {
// Get the chat history from localStorage.
const chatallMessages = localStorage.getItem("chatall-messages");
if (!chatallMessages) {
return;
}
const chats = JSON.parse(chatallMessages)?.chats ?? [];
try {
// Create an array of messages from the chat history.
const messages = chats
.filter((d) => !d.hide)
.map((chat) => ({
// The title of the chat.
title: chat.title,
// The messages in the chat.
messages: chat.messages
.filter((d) => !d.hide)
.reduce((arr, message) => {
const t = message.type;
const content = message.content;
if (t == "prompt") {
arr.push({
prompt: content,
responses: [],
});
} else {
const botClassname = message.className;
const bot = bots.getBotByClassName(botClassname);
const botName = bot.getFullname();
arr.at(-1).responses.push({
content,
botName,
botClassname,
botModel: message.model,
highlight: message.highlight,
});
}
return arr;
}, []),
}));
return messages;
} catch (e) {
// debugger;
}
}
const downloadDataJson = () => {
const content = "data";
const messages = localStorage;
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default createStore({
azureOpenAIApiDeploymentName: "",
azureOpenAIApiVersion: "",
},
MongoDB_URL: "",
mongoDbUrl: "",
chatgpt: {
refreshCycle: 0,
riskConfirmed: false,
Expand Down Expand Up @@ -326,7 +326,7 @@ export default createStore({
state.currentChatIndex = 0;
},
setMongoDBURL(state, url) {
state.MongoDB_URL = url;
state.mongoDbUrl = url;
},
addPrompt(state, values) {
const addPrompt = { ...values };
Expand Down

0 comments on commit f8e291b

Please sign in to comment.