similaritysearch UI modified

This commit is contained in:
sumedh
2024-08-06 20:05:01 +05:30
parent 4f264dec42
commit 9b9aef9257
3 changed files with 169 additions and 50 deletions

10
package-lock.json generated
View File

@@ -14,6 +14,7 @@
"moment": "^2.30.1", "moment": "^2.30.1",
"primeicons": "^6.0.1", "primeicons": "^6.0.1",
"primevue": "^4.0.0", "primevue": "^4.0.0",
"prismjs": "^1.29.0",
"vue": "^3.4.34", "vue": "^3.4.34",
"vue-router": "^4.4.0" "vue-router": "^4.4.0"
}, },
@@ -3007,6 +3008,15 @@
"node": ">=12.11.0" "node": ">=12.11.0"
} }
}, },
"node_modules/prismjs": {
"version": "1.29.0",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.29.0.tgz",
"integrity": "sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/proxy-from-env": { "node_modules/proxy-from-env": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",

View File

@@ -0,0 +1,82 @@
<template>
<div class="code-snippet-container">
<div class="button-container h-8 w-8 p-0 inline-flex items-center justify-center">
<!-- Button to copy code to clipboard -->
<Button icon="pi pi-copy" @click="copyToClipboard" class="p-mt-2" />
</div>
<!-- Code display area with syntax highlighting -->
<pre v-html="highlightedCode"></pre>
</div>
</template>
<script setup>
import { computed } from 'vue';
import Button from 'primevue/button';
import Toast from 'primevue/toast';
import { useToast } from 'primevue/usetoast';
import Prism from 'prismjs';
import 'prismjs/components/prism-javascript'; // Import necessary languages
import 'prismjs/components/prism-systemd'; // Import necessary languages
import 'prismjs/themes/prism-tomorrow.css'; // Import a theme for syntax highlighting
const toast = useToast();
// Define the code snippet as a prop
const props = defineProps({
code: {
type: String,
required: true
},
language: {
type: String,
default: 'systemd'
}
});
const highlightedCode = computed(() => {
return Prism.highlight(props.code, Prism.languages[props.language], props.language);
});
// Function to copy the code to the clipboard
function copyToClipboard() {
navigator.clipboard.writeText(props.code).then(() => {
toast.add({ severity: 'success', summary: 'Success', detail: 'Code copied to clipboard!', life: 10000 });
}).catch((error) => {
console.error('Failed to copy code:', error);
toast.add({ severity: 'error', summary: 'Error', detail: 'Failed to copy code.', life: 10000 });
});
}
</script>
<style scoped>
.code-snippet-container {
position: relative; /* Enable positioning of child elements */
}
.class="button-container" {
position: sticky;
top: 10px; /* Adjust as needed */
right: 10px; /* Adjust as needed */
z-index: 1000;
}
pre {
background-color: #2d2d2d;
color: #ccc;
padding: 1em;
border-radius: 5px;
overflow-x: auto;
white-space: pre-wrap;
}
.button-container {
position: absolute;
top: 10px; /* Adjust as needed */
right: 10px; /* Adjust as needed */
}
.p-mt-2 {
margin-top: 1em;
}
</style>

View File

@@ -1,34 +1,28 @@
<template> <template>
<Fluid> <Fluid>
<div class="flex mt-6"> <div class="similarity-search">
<div class="card flex flex-col gap-4 w-full"> <div class="card-container flex flex-col gap-6">
<div> <h2 class="text-4xl font-semibold text-center mb-4">Similarity Search</h2>
<h2 class="text-3xl font-bold mb-4">Similarity Search</h2> <div class="flex flex-col gap-4">
</div> <Textarea id="query" v-model="query" rows="6" placeholder="Enter your query..." class="input-textarea" />
<div class="flex flex-wrap"> <div class="select-container">
<!--label for="address">Address</label--> <SelectButton
<Textarea id="query" v-model="query" rows="4" placeholder="Enter your query..." class="w-full" /> id="type"
</div> v-model="dropdownItem"
:options="dropdownItems"
<div class="flex flex-col md:flex-row gap-4"> optionLabel="name"
<div class="flex flex-wrap gap-2 w-full"> class="select-button"
<Select id="type" v-model="dropdownItem" :options="dropdownItems" optionLabel="name" />
placeholder="Select type" class="w-full"></Select>
</div> </div>
</div> </div>
<Button label="Send" icon="pi pi-send" @click="sendQuery" class="send-button" />
<div class="p-field p-col-12 p-md-2">
<Button label="Send" icon="pi pi-send" :fluid="false" @click="sendQuery" />
</div>
</div> </div>
</div>
<div class="flex mt-6"> <div class="results-container mt-6">
<div class="results-container p-mt-4"> <Card v-for="(result, index) in messages" :key="index" class="result-card">
<Card v-for="(result, index) in messages" :key="index" class="p-mb-3">
<template #content> <template #content>
<ScrollPanel style="width: 100%; max-height: 200px"> <ScrollPanel style="width: 100%; max-height: 400px">
<pre class="result-content">{{ result }}</pre> <CodeSnippet :code="dynamicCode" language="systemd" />
</ScrollPanel> </ScrollPanel>
</template> </template>
</Card> </Card>
@@ -41,20 +35,22 @@
import Button from 'primevue/button'; import Button from 'primevue/button';
import Card from 'primevue/card'; import Card from 'primevue/card';
import ScrollPanel from 'primevue/scrollpanel'; import ScrollPanel from 'primevue/scrollpanel';
import SelectButton from 'primevue/selectbutton'; // Import SelectButton
import { useToast } from 'primevue/usetoast'; import { useToast } from 'primevue/usetoast';
import { ref } from 'vue'; import { watch, ref } from 'vue';
import CodeSnippet from './CodeSnippet.vue';
const query = ref(''); const query = ref('');
const dropdownItem = ref(null); const dropdownItem = ref(null);
const messages = ref([]); const messages = ref([]);
const toast = useToast(); const toast = useToast();
const dynamicCode = ref('');
const dropdownItems = [ const dropdownItems = [
{ name: 'Documentation', code: 'setup-documentation' }, { name: 'Documentation', code: 'setup-documentation' },
{ name: 'Deploy Documentation', code: 'deploy-documentation' } { name: 'Deploy Documentation', code: 'deploy-documentation' }
]; ];
const sendQuery = async () => { const sendQuery = async () => {
if (query.value.trim() !== '' && dropdownItem.value) { if (query.value.trim() !== '' && dropdownItem.value) {
try { try {
@@ -78,42 +74,73 @@ const sendQuery = async () => {
toast.add({ severity: 'warn', summary: 'Warning', detail: 'Please enter a query and select a type', life: 3000 }); toast.add({ severity: 'warn', summary: 'Warning', detail: 'Please enter a query and select a type', life: 3000 });
} }
}; };
// Function to generate dynamic code snippet
function generateDynamicCode() {
const randomValue = messages.value.join(', ');
return `[${randomValue}]`;
}
watch(messages, (newMessages) => {
dynamicCode.value = generateDynamicCode();
});
</script> </script>
<style scoped> <style scoped>
.similarity-search { .similarity-search {
max-width: 1200px; max-width: 1000px;
margin: 0 auto; margin: 0 auto;
padding: 2rem;
}
.card-container {
padding: 2rem;
border-radius: 8px;
background-color: #ffffff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.input-textarea {
width: 100%;
resize: vertical;
min-height: 150px; /* Increased height for better readability */
border-radius: 8px;
padding: 1rem; padding: 1rem;
border: 1px solid #ccc;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}
.select-container {
display: flex;
justify-content: center;
}
.select-button {
width: 100%;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.send-button {
width: 100%;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
} }
.results-container { .results-container {
max-height: 600px; padding: 2rem;
overflow-y: auto; background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
} }
.result-content { .result-card {
white-space: pre-wrap; margin-bottom: 1rem;
word-wrap: break-word; border-radius: 8px;
font-family: monospace;
font-size: 0.9em;
padding: 1rem;
background-color: #f8f9fa;
border-radius: 4px;
} }
.p-select { .p-scrollpanel {
width: 100%; border-radius: 8px;
} background-color: #ffffff;
.p-select .p-select-label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.p-inputtextarea {
resize: vertical;
min-height: 100px;
} }
</style> </style>