Files
talemate/talemate_frontend/src/components/LoadScene.vue
FInalWombat 72202dee02 Prep 0.12.0 (#26)
* no " or * just treat as spoken words

* chromadb perist to db

* collect name should contain embedding so switching between chromadb configurations doesn't brick your scenes

* fix save-as long term memory transfer

* add chroma

* director agent refactor

* tweak director command, prompt reset, ux display

* tweak director message ux

* allow clearing of prompt log

* remove auto adding of quotes if neither quote or * are present

* command to reset long term memory for the scene

* improve summarization template as it would cause some llms to add extra details

* rebuilding history will now also rebuild long term memory

* direct scene template

* fix scene time reset

* dialogue template tweaks

* better dialog format fixing

* some dialogue template adjustments

* adjust default values of director agent

* keep track of scene saved/unsaved status and confirm loading a different scene if current scene is unsaved

* prompt fixes

* remove the collection on recommitting the seen to memory, as the embeddings may have changed

* change to the official python api for the openai client and make it async

* prompt tweaks

* world state prompt parsing fixes

* improve handling of json responses

* 0 seconds ago changed to moments ago

* move memory context closer to scene

* token counts for openai client

* narrator agent option: narrate passage of time

* gitignore

* remove memory id

* refactor world state with persistence to chromadb (wip)

* remove world state update instructions

* dont display blank emotion in world state

* openai gpt-4 turbo support

* conversation agent extra instructions

* track prompt response times

* Yi and UtopiaXL

* long term memory retrieval improvements during conversations

* narrate scene tweaks

* conversation ltm augment tweaks

* hide subconfig if parent config isnt enabled

* ai assisted memory recall during conversation default to off

* openai json_object coersion only on model that supports it

openai client emit prompt processing time

* 0.12.0

* remove prompt number from prompt debug list

* add prompt number back in but shift it to the upper row

* narrate time passage hard content limit restriction for now as gpt-4
would just write a whole chapter.

* relock
2023-11-10 22:45:50 +02:00

149 lines
6.2 KiB
Vue

<template>
<v-list-subheader @click="toggle()" class="text-uppercase"><v-icon>mdi-script-text-outline</v-icon> Load
<v-progress-circular v-if="loading" indeterminate color="primary" size="20"></v-progress-circular>
<v-icon v-if="expanded" icon="mdi-chevron-down"></v-icon>
<v-icon v-else icon="mdi-chevron-up"></v-icon>
</v-list-subheader>
<v-list-item-group v-if="!loading && isConnected() && expanded && !configurationRequired()">
<v-list-item>
<v-list-item-content class="mb-3">
<!-- Toggle buttons for switching between file upload and path input -->
<v-btn-toggle density="compact" class="mb-3" v-model="inputMethod" mandatory>
<v-btn value="file">
<v-icon>mdi-file-upload</v-icon>
</v-btn>
<v-btn value="path">
<v-icon>mdi-file-document-outline</v-icon>
</v-btn>
<v-btn value="creative">
<v-icon>mdi-palette-outline</v-icon>
</v-btn>
</v-btn-toggle>
<!-- File input for file upload -->
<div v-if="inputMethod === 'file' && !loading">
<v-file-input prepend-icon="" style="height:200px" density="compact" v-model="sceneFile" @change="loadScene" label="Upload a character card"
outlined accept="image/*" variant="solo-filled"></v-file-input>
</div>
<!-- Text field for path input -->
<v-autocomplete v-else-if="inputMethod === 'path' && !loading" v-model="sceneInput" :items="scenes"
label="Search scenes" outlined @update:search="updateSearchInput" item-title="label" item-value="path" :loading="sceneSearchLoading">
</v-autocomplete>
<!-- Upload/Load button -->
<v-btn v-if="!loading && inputMethod === 'path'" @click="loadScene" color="primary" block class="mb-3">
<v-icon left>mdi-folder</v-icon>
Load
</v-btn>
<v-btn v-else-if="!loading && inputMethod === 'creative'" @click="loadCreative" color="primary" block class="mb-3">
<v-icon left>mdi-palette-outline</v-icon>
Creative Mode
</v-btn>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
<div v-else-if="configurationRequired()">
<v-alert type="warning" variant="tonal">You need to configure a Talemate client before you can load scenes.</v-alert>
</div>
</template>
<script>
export default {
name: 'LoadScene',
data() {
return {
loading: false,
inputMethod: 'path',
sceneFile: [],
sceneInput: '',
scenes: [],
sceneSearchInput: null,
sceneSearchLoading: false,
sceneSaved: null,
expanded: true,
}
},
inject: ['getWebsocket', 'registerMessageHandler', 'isConnected', 'configurationRequired'],
methods: {
toggle() {
this.expanded = !this.expanded;
},
updateSearchInput(val) {
this.sceneSearchInput = val;
clearTimeout(this.searchTimeout); // Clear the previous timeout
this.searchTimeout = setTimeout(this.fetchScenes, 300); // Start a new timeout
},
fetchScenes() {
if (!this.sceneSearchInput)
return
this.sceneSearchLoading = true;
console.log("Fetching scenes", this.sceneSearchInput)
this.getWebsocket().send(JSON.stringify({ type: 'request_scenes_list', query: this.sceneSearchInput }));
},
loadCreative() {
this.loading = true;
this.getWebsocket().send(JSON.stringify({ type: 'load_scene', file_path: "environment:creative" }));
},
loadScene() {
if(this.sceneSaved === false) {
if(!confirm("The current scene is not saved. Are you sure you want to load a new scene?")) {
return;
}
}
this.loading = true;
if (this.inputMethod === 'file' && this.sceneFile.length > 0) { // Check if the input method is "file" and there is at least one file
// Convert the uploaded file to base64
const reader = new FileReader();
reader.readAsDataURL(this.sceneFile[0]); // Access the first file in the array
reader.onload = () => {
//const base64File = reader.result.split(',')[1];
this.getWebsocket().send(JSON.stringify({
type: 'load_scene',
scene_data: reader.result,
filename: this.sceneFile[0].name,
}));
this.sceneFile = [];
};
} else if (this.inputMethod === 'path' && this.sceneInput) { // Check if the input method is "path" and the scene input is not empty
this.getWebsocket().send(JSON.stringify({ type: 'load_scene', file_path: this.sceneInput }));
this.sceneInput = '';
}
},
handleMessage(data) {
// Scene loaded
if (data.type === "system") {
if (data.id === 'scene.loaded') {
this.loading = false;
this.expanded = false;
}
}
// Handle scenes_list message type
if (data.type === 'scenes_list') {
this.scenes = data.data;
this.sceneSearchLoading = false;
return;
}
// Handle scene status
if (data.type == "scene_status") {
this.sceneSaved = data.data.saved;
return;
}
}
},
created() {
this.registerMessageHandler(this.handleMessage);
},
mounted() {
console.log("Websocket", this.getWebsocket()); // Check if websocket is available
}
}
</script>
<style scoped>
/* styles for LoadScene component */
</style>