Skip to content

Commit 624cba8

Browse files
committed
chat editing
1 parent 038a1ba commit 624cba8

File tree

6 files changed

+211
-11
lines changed

6 files changed

+211
-11
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ Example: https://eliaspereirah.github.io/OrionChat/?model=moonshotai/kimi-k2-ins
159159
This way, you can save the URL in your bookmarks, making it easier to switch between models for different types of tasks.
160160

161161

162+
### Few-Shot prompting
163+
164+
You can now edit or remove parts of a conversation.
165+
166+
This is also very useful for applying the Few-Shot prompting technique, guiding how the AI should respond if the
167+
system prompt is not sufficient.
168+
First, interact with the AI, and the edit option will appear right below the response.
169+
170+
From then on, you can edit the conversation and add new examples as you wish.
162171

163172
### Old chats
164173
Orion will automatically delete older chats when the number of chats exceeds 512, so the maximum chat history will be 512.

css/chat.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ code.hljs::-webkit-scrollbar-track {
551551
margin-top: -33px;
552552
}
553553

554-
.copy-btn, .down-btn, .see_info, .preview-btn {
554+
.copy-btn, .down-btn, .see_info, .preview-btn, .btn-edit{
555555
padding: 3px 5px;
556556
color: var(--copy-btn-color);
557557
background-color: transparent;
@@ -562,10 +562,15 @@ code.hljs::-webkit-scrollbar-track {
562562
}
563563

564564

565-
.btn-group .copy-btn, .btn-group .down-btn,.preview-btn {
565+
.btn-group .copy-btn, .btn-group .down-btn, .preview-btn, .btn-edit {
566566
background-color: var(--copy-btn-bg);
567567
}
568-
.preview-btn{
568+
569+
.see_info{
570+
display: none !important;
571+
}
572+
573+
.preview-btn, .btn-new{
569574
border: 1px solid #FFEB3B;
570575
}
571576

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!doctype html>
2+
<html lang="en" data-theme="dark">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<meta name="description" content="Chat editing">
8+
<title>Chat editing - OrionChat</title>
9+
<link rel="icon" href="../../favicon.png">
10+
<link rel="stylesheet" href="../../css/chat.css?v=3.2.2">
11+
<link rel="stylesheet" href="../../css/labs.css?v=1.0.1">
12+
<meta property="og:type" content="article">
13+
<meta property="og:title" content="Chat editing - OrionChat">
14+
<meta property="og:description" content="Chat editing - OrionChat">
15+
<meta property="og:image" content="https://eliaspereirah.github.io/OrionChat/imgs/screenshot.png">
16+
<meta property="og:locale" content="en-US">
17+
<meta property="og:url" content="https://eliaspereirah.github.io/OrionChat/">
18+
</head>
19+
<body>
20+
<div class="container">
21+
<div id="all_dialogs"></div>
22+
<div class="conversations">
23+
<div class="jsClose"></div>
24+
</div>
25+
<div id="experiments" class="labs">
26+
<div class="center">
27+
<h1>Chat editing</h1>
28+
<p>Edit or remove specific parts of chat conversations</p>
29+
<div class="center">
30+
<button onclick="saveChanges()" id="save_changes">Save Changes</button>
31+
<button class="add_field" onclick="addField()">Add fields</button>
32+
<br><br>
33+
</div>
34+
<div class="center">
35+
<div class="info_warning"></div>
36+
<div id="edit_task"></div>
37+
</div>
38+
39+
</div>
40+
</div>
41+
42+
</div> <!-- end container -->
43+
<script src="../../js/edit.js?v=0.0.4"></script>
44+
</body>
45+
<style>
46+
#edit_task{
47+
}
48+
label{
49+
/* display: grid;
50+
margin-bottom: 25px; */
51+
max-width: 80%;
52+
}
53+
#edit_task textarea{
54+
float: left;
55+
padding: 4px !important;
56+
border-radius: 5px !important;
57+
}
58+
#edit_task button{
59+
width: fit-content;
60+
}
61+
#edit_task button{
62+
float: left;
63+
}
64+
#my_form{
65+
max-height: 70dvh;
66+
overflow-y: scroll;
67+
}
68+
.block{
69+
display: inline-grid;
70+
width: 80%;
71+
margin: 0 10% 35px;
72+
}
73+
74+
.save{
75+
color: #fff;
76+
background-color: #25a359;
77+
font-weight: 600;
78+
}
79+
80+
</style>
81+
</html>

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212
<link rel="icon" href="favicon.png">
1313
<link rel="stylesheet" href="css/highlight_js/themes/github-dark-dimmed.css?v=1.0.3">
14-
<link rel="stylesheet" href="css/chat.css?v=3.2.4">
14+
<link rel="stylesheet" href="css/chat.css?v=3.2.7">
1515
<link rel="manifest" href="manifest.json">
1616
<meta property="og:type" content="article">
1717
<meta property="og:title" content="OrionChat">
@@ -77,7 +77,7 @@
7777
<script src="js/4devs.js?v=1.0.1"></script>
7878
<script src="js/prompts.js?v=1.1.0"></script>
7979
<script src="js/tools_list.js?v=1.2.0"></script>
80-
<script src="js/script.js?v=3.2.6"></script>
80+
<script src="js/script.js?v=3.2.8"></script>
8181
<script src="js/search_chats.js?v=0.0.3"></script>
8282
<script src="js/voice_rec.js?v=1.0.6"></script>
8383
<script src="js/nuggets.js?v=0.0.1"></script>

js/edit.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
let edit_url = new URL(document.URL);
2+
chat_id = edit_url.searchParams.get('chat_id')?.trim();
3+
let chat_data = localStorage.getItem(chat_id);
4+
let form_ele = document.createElement('div');
5+
form_ele.id = 'my_form';
6+
let edit_task = document.querySelector('#edit_task');
7+
8+
if (chat_data) {
9+
chat_data = JSON.parse(chat_data);
10+
let txt_area,delete_btn, block;
11+
let idx = 0;
12+
chat_data.messages.forEach(data=>{
13+
block = document.createElement('div');
14+
block.innerHTML = data.role+":";
15+
block.classList.add('block');
16+
txt_area = document.createElement('textarea');
17+
txt_area.oninput = ()=>{
18+
document.querySelector("#save_changes").classList.add('save')
19+
}
20+
delete_btn = document.createElement('button');
21+
delete_btn.innerText = 'Delete';
22+
let part_id = idx;
23+
let block_rm = block;
24+
delete_btn.addEventListener('click',()=>{
25+
removeChatPart(part_id, block_rm);
26+
})
27+
idx++;
28+
29+
let tot_lines = data.content.match(/\n/g)?.length ?? 0;
30+
if(tot_lines > 2){
31+
let px = tot_lines * 16;
32+
if(px > 90){
33+
px = 90;
34+
}
35+
txt_area.style.height = `${px}px`;
36+
}
37+
txt_area.value = data.content;
38+
txt_area.setAttribute('data-role',data.role);
39+
block.appendChild(txt_area);
40+
block.append(delete_btn);
41+
form_ele.append(block)
42+
})
43+
edit_task.append(form_ele)
44+
45+
}else {
46+
console.log('no chat data')
47+
}
48+
49+
function removeChatPart(id, block){
50+
block.remove();
51+
chat_data.messages.splice(id, 1);
52+
localStorage.setItem(chat_id, JSON.stringify(chat_data));
53+
}
54+
55+
function saveChanges(){
56+
let all_inputs = document.querySelectorAll('#my_form textarea');
57+
let new_messages = [];
58+
all_inputs.forEach(input=>{
59+
if(input.value.trim() !== ""){
60+
let role = input.getAttribute('data-role');
61+
let part = {'role': role, content: input.value};
62+
new_messages.push(part);
63+
}
64+
})
65+
chat_data.messages = new_messages;
66+
localStorage.setItem(chat_id, JSON.stringify(chat_data));
67+
window.open('../../#'+chat_id, '_self');
68+
69+
}
70+
71+
72+
function addField(){
73+
const all_textarea = document.querySelectorAll('#edit_task textarea');
74+
const lastTextarea = all_textarea[all_textarea.length - 1];
75+
let role = 'user';
76+
if(lastTextarea.getAttribute('data-role') === 'user'){
77+
role = 'assistant';
78+
}
79+
let ta,del_button, div_block;
80+
let idx = chat_data.messages.length - 1;
81+
div_block = document.createElement('div');
82+
div_block.innerHTML = role+":";
83+
div_block.classList.add('block');
84+
ta = document.createElement('textarea');
85+
ta.oninput = ()=>{
86+
document.querySelector("#save_changes").classList.add('save')
87+
}
88+
del_button = document.createElement('button');
89+
del_button.innerText = 'Delete';
90+
let part_id = idx;
91+
del_button.addEventListener('click',()=>{
92+
removeChatPart(part_id, div_block);
93+
})
94+
idx++;
95+
96+
ta.setAttribute('data-role', role);
97+
div_block.appendChild(ta);
98+
div_block.append(del_button);
99+
form_ele.append(div_block)
100+
ta.scrollIntoView();
101+
}

js/script.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ function addConversation(role, content, add_to_document = true, do_scroll = true
324324
cnt = converter.makeHtml(full_content);
325325
div.innerHTML = cnt;
326326
genAudio(clen_content, div);
327+
327328
} else {
328329
let lastBot = document.querySelectorAll(".bot")[document.querySelectorAll(".bot").length - 1];
329330
genAudio(clen_content, lastBot);
@@ -346,8 +347,7 @@ function saveLocalHistory() {
346347
localStorage.setItem(chat_id.toString(), JSON.stringify(conversations));
347348
}catch (e) {
348349
if (e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED'){
349-
addWarning('Your browser has reached the maximum number of items allowed for local storage.' +
350-
' Please clear out some old chats to free up space.', false);
350+
//addWarning('Your browser has reached the maximum number of items allowed for local storage. Please clear out some old chats to free up space.', false);
351351
}
352352
}
353353
}
@@ -550,7 +550,6 @@ function loadOldConversation(old_talk_id) {
550550
}
551551
div_talk.innerHTML = converter.makeHtml(full_content);
552552
}
553-
554553
chatMessages.append(div_talk);
555554

556555
});
@@ -985,17 +984,25 @@ function enableFullTextCopy() {
985984
if (!has_copy_btn) { // to not be added more the one time
986985
const button = document.createElement('button');
987986
const btn_info = document.createElement('button');
987+
const btn_edit = document.createElement('button');
988988
const ele = document.createElement('div');
989989
ele.className = 'btn-ft-group';
990990
button.className = 'copy-btn';
991991
btn_info.className = 'see_info';
992+
btn_edit.className = 'btn-edit btn-new';
992993
button.innerText = 'Copy text';
993994
btn_info.innerText = 'Info';
995+
btn_edit.innerText = 'Edit';
994996
btn_info.onclick = () => {
995997
showInfo();
996998
}
999+
btn_edit.onclick = ()=>{
1000+
window.open('experiments/chat_editing?chat_id='+chat_id,'_blank');
1001+
1002+
}
9971003
ele.append(button);
9981004
ele.append(btn_info)
1005+
ele.append(btn_edit)
9991006
div.append(ele);
10001007
button.addEventListener('click', () => {
10011008
//const full_text = div_copy.innerHTML;
@@ -2492,8 +2499,6 @@ async function streamChat(can_use_tools = true) {
24922499
hljs.highlightAll();
24932500
if (first_response) {
24942501
first_response = false;
2495-
//toggleAnimation(true);
2496-
//toggleAiGenAnimation(false);
24972502
botMessageDiv.scrollIntoView();
24982503
}
24992504

@@ -3598,7 +3603,6 @@ if(url_set_model && url_set_platform){
35983603

35993604

36003605

3601-
36023606
}
36033607
new_url = new_url.split('?')[0];
36043608
new_url = new_url.split("#")[0];

0 commit comments

Comments
 (0)