-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86a6273
commit 2999c29
Showing
3 changed files
with
84 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,169 +1,91 @@ | ||
<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
<!-- Generated by AI --> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>RAG Demo</title> | ||
<link rel="stylesheet" href="https://unpkg.com/sanitize.css"> | ||
<style> | ||
body { | ||
font-family: 'Arial', sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f7f7f7; | ||
} | ||
|
||
.container { | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
background: white; | ||
padding: 20px; | ||
border-radius: 8px; | ||
width: 400px; | ||
} | ||
|
||
input, | ||
button { | ||
width: 100%; | ||
padding: 10px; | ||
margin-top: 10px; | ||
border-radius: 5px; | ||
border: 1px solid #ddd; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
padding: 10px; | ||
margin-top: 10px; | ||
border-radius: 5px; | ||
border: 1px solid #ddd; | ||
background-color: #0056b3; | ||
color: white; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #004494; | ||
} | ||
|
||
button:disabled { | ||
background-color: #ccc; | ||
color: #666; | ||
cursor: not-allowed; | ||
} | ||
|
||
|
||
#responses { | ||
margin-top: 20px; | ||
background: #f0f0f0; | ||
padding: 10px; | ||
height: 150px; | ||
overflow-y: auto; | ||
font-size: 0.9em; | ||
border-radius: 5px; | ||
} | ||
|
||
.loading-overlay { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: rgba(255, 255, 255, 0.8); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.loading-spinner { | ||
border: 4px solid rgba(0, 0, 0, 0.1); | ||
width: 36px; | ||
height: 36px; | ||
border-radius: 50%; | ||
border-left-color: #09f; | ||
animation: spin 1s linear infinite; | ||
} | ||
|
||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
|
||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
</style> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>LlamaIndex & TiDB RAG Demo</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script> | ||
<script src="https://unpkg.com/[email protected]"></script> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"> | ||
</head> | ||
|
||
<body> | ||
<div id="app" class="container"> | ||
<input type="text" v-model="question" placeholder="Input question..."> | ||
<button :disabled="loading" @click="askQuestion">Ask</button> | ||
<div id="responses" style="position: relative;"> | ||
<div v-if="loading && responses == ''" class="loading-overlay"> | ||
<div class="loading-spinner"></div> | ||
</div> | ||
<div v-html="responses"></div> | ||
</div> | ||
<div class="flex justify-center py-40"> | ||
<div id="app" class="w-1/2"> | ||
<label class="block"> | ||
<input type="text" v-model="question" placeholder="Input question..." | ||
class="block p-2 w-full border-solid border-gray-300 focus:border-gray-900 border rounded-none focus:outline-none"> | ||
</label> | ||
<button type="button" class="bg-black block w-full my-2 p-2 rounded text-white" :disabled="loading" | ||
@click="askQuestion"> | ||
<i v-if="loading && responses == ''" class="fas fa-spinner animate-spin"></i> | ||
Ask | ||
</button> | ||
<div id="responses" class="w-full min-h-full border py-2 px-6"> | ||
<div v-html="compiledMarkdown">Empty</div> | ||
</div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script> | ||
<script> | ||
new Vue({ | ||
el: '#app', | ||
data: { | ||
question: 'What did the author do growing up?', | ||
responses: '', | ||
loading: false | ||
}, | ||
methods: { | ||
askQuestion: function () { | ||
const self = this; | ||
if (this.question.trim() === '') { | ||
alert('Please input a question.'); | ||
</div> | ||
<script> | ||
new Vue({ | ||
el: '#app', | ||
data: { | ||
question: 'What did the author do at each stage of his/her growth? Use markdown format if possible', | ||
responses: 'Empty...', | ||
loading: false | ||
}, | ||
computed: { | ||
compiledMarkdown: function () { | ||
return marked(this.responses, { sanitize: true }); | ||
} | ||
}, | ||
methods: { | ||
askQuestion: function () { | ||
const self = this; | ||
if (this.question.trim() === '') { | ||
alert('Please input a question.'); | ||
return; | ||
} | ||
self.responses = ''; | ||
self.loading = true; | ||
fetch(`/ask?q=${encodeURIComponent(this.question)}`) | ||
.then(response => { | ||
const reader = response.body.getReader(); | ||
const stream = new ReadableStream({ | ||
start(controller) { | ||
function push() { | ||
reader.read().then(({ done, value }) => { | ||
if (done) { | ||
controller.close(); | ||
self.loading = false; | ||
return; | ||
} | ||
self.responses = ''; | ||
self.loading = true; | ||
fetch(`/ask?q=${encodeURIComponent(this.question)}`) | ||
.then(response => { | ||
const reader = response.body.getReader(); | ||
const stream = new ReadableStream({ | ||
start(controller) { | ||
function push() { | ||
reader.read().then(({ done, value }) => { | ||
if (done) { | ||
controller.close(); | ||
self.loading = false; | ||
return; | ||
} | ||
const chunk = new TextDecoder("utf-8").decode(value); | ||
self.responses += chunk; | ||
controller.enqueue(value); | ||
push(); | ||
}).catch(error => { | ||
self.loading = false; | ||
console.error('Fetch error:', error); | ||
controller.error(error); | ||
}); | ||
} | ||
push(); | ||
} | ||
}); | ||
return new Response(stream); | ||
}) | ||
.catch(error => { | ||
console.error('Fetch error:', error); | ||
self.loading = false; | ||
alert('An error occurred while fetching the response.'); | ||
}); | ||
} | ||
const chunk = new TextDecoder("utf-8").decode(value); | ||
self.responses += chunk; | ||
controller.enqueue(value); | ||
push(); | ||
}).catch(error => { | ||
self.loading = false; | ||
console.error('Fetch error:', error); | ||
controller.error(error); | ||
}); | ||
} | ||
push(); | ||
} | ||
} | ||
}); | ||
</script> | ||
}); | ||
return new Response(stream); | ||
}) | ||
.catch(error => { | ||
console.error('Fetch error:', error); | ||
self.loading = false; | ||
alert('An error occurred while fetching the response.'); | ||
}); | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |