This commit is contained in:
Saifeddine ALOUI 2024-02-11 02:09:31 +01:00
parent fca7c54748
commit 3c33cb55a0
11 changed files with 349 additions and 328 deletions

@ -1 +1 @@
Subproject commit 0337e8a38bbbfe12d34a7eea304710b355826f3c Subproject commit 62677f4ee5e6c01ab83a25abf9e90182acd48487

View File

@ -759,7 +759,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
self.personality.step_start("Crafting internet search query") self.personality.step_start("Crafting internet search query")
query = self.personality.fast_gen(f"!@>discussion:\n{discussion[-2048:]}\n!@>instruction: Read the discussion and craft a web search query suited to recover needed information to reply to last {self.config.user_name} message.\nDo not answer the prompt. Do not add explanations.\n!@>websearch query: ", max_generation_size=256, show_progress=True, callback=self.personality.sink) query = self.personality.fast_gen(f"!@>discussion:\n{discussion[-2048:]}\n!@>instruction: Read the discussion and craft a web search query suited to recover needed information to reply to last {self.config.user_name} message.\nDo not answer the prompt. Do not add explanations.\n!@>websearch query: ", max_generation_size=256, show_progress=True, callback=self.personality.sink)
self.personality.step_end("Crafting internet search query") self.personality.step_end("Crafting internet search query")
self.personality.step(f"query:{query}") self.personality.step(f"web search query: {query}")
self.personality.step_start("Performing Internet search") self.personality.step_start("Performing Internet search")
@ -874,7 +874,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
# Raise an error if the available space is 0 or less # Raise an error if the available space is 0 or less
if available_space<1: if available_space<1:
self.error("Not enough space in context!!") self.error(f"Not enough space in context!!\nVerify that your vectorization settings for documents or internet search are realistic compared to your context size.\nYou are {available_space} short of context!")
raise Exception("Not enough space in context!!") raise Exception("Not enough space in context!!")
# Accumulate messages until the cumulative number of tokens exceeds available_space # Accumulate messages until the cumulative number of tokens exceeds available_space
@ -1381,114 +1381,119 @@ class LOLLMSWebUI(LOLLMSElfServer):
# send the message to the bot # send the message to the bot
print(f"Received message : {message.content}") print(f"Received message : {message.content}")
if self.connections[client_id]["current_discussion"]: if self.connections[client_id]["current_discussion"]:
if not self.model:
self.error("No model selected. Please make sure you select a model before starting generation", client_id=client_id)
return
# First we need to send the new message ID to the client
if is_continue:
self.connections[client_id]["current_discussion"].load_message(message_id)
self.connections[client_id]["generated_text"] = message.content
else:
self.new_message(client_id, self.personality.name, "")
self.update_message(client_id, "✍ warming up ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_START)
# prepare query and reception
self.discussion_messages, self.current_message, tokens, context_details, internet_search_infos = self.prepare_query(client_id, message_id, is_continue, n_tokens=self.config.min_n_predict, generation_type=generation_type)
self.prepare_reception(client_id)
self.generating = True
self.connections[client_id]["processing"]=True
try: try:
self.generate( if not self.model:
self.discussion_messages, self.error("No model selected. Please make sure you select a model before starting generation", client_id=client_id)
self.current_message, return
context_details=context_details, # First we need to send the new message ID to the client
n_predict = self.config.ctx_size-len(tokens)-1, if is_continue:
client_id=client_id, self.connections[client_id]["current_discussion"].load_message(message_id)
callback=partial(self.process_chunk,client_id = client_id) self.connections[client_id]["generated_text"] = message.content
) else:
if self.config.enable_voice_service and self.config.auto_read and len(self.personality.audio_samples)>0: self.new_message(client_id, self.personality.name, "")
try: self.update_message(client_id, "✍ warming up ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_START)
self.process_chunk("Generating voice output",MSG_TYPE.MSG_TYPE_STEP_START,client_id=client_id)
from lollms.services.xtts.lollms_xtts import LollmsXTTS # prepare query and reception
if self.tts is None: self.discussion_messages, self.current_message, tokens, context_details, internet_search_infos = self.prepare_query(client_id, message_id, is_continue, n_tokens=self.config.min_n_predict, generation_type=generation_type)
self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices", xtts_base_url= self.config.xtts_base_url) self.prepare_reception(client_id)
language = convert_language_name(self.personality.language) self.generating = True
self.tts.set_speaker_folder(Path(self.personality.audio_samples[0]).parent) self.connections[client_id]["processing"]=True
fn = self.personality.name.lower().replace(' ',"_").replace('.','') try:
fn = f"{fn}_{message_id}.wav" self.generate(
url = f"audio/{fn}" self.discussion_messages,
self.tts.tts_to_file(self.connections[client_id]["generated_text"], Path(self.personality.audio_samples[0]).name, f"{fn}", language=language) self.current_message,
fl = f""" context_details=context_details,
<audio controls> n_predict = self.config.ctx_size-len(tokens)-1,
<source src="{url}" type="audio/wav"> client_id=client_id,
Your browser does not support the audio element. callback=partial(self.process_chunk,client_id = client_id)
</audio> )
""" if self.config.enable_voice_service and self.config.auto_read and len(self.personality.audio_samples)>0:
self.process_chunk("Generating voice output", MSG_TYPE.MSG_TYPE_STEP_END, {'status':True},client_id=client_id) try:
self.process_chunk(fl,MSG_TYPE.MSG_TYPE_UI, client_id=client_id) self.process_chunk("Generating voice output",MSG_TYPE.MSG_TYPE_STEP_START,client_id=client_id)
from lollms.services.xtts.lollms_xtts import LollmsXTTS
""" if self.tts is None:
self.info("Creating audio output",10) self.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices", xtts_base_url= self.config.xtts_base_url)
self.personality.step_start("Creating audio output") language = convert_language_name(self.personality.language)
if not PackageManager.check_package_installed("tortoise"): self.tts.set_speaker_folder(Path(self.personality.audio_samples[0]).parent)
PackageManager.install_package("tortoise-tts") fn = self.personality.name.lower().replace(' ',"_").replace('.','')
from tortoise import utils, api fn = f"{fn}_{message_id}.wav"
import sounddevice as sd url = f"audio/{fn}"
if self.tts is None: self.tts.tts_to_file(self.connections[client_id]["generated_text"], Path(self.personality.audio_samples[0]).name, f"{fn}", language=language)
self.tts = api.TextToSpeech( kv_cache=True, half=True) fl = f"\n".join([
reference_clips = [utils.audio.load_audio(str(p), 22050) for p in self.personality.audio_samples] f"<audio controls>",
tk = self.model.tokenize(self.connections[client_id]["generated_text"]) f' <source src="{url}" type="audio/wav">',
if len(tk)>100: f' Your browser does not support the audio element.',
chunk_size = 100 f'</audio>'
])
self.process_chunk("Generating voice output", MSG_TYPE.MSG_TYPE_STEP_END, {'status':True},client_id=client_id)
self.process_chunk(fl,MSG_TYPE.MSG_TYPE_UI, client_id=client_id)
for i in range(0, len(tk), chunk_size): """
chunk = self.model.detokenize(tk[i:i+chunk_size]) self.info("Creating audio output",10)
if i==0: self.personality.step_start("Creating audio output")
pcm_audio = self.tts.tts_with_preset(chunk, voice_samples=reference_clips, preset='fast').numpy().flatten() if not PackageManager.check_package_installed("tortoise"):
else: PackageManager.install_package("tortoise-tts")
pcm_audio = np.concatenate([pcm_audio, self.tts.tts_with_preset(chunk, voice_samples=reference_clips, preset='ultra_fast').numpy().flatten()]) from tortoise import utils, api
else: import sounddevice as sd
pcm_audio = self.tts.tts_with_preset(self.connections[client_id]["generated_text"], voice_samples=reference_clips, preset='fast').numpy().flatten() if self.tts is None:
sd.play(pcm_audio, 22050) self.tts = api.TextToSpeech( kv_cache=True, half=True)
self.personality.step_end("Creating audio output") reference_clips = [utils.audio.load_audio(str(p), 22050) for p in self.personality.audio_samples]
""" tk = self.model.tokenize(self.connections[client_id]["generated_text"])
if len(tk)>100:
chunk_size = 100
for i in range(0, len(tk), chunk_size):
chunk = self.model.detokenize(tk[i:i+chunk_size])
if i==0:
pcm_audio = self.tts.tts_with_preset(chunk, voice_samples=reference_clips, preset='fast').numpy().flatten()
else:
pcm_audio = np.concatenate([pcm_audio, self.tts.tts_with_preset(chunk, voice_samples=reference_clips, preset='ultra_fast').numpy().flatten()])
else:
pcm_audio = self.tts.tts_with_preset(self.connections[client_id]["generated_text"], voice_samples=reference_clips, preset='fast').numpy().flatten()
sd.play(pcm_audio, 22050)
self.personality.step_end("Creating audio output")
"""
except Exception as ex: except Exception as ex:
ASCIIColors.error("Couldn't read") ASCIIColors.error("Couldn't read")
trace_exception(ex) trace_exception(ex)
print() print()
ASCIIColors.success("## Done Generation ##") ASCIIColors.success("## Done Generation ##")
print() print()
except Exception as ex: except Exception as ex:
trace_exception(ex) trace_exception(ex)
print() print()
ASCIIColors.error("## Generation Error ##") ASCIIColors.error("## Generation Error ##")
print() print()
self.cancel_gen = False self.cancel_gen = False
# Send final message # Send final message
if self.config.activate_internet_search: if self.config.activate_internet_search:
from lollms.internet import get_favicon_url, get_root_url from lollms.internet import get_favicon_url, get_root_url
sources_text = '<div class="mt-4 flex flex-wrap items-center gap-x-2 gap-y-1.5 text-sm ">' sources_text = '<div class="mt-4 flex flex-wrap items-center gap-x-2 gap-y-1.5 text-sm ">'
sources_text += '<div class="text-gray-400 mr-10px">Sources:</div>' sources_text += '<div class="text-gray-400 mr-10px">Sources:</div>'
for source in internet_search_infos: for source in internet_search_infos:
url = source["url"] url = source["url"]
favicon_url = get_favicon_url(url) title = source["title"]
if favicon_url is None: brief = source["brief"]
favicon_url ="/personalities/internet/loi/assets/logo.png" favicon_url = get_favicon_url(url)
root_url = get_root_url(url) if favicon_url is None:
sources_text += "\n".join([ favicon_url ="/personalities/internet/loi/assets/logo.png"
f'<a class="flex items-center gap-2 whitespace-nowrap rounded-lg border bg-white px-2 py-1.5 leading-none hover:border-gray-300 dark:border-gray-800 dark:bg-gray-900 dark:hover:border-gray-700" target="_blank" href="{url}">', root_url = get_root_url(url)
f' <img class="h-3.5 w-3.5 rounded" src="{favicon_url}">', sources_text += "\n".join([
f' <div>{root_url}</div>', f'<a class="relative flex items-center gap-2 whitespace-nowrap rounded-lg border bg-white px-2 py-1.5 leading-none hover:border-gray-300 dark:border-gray-800 dark:bg-gray-900 dark:hover:border-gray-700" target="_blank" href="{url}" title="{brief}">',
f'</a>', f' <img class="h-3.5 w-3.5 rounded" src="{favicon_url}">',
]) f' <div>{root_url}</div>',
sources_text += '</div>' f'</a>',
self.connections[client_id]["generated_text"]=self.connections[client_id]["generated_text"].split("!@>")[0] + "\n" + sources_text ])
self.personality.full(self.connections[client_id]["generated_text"]) sources_text += '</div>'
self.connections[client_id]["generated_text"]=self.connections[client_id]["generated_text"].split("!@>")[0] + "\n" + sources_text
self.personality.full(self.connections[client_id]["generated_text"])
except:
pass
self.close_message(client_id) self.close_message(client_id)
self.update_message(client_id, "Generating ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_END) self.update_message(client_id, "Generating ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_END)

View File

@ -28,4 +28,7 @@ uvicorn
python-multipart python-multipart
python-socketio python-socketio
python-socketio[client] python-socketio[client]
python-socketio[asyncio_client] python-socketio[asyncio_client]
selenium

View File

@ -1,14 +1,34 @@
colorama
datasets
einops
jinja2==3.1.3
numpy==1.24.*
pandas
Pillow>=9.5.0
pyyaml
requests
rich
safetensors==0.4.1
scipy
sentencepiece
tensorboard
transformers==4.37.*
tqdm
setuptools
tqdm tqdm
psutil psutil
pytest pytest
pyyaml
markdown
gevent
gevent-websocket
requests
eventlet
websocket-client
GitPython GitPython
setuptools ascii_colors>=0.1.4
numpy beautifulsoup4
packaging packaging
fastapi
uvicorn
python-multipart
python-socketio
python-socketio[client]
python-socketio[asyncio_client]
selenium

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title> <title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-e3a9f414.js"></script> <script type="module" crossorigin src="/assets/index-3b9f838e.js"></script>
<link rel="stylesheet" href="/assets/index-b55bf791.css"> <link rel="stylesheet" href="/assets/index-5f320cbc.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -2,16 +2,21 @@
<form> <form>
<div class="absolute bottom-0 left-0 w-fit min-w-96 w-full justify-center text-center p-4"> <div class="absolute bottom-0 left-0 w-fit min-w-96 w-full justify-center text-center p-4">
<div class="items-center gap-2 rounded-lg border bg-white p-1.5 shadow-sm hover:shadow-none dark:border-gray-800 dark:bg-gray-900 w-fit"> <div v-if="filesList.length > 0 || showPersonalities" class="items-center gap-2 rounded-lg border bg-white p-1.5 shadow-sm hover:shadow-none dark:border-gray-800 dark:bg-gray-900 w-fit">
<!-- EXPAND / COLLAPSE BUTTON --> <!-- EXPAND / COLLAPSE BUTTON -->
<div class="flex"> <div class="flex">
<button v-if="filesList.length > 0" <button
class="mx-1 w-full text-2xl hover:text-secondary duration-75 flex justify-center hover:bg-bg-light-tone hover:dark:bg-bg-dark-tone rounded-lg " class="mx-1 w-full text-2xl hover:text-secondary duration-75 flex justify-center hover:bg-bg-light-tone hover:dark:bg-bg-dark-tone rounded-lg "
:title="showfilesList ? 'Hide file list' : 'Show file list'" type="button" :title="showfilesList ? 'Hide file list' : 'Show file list'" type="button"
@click.stop=" showfilesList = !showfilesList"> @click.stop=" showfilesList = !showfilesList">
<i data-feather="list"></i> <i data-feather="list"></i>
</button> </button>
</div> </div>
<button v-if="loading" type="button"
class="bg-red-500 dark:bg-red-800 hover:bg-red-600 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:hover:bg-bg-dark-tone focus:outline-none dark:focus:ring-blue-800"
@click.stop="stopGenerating">
Stop generating
</button>
<!-- FILES --> <!-- FILES -->
<div v-if="filesList.length > 0 && showfilesList ==true"> <div v-if="filesList.length > 0 && showfilesList ==true">
<div class="flex flex-col max-h-64 "> <div class="flex flex-col max-h-64 ">
@ -94,7 +99,7 @@
@click="clear_files"> @click="clear_files">
<i data-feather="trash" class="w-5 h-5 "></i> <i data-feather="trash" class="w-5 h-5 "></i>
</button> </button>
<button type="button" title="Clear all" <button type="button" title="Download database"
class="flex items-center p-0.5 text-sm rounded-sm hover:text-red-600 active:scale-75" class="flex items-center p-0.5 text-sm rounded-sm hover:text-red-600 active:scale-75"
@click="download_database"> @click="download_database">
<i data-feather="download-cloud" class="w-5 h-5 "></i> <i data-feather="download-cloud" class="w-5 h-5 "></i>
@ -119,15 +124,6 @@
<span class="sr-only">Selecting model...</span> <span class="sr-only">Selecting model...</span>
</div> </div>
</div> </div>
<button v-if="loading" type="button"
class="bg-red-500 dark:bg-red-800 hover:bg-red-600 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:hover:bg-bg-dark-tone focus:outline-none dark:focus:ring-blue-800"
@click.stop="stopGenerating">
Stop generating
</button>
<div class="flex w-fit pb-3 relative grow w-full"> <div class="flex w-fit pb-3 relative grow w-full">
<div class="relative grow flex h-15 cursor-pointer select-none items-center gap-2 rounded-lg border bg-white p-1.5 shadow-sm hover:shadow-none dark:border-gray-800 dark:bg-gray-900" tabindex="0"> <div class="relative grow flex h-15 cursor-pointer select-none items-center gap-2 rounded-lg border bg-white p-1.5 shadow-sm hover:shadow-none dark:border-gray-800 dark:bg-gray-900" tabindex="0">
<div v-if="loading" title="Waiting for reply"> <div v-if="loading" title="Waiting for reply">
@ -805,8 +801,12 @@ export default {
}, },
removeItem(file) { removeItem(file) {
this.filesList = this.filesList.filter((item) => item != file) console.log(file)
// console.log(this.filesList) axios.post('/remove_file',{file}).then(()=>{
this.filesList = this.filesList.filter((item) => item != file)
})
console.log(this.filesList)
}, },
sendMessageEvent(msg) { sendMessageEvent(msg) {
this.$emit('messageSentEvent', msg) this.$emit('messageSentEvent', msg)

View File

@ -174,15 +174,7 @@
> >
<i data-feather="voicemail"></i> <i data-feather="voicemail"></i>
</div> </div>
<svg v-else aria-hidden="true" class="w-6 h-6 animate-spin fill-secondary" viewBox="0 0 100 101 cursor-pointer" title="Generating voice, please stand by ..." <img v-else :src="loading_svg">
fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor" />
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill" />
</svg>
</div> </div>
</div> </div>
@ -206,7 +198,7 @@
<div class="content px-5 pb-5 pt-4"> <div class="content px-5 pb-5 pt-4">
<ol class="list-none"> <ol class="list-none">
<div v-for="(step, index) in message.steps" :key="'step-' + message.id + '-' + index" class="group border-l pb-6 last:!border-transparent last:pb-0 dark:border-gray-800" :style="{ backgroundColor: step.done ? 'transparent' : 'inherit' }"> <div v-for="(step, index) in message.steps" :key="'step-' + message.id + '-' + index" class="group border-l pb-6 last:!border-transparent last:pb-0 dark:border-gray-800" :style="{ backgroundColor: step.done ? 'transparent' : 'inherit' }">
<Step :done="step.done" :message="step.message" :status="step.status" /> <Step :done="step.done" :message="step.message" :status="step.status" :step_type = "step.type"/>
</div> </div>
</ol> </ol>
</div> </div>
@ -472,10 +464,11 @@ export default {
else{ else{
this.isSynthesizingVoice=true this.isSynthesizingVoice=true
axios.post("./text2Audio",{text:this.message.content}).then(response => { axios.post("./text2Audio",{text:this.message.content}).then(response => {
let url = response.data.url this.isSynthesizingVoice=false
console.log(url) let url = response.data.url
this.audio_url = url console.log(url)
this.$emit('updateMessage', this.message.id, this.message.content, this.audio_url) this.audio_url = url
this.$emit('updateMessage', this.message.id, this.message.content, this.audio_url)
}).catch(ex=>{ }).catch(ex=>{
this.$store.state.toast.showToast(`Error: ${ex}`,4,false) this.$store.state.toast.showToast(`Error: ${ex}`,4,false)
this.isSynthesizingVoice=false this.isSynthesizingVoice=false

View File

@ -1,20 +1,20 @@
<template> <template>
<div class="flex items-start"> <div class="flex items-start">
<div class="step flex items-center mb-4"> <div class="step flex items-center mb-4">
<div class="flex items-center justify-center w-6 h-6 mr-2"> <div v-if="step_type=='start_end'" class="flex items-center justify-center w-6 h-6 mr-2">
<div v-if="!done && type=='start_end'"> <div v-if="!done">
<i <i
data-feather="square" data-feather="square"
class="text-gray-400 w-4 h-4" class="text-gray-400 w-4 h-4"
></i> ></i>
</div> </div>
<div v-if="done && status && type=='start_end'"> <div v-if="done && status">
<i <i
data-feather="check-square" data-feather="check-square"
class="text-green-500 w-4 h-4" class="text-green-500 w-4 h-4"
></i> ></i>
</div> </div>
<div v-if="done && !status && type=='start_end'"> <div v-if="done && !status">
<i <i
data-feather="x-square" data-feather="x-square"
class="text-red-500 w-4 h-4" class="text-red-500 w-4 h-4"
@ -56,7 +56,7 @@
type: Boolean, type: Boolean,
required: true required: true
}, },
type: { step_type: {
type: String, type: String,
required: false, required: false,
default: 'start_end' default: 'start_end'

@ -1 +1 @@
Subproject commit cd9661448f09f70f59c73bf513dd7052f1e147fc Subproject commit 2904be08e6326c25e7a1901f8bf7470ae2faf76b