Comments (10)
I think what would be even better is not to lock the write section with "processing query" but to add a cancel button and also if you try to prompt while it's prompting something else it's put into a queue
from chatdocs.
In ui.py before def ui
I added:
# A flag indicating whether the worker is busy.
worker_busy = False
Then within def(worker(... at the beginning I added:
global worker_busy
worker_busy = True
At the end of this part I added:
worker_busy = False
Then within def ui
I added:
@app.get("/worker_status")
async def worker_status():
# Return the status of the worker.
return {"busy": worker_busy}
In the index.html before </script>
I added:
// Check the status of the worker every second and disable the submit button if the worker is busy.
function checkWorkerStatus() {
Promise.race([
fetch('/worker_status'),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('timeout')), 1000) // 1 second timeout
)
])
.then(response => response.json())
.then(data => {
if (data.busy) {
form.elements.query.style.color = 'red';
form.elements.submit.disabled = true;
if (form.elements.query.value === 'Processing your query. Please wait...') {
document.title = '\u{1F7E0} answering: ChatDocs';
} else {
document.title = '\u{1F534} busy: ChatDocs';
}
} else {
form.elements.submit.disabled = false; // Only enable the submit button if the worker is not busy
form.elements.query.style.color = 'white'; // Reset the color to the default
document.title = '\u{1F7E2} available: ChatDocs';
}
})
.catch(error => {
console.error(error);
form.elements.query.style.color = 'red';
form.elements.submit.disabled = true;
if (form.elements.query.value === 'Processing your query. Please wait...') {
document.title = '\u{1F7E0} answering: ChatDocs';
} else {
document.title = '\u{1F534} busy: ChatDocs';
}
})
.finally(() => {
// Schedule the next check regardless of whether the fetch operation was successful or not.
setTimeout(checkWorkerStatus, 1000);
});
}
// Start checking the worker status as soon as the script runs.
document.addEventListener('DOMContentLoaded', checkWorkerStatus);
This updates a red, green or yellow point in the title bar every second, so people now it if it runs in the background also.
During the processing of the prompt the webserver doesn't react to other requests, so that's why there is a short timeout which also triggers the busy state.
But as I said, it's not perfect. If someone closes the page while it is processing the prompt, the answer might get delivered to another user. It's the quickest change I could do without changing the architecture.
from chatdocs.
Many thanks!
from chatdocs.
In the meantime I've implemented a worker_status endpoint in ui.py which is queried by a corresponding JavaScript function which checks every second and disables the text field as soon as the worker is running for everyone, also shows the status in the title bar so people see when it's available. But it's far from perfect...
from chatdocs.
In the meantime I've implemented a worker_status endpoint in ui.py which is queried by a corresponding JavaScript function which checks every second and disables the text field as soon as the worker is running for everyone, also shows the status in the title bar so people see when it's available. But it's far from perfect...
@wypiki Would you be willing to share the code? Thanks
from chatdocs.
@wypiki would this also give you the ability to run multiple instances. Let's say I prompt in one webbrowser and run it on another webbrowser and try to prompt there also (a que is present)
from chatdocs.
I couldn't understand the instructions fully mind sharing the ui.py and index.html ?
from chatdocs.
I figured it out! It works great!
I have been able to make it crash when I loaded up two prompt windows with content and more or less hit enter at the exact same time. I wonder if we can do something to fix that. What do you think @wypiki
from chatdocs.
@wypiki would this also give you the ability to run multiple instances. Let's say I prompt in one webbrowser and run it on another webbrowser and try to prompt there also (a que is present)
No, there's no queue, it just blocks other requests for this time and shows a colored indicator in the titlebar so people know when it's ready. A queue would be a bigger change, didn't want to spend too much time with that yet in hopes @marella implements it in the future.
from chatdocs.
I couldn't understand the instructions fully mind sharing the ui.py and index.html ?
Sorry, I'm still on vacation.
I figured it out! It works great!
I have been able to make it crash when I loaded up two prompt windows with content and more or less hit enter at the exact same time. I wonder if we can do something to fix that. What do you think @wypiki
Glad, you figured it out! Yes, that's a weakpoint of my implementation. It's unlikely that this happens though. The easiest but not most efficient change would be lowering the timeout in promise.race():
setTimeout(() => reject(new Error('timeout')), 80)
This would change the state to busy when the webserver is not replying because of being busy to 80 milliseconds instead of 1 second. In a local network with a fast cpu that would probably be fine. Over VPN in combination with a maxed out CPU this could lead to unwanted busy states. But usually responds should come in 5-30ms, so it should be fine.
from chatdocs.
Related Issues (20)
- how to turn off citations? HOT 1
- `score_threshold` in db.as_retriever doesn't seem to be enforced HOT 1
- ModuleNotFoundError: No module named 'langchain.embeddings.base' HOT 1
- ImportError: cannot import name 'soft_unicode' from 'markupsafe' HOT 1
- pad_token errors
- Google colab: OSError: libcudart.so.12: cannot open shared object file: No such file or directory
- model DocsGPT-7B
- Error ImportError: cannot import name 'url_quote' from 'werkzeug.urls'after this command chatdocs ui HOT 1
- ui color change HOT 1
- HTTPS not working? Please help.
- In which path the add file will be loaded any how can we delete the loaded file ?
- Works only on one session at a time.
- Error ImportError: cannot import name 'url_quote' from 'werkzeug.urls' HOT 1
- Turning on GPU gives PTX error
- Tabulate missing as dependency
- Update to Python 3.12 - Remove 'stdlib distutils module' requirement (deprecated)
- French language support
- IndexError when using chatdocs add command for some documents
- Can't download models anymore, not sure why. Used to work perfectly HOT 4
- Is chatdocs still being supported? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatdocs.