Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleChat: a simple and dumb web front end for testing /chat/completions and /completions end points and try chat #7350

Merged
merged 64 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
69ecad2
SimpleChat: Add a skeletal html page
hanishkvc May 17, 2024
0402a4b
SimpleChat: A js skeleton with SimpleChat class
hanishkvc May 17, 2024
1d3cc93
SimpleChat: request_json, globals, startme
hanishkvc May 17, 2024
70e5860
SimpleChatJS: Roles Class, submitClick
hanishkvc May 17, 2024
24d348a
SimpleChat:HTML: Bring in the js file
hanishkvc May 17, 2024
256e02c
SimpleChat: Rather value wrt input text element
hanishkvc May 17, 2024
639d647
SimpleChat: Also add completions related prompt
hanishkvc May 17, 2024
ce4aaeb
SimpleChat: Use common helper logic wrt json data
hanishkvc May 17, 2024
27268a6
SimpleChat: Move handling of submit request into its own func
hanishkvc May 17, 2024
33bc67b
SimpleChat: Try handshake with llm over its web service endpoint
hanishkvc May 17, 2024
c665347
SimpleChat:JS: Extract model response and show to user
hanishkvc May 17, 2024
564469e
SimpleChat:JS: Messages/Prompt, indicate working to end user
hanishkvc May 17, 2024
7d772f6
SimpleChat: Try keep input element in view
hanishkvc May 17, 2024
9942851
SimpleChat: Diff user/assistant msgs, Make input wider
hanishkvc May 17, 2024
ebe330d
SimpleChat: Move into its own sub directory to avoid confusion
hanishkvc May 17, 2024
29d2d22
SimpleChat:sh: Add simple shell script to run python3 http.server
hanishkvc May 17, 2024
e62087b
SimpleChat:JS: Try trap enter key press wrt input text field
hanishkvc May 17, 2024
9feb58e
SimpleChat: Allow user to select chat or completion mode
hanishkvc May 17, 2024
3e5edba
SimpleChat: Dont submit if already submitted and waiting
hanishkvc May 17, 2024
aef32d9
SimpleChat:JS: Handle difference in response
hanishkvc May 17, 2024
b364417
SimpleChat:JS: Force completion mode be single message by default
hanishkvc May 17, 2024
668b987
SimpleChat: Add a simple readme file
hanishkvc May 17, 2024
69817fe
SimpleChat:HTML: Cleanup/structure UI a bit, Add input for system
hanishkvc May 17, 2024
ae52ad1
SimpleChat:Allow system prompt to be set, if provided before user
hanishkvc May 17, 2024
884adfd
SimpleChat: Ignore empty user input, without trimming
hanishkvc May 17, 2024
72151aa
SimpleChat:Alert user if they provide sysprompt late or change it
hanishkvc May 17, 2024
601fedf
SimpleChat: Move handling systemprompt into its own func
hanishkvc May 17, 2024
0d0a28b
SimpleChat:HTML: Add a style for system role message
hanishkvc May 17, 2024
65a56e6
SimpleChat: Update the readme file
hanishkvc May 17, 2024
ebd5e71
SimpleChat:CSS: Move style info into its own css file
hanishkvc May 18, 2024
a1a2f36
SimpleChat:CSS: Allow for chat div to be scrollable
hanishkvc May 18, 2024
a944ce7
SimpleChat:JS: Try ensure the last entry in chat is visible
hanishkvc May 18, 2024
6eb1e0f
SimpleChat:JS: bottom of element visible, Set focus to user input
hanishkvc May 18, 2024
5a5f6ab
SimpleChat: Update notes a bit. Try keep browser happy
hanishkvc May 18, 2024
676053f
SimpleChat:HTML:Group user input+btn together; Note about multichat
hanishkvc May 18, 2024
7905f2f
SimpleChat:JS: Allow for changing system prompt anytime for future
hanishkvc May 18, 2024
5976126
SimpleChat:Readme: Note about handle_systemprompt begin/anytime
hanishkvc May 18, 2024
c191e47
SimpleChat:HTML: Add viewport meta for better mobile friendliness
hanishkvc May 19, 2024
c88088c
SimpleChat:HtmlCss: Cleanup UI flow
hanishkvc May 20, 2024
dfadac7
SimpleChat: textarea for multiline user chat, inturn shift+enter 4 enter
hanishkvc May 20, 2024
6597faf
SimpleChat: Make vertical layout better responsive (flex based)
hanishkvc May 20, 2024
e5000cd
SimpleChat: Rename simplechat.html to index.html, update readme
hanishkvc May 20, 2024
3fc607f
SimpleChat: Screen fixed view and scrolling, Printing full
hanishkvc May 20, 2024
af62197
SimpleChat:JS:CI: Avoid space at end of jsdoc param line
hanishkvc May 20, 2024
9b97fea
SimpleChat:JS: MultiChat initial skeleton
hanishkvc May 20, 2024
5c1a9f4
SimpleChat:JS: Move system prompt begin/anytime into SimpleChat
hanishkvc May 20, 2024
fcf2af9
SimpleChat:JS:Keep MultiChatUI simple for now
hanishkvc May 20, 2024
8ef1aa9
SimpleChat:JS: Move handle submit into MultiChat, build on same
hanishkvc May 20, 2024
7be6aeb
SimpleChat:JS: Move to dictionary of SimpleChat, instead of array
hanishkvc May 20, 2024
1cd10ae
SimpleChat: Move ui elements into MultiChatUI, Update el IDs
hanishkvc May 21, 2024
1b82f22
SimpleChat:MCUI:Show available chat sessions, try switch btw them
hanishkvc May 21, 2024
928cc36
SimpleChat:MCUI: Store and use current chat session id
hanishkvc May 21, 2024
d57274b
SimpleChat:MCUI: Delay enabling user-input to avoid race
hanishkvc May 21, 2024
7297dda
SimpleChat: Take care of system prompt
hanishkvc May 21, 2024
3458d2f
SimpleChat:GetSystemLatest, fix a oversight.
hanishkvc May 21, 2024
b9f9c0e
SimpleChat:MCUI: Allow selected chat-session btn to be highlighted
hanishkvc May 21, 2024
68ef740
SimpleChat:Cleanup corners
hanishkvc May 21, 2024
2a40719
SimpleChat:MCUI: Ensure req-resp failure doesnt lock up things
hanishkvc May 21, 2024
14083d1
SimpleChat:MCUI: Support for new chat sessions
hanishkvc May 21, 2024
6c71277
SimpleChat:MCUI: CreateSessionBtn helper, use wrt NewChat
hanishkvc May 21, 2024
d3405ea
SimpleChat:MCUI: NewChat btn first before existing chat sessions
hanishkvc May 21, 2024
c2e8d62
SimpleChat:MCUI:CornerCases:Skip new chat, show only if current
hanishkvc May 21, 2024
fb848b2
SimpleChat: Update readme, title, show usage if no chat to show
hanishkvc May 21, 2024
1d87c50
SimpleChat: Cleanup the log/dialog messages a bit
hanishkvc May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/server/public_simplechat/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>SimpleChat (LlamaCPP, ...) </title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="message" content="Save Nature Save Earth" />
<meta name="description" content="SimpleChat: trigger LLM web service endpoints /chat/completions and /completions, single/multi chat sessions" />
<meta name="author" content="by Humans for All" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<script src="simplechat.js" defer></script>
<link rel="stylesheet" href="simplechat.css" />
</head>
<body>
<div class="samecolumn" id="fullbody">

<div class="sameline">
<p class="heading flex-grow" > <b> SimpleChat </b> </p>
<div class="sameline">
<label for="api-ep">Mode:</label>
<select name="api-ep" id="api-ep">
<option value="chat" selected>Chat</option>
<option value="completion">Completion</option>
</select>
</div>
</div>

<div id="sessions-div" class="sameline"></div>

<hr>
<div class="sameline">
<label for="system-in">System</label>
<input type="text" name="system" id="system-in" class="flex-grow"/>
</div>

<hr>
<div id="chat-div">
<p> Enter the system prompt above, before entering/submitting any user query.</p>
<p> Enter your text to the ai assistant below.</p>
<p> Use shift+enter for inserting enter.</p>
<p> Refresh the page to start over fresh.</p>
</div>

<hr>
<div class="sameline">
<textarea id="user-in" class="flex-grow" rows="3"></textarea>
<button id="user-btn">submit</button>
</div>

</div>
</body>
</html>
81 changes: 81 additions & 0 deletions examples/server/public_simplechat/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

# SimpleChat

by Humans for All.


## overview

This simple web frontend, allows triggering/testing the server's /completions or /chat/completions endpoints
in a simple way with minimal code from a common code base. Inturn additionally it tries to allow single or
multiple independent back and forth chatting to an extent, with the ai llm model at a basic level, with their
own system prompts.

The UI follows a responsive web design so that the layout can adapt to available display space in a usable
enough manner, in general.

NOTE: Given that the idea is for basic minimal testing, it doesnt bother with any model context length and
culling of old messages from the chat.

NOTE: It doesnt set any parameters other than temperature for now. However if someone wants they can update
the js file as needed.


## usage

One could run this web frontend directly using server itself or if anyone is thinking of adding a built in web
frontend to configure the server over http(s) or so, then run this web frontend using something like python's
http module.

### running using examples/server

bin/server -m path/model.gguf --path ../examples/server/public_simplechat [--port PORT]

### running using python3's server module

first run examples/server
* bin/server -m path/model.gguf

next run this web front end in examples/server/public_simplechat
* cd ../examples/server/public_simplechat
* python3 -m http.server PORT

### using the front end

Open this simple web front end from your local browser
* http://127.0.0.1:PORT/index.html

Once inside
* Select between chat and completion mode. By default it is set to chat mode.
* If you want to provide a system prompt, then ideally enter it first, before entering any user query.
* if chat.add_system_begin is used
* you cant change the system prompt, after it is has been submitted once along with user query.
* you cant set a system prompt, after you have submitted any user query
* if chat.add_system_anytime is used
* one can change the system prompt any time during chat, by changing the contents of system prompt.
* inturn the updated/changed system prompt will be inserted into the chat session.
* this allows for the subsequent user chatting to be driven by the new system prompt set above.
* Enter your query and either press enter or click on the submit button.
If you want to insert enter (\n) as part of your chat/query to ai model, use shift+enter.
* Wait for the logic to communicate with the server and get the response.
* the user is not allowed to enter any fresh query during this time.
* the user input box will be disabled and a working message will be shown in it.
* just refresh the page, to reset wrt the chat history and or system prompt and start afresh.
* Using NewChat one can start independent chat sessions.
* two independent chat sessions are setup by default.


## Devel note

Sometimes the browser may be stuborn with caching of the file, so your updates to html/css/js
may not be visible. Also remember that just refreshing/reloading page in browser or for that
matter clearing site data, dont directly override site caching in all cases. Worst case you may
have to change port. Or in dev tools of browser, you may be able to disable caching fully.

Concept of multiple chat sessions with different servers, as well as saving and restoring of
those across browser usage sessions, can be woven around the SimpleChat/MultiChatUI class and
its instances relatively easily, however given the current goal of keeping this simple, it has
not been added, for now.

By switching between chat.add_system_begin/anytime, one can control whether one can change
the system prompt, anytime during the conversation or only at the beginning.
61 changes: 61 additions & 0 deletions examples/server/public_simplechat/simplechat.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* the styling of the simplechat web frontend
* by Humans for All
*/

#fullbody {
height: 98vh;
}

.heading {
background-color: lightgray;
}

.session-selected {
background-color: lightblue;
}

.role-system {
background-color: lightblue;
}
.role-user {
background-color: lightgray;
}

.flex-grow {
flex-grow: 1;
}
.float-right {
float: right;
}

#chat-div {
overflow: scroll;
flex-grow: 1;
flex-shrink: 1;
min-height: 40vh;
}
button {
min-width: 8vw;
}

.sameline {
display: flex;
flex-direction: row;
}
.samecolumn {
display: flex;
flex-direction: column;
}

* {
margin: 0.6vmin;
}

@media print {

#fullbody {
height: auto;
}

}
Loading
Loading