summaryrefslogtreecommitdiffstats
path: root/g4f/gui
diff options
context:
space:
mode:
authorabc <98614666+xtekky@users.noreply.github.com>2024-03-07 13:31:32 +0100
committerabc <98614666+xtekky@users.noreply.github.com>2024-03-07 13:31:32 +0100
commit8f7dbfec63edf58a3845b0bd9b06c32f41380856 (patch)
tree2945f1f1e04450a47e45a8f12bc50efb384b54f5 /g4f/gui
parent~ | fixed Vercel Provider (diff)
parentMerge pull request #1660 from Commenter123321/patch-1 (diff)
downloadgpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.tar
gpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.tar.gz
gpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.tar.bz2
gpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.tar.lz
gpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.tar.xz
gpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.tar.zst
gpt4free-8f7dbfec63edf58a3845b0bd9b06c32f41380856.zip
Diffstat (limited to 'g4f/gui')
-rw-r--r--g4f/gui/client/html/index.html8
-rw-r--r--g4f/gui/client/js/chat.v1.js9
-rw-r--r--g4f/gui/server/internet.py2
3 files changed, 8 insertions, 11 deletions
diff --git a/g4f/gui/client/html/index.html b/g4f/gui/client/html/index.html
index 96829b2c..887562c2 100644
--- a/g4f/gui/client/html/index.html
+++ b/g4f/gui/client/html/index.html
@@ -31,12 +31,16 @@
</script>
<script id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/mistral-tokenizer-js" async>
- import mistralTokenizer from 'mistral-tokenizer-js'
+ import mistralTokenizer from "mistral-tokenizer-js"
</script>
<script type="module" src="https://belladoreai.github.io/llama-tokenizer-js/llama-tokenizer.js" async>
- import llamaTokenizer from 'llama-tokenizer-js'
+ import llamaTokenizer from "llama-tokenizer-js"
</script>
<script src="https://unpkg.com/gpt-tokenizer/dist/cl100k_base.js" async></script>
+ <script type="module" async>
+ import { countWords } from 'https://esm.run/alfaaz';
+ window.countWords = countWords;
+ </script>
<script>
const user_image = '<img src="/assets/img/user.png" alt="your avatar">';
const gpt_image = '<img src="/assets/img/gpt.png" alt="your avatar">';
diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js
index 9772fbf7..7135b8f6 100644
--- a/g4f/gui/client/js/chat.v1.js
+++ b/g4f/gui/client/js/chat.v1.js
@@ -66,7 +66,6 @@ const register_remove_message = async () => {
}
const delete_conversations = async () => {
- localStorage.clear();
for (let i = 0; i < localStorage.length; i++){
let key = localStorage.key(i);
if (key.startsWith("conversation:")) {
@@ -476,12 +475,6 @@ const load_conversation = async (conversation_id) => {
}, 500);
};
-// https://stackoverflow.com/questions/20396456/how-to-do-word-counts-for-a-mixture-of-english-and-chinese-in-javascript
-function count_words(str) {
- var matches = str.match(/[\u00ff-\uffff]|\S+/g);
- return matches ? matches.length : 0;
-}
-
function count_tokens(model, text) {
if (model.startsWith("gpt-3") || model.startsWith("gpt-4")) {
return GPTTokenizer_cl100k_base?.encode(text).length;
@@ -497,7 +490,7 @@ function count_tokens(model, text) {
function count_words_and_tokens(text, model) {
const tokens_count = model ? count_tokens(model, text) : null;
const tokens_append = tokens_count ? `, ${tokens_count} tokens` : "";
- return `(${count_words(text)} words${tokens_append})`
+ return countWords ? `(${countWords(text)} words${tokens_append})` : "";
}
const get_conversation = async (conversation_id) => {
diff --git a/g4f/gui/server/internet.py b/g4f/gui/server/internet.py
index e784e52d..a1fafa7d 100644
--- a/g4f/gui/server/internet.py
+++ b/g4f/gui/server/internet.py
@@ -101,7 +101,7 @@ async def search(query: str, n_results: int = 5, max_words: int = 2500, add_text
raise MissingRequirementsError('Install "duckduckgo-search" and "beautifulsoup4" package')
async with AsyncDDGS() as ddgs:
results = []
- async for result in ddgs.text(
+ for result in await ddgs.text(
query,
region="wt-wt",
safesearch="moderate",