diff --git a/lollms_core b/lollms_core index 0337e8a3..62677f4e 160000 --- a/lollms_core +++ b/lollms_core @@ -1 +1 @@ -Subproject commit 0337e8a38bbbfe12d34a7eea304710b355826f3c +Subproject commit 62677f4ee5e6c01ab83a25abf9e90182acd48487 diff --git a/lollms_webui.py b/lollms_webui.py index 1cac8c1c..53ee34cc 100644 --- a/lollms_webui.py +++ b/lollms_webui.py @@ -759,7 +759,7 @@ class LOLLMSWebUI(LOLLMSElfServer): 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) 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") @@ -874,7 +874,7 @@ class LOLLMSWebUI(LOLLMSElfServer): # Raise an error if the available space is 0 or less 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!!") # Accumulate messages until the cumulative number of tokens exceeds available_space @@ -1381,114 +1381,119 @@ class LOLLMSWebUI(LOLLMSElfServer): # send the message to the bot print(f"Received message : {message.content}") 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: - self.generate( - self.discussion_messages, - self.current_message, - context_details=context_details, - n_predict = self.config.ctx_size-len(tokens)-1, - client_id=client_id, - callback=partial(self.process_chunk,client_id = client_id) - ) - if self.config.enable_voice_service and self.config.auto_read and len(self.personality.audio_samples)>0: - try: - 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.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices", xtts_base_url= self.config.xtts_base_url) - language = convert_language_name(self.personality.language) - self.tts.set_speaker_folder(Path(self.personality.audio_samples[0]).parent) - fn = self.personality.name.lower().replace(' ',"_").replace('.','') - fn = f"{fn}_{message_id}.wav" - url = f"audio/{fn}" - self.tts.tts_to_file(self.connections[client_id]["generated_text"], Path(self.personality.audio_samples[0]).name, f"{fn}", language=language) - fl = f""" - -""" - 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) - - """ - self.info("Creating audio output",10) - self.personality.step_start("Creating audio output") - if not PackageManager.check_package_installed("tortoise"): - PackageManager.install_package("tortoise-tts") - from tortoise import utils, api - import sounddevice as sd - if self.tts is None: - self.tts = api.TextToSpeech( kv_cache=True, half=True) - 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 + 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: + self.generate( + self.discussion_messages, + self.current_message, + context_details=context_details, + n_predict = self.config.ctx_size-len(tokens)-1, + client_id=client_id, + callback=partial(self.process_chunk,client_id = client_id) + ) + if self.config.enable_voice_service and self.config.auto_read and len(self.personality.audio_samples)>0: + try: + 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.tts = LollmsXTTS(self, voice_samples_path=Path(__file__).parent.parent/"voices", xtts_base_url= self.config.xtts_base_url) + language = convert_language_name(self.personality.language) + self.tts.set_speaker_folder(Path(self.personality.audio_samples[0]).parent) + fn = self.personality.name.lower().replace(' ',"_").replace('.','') + fn = f"{fn}_{message_id}.wav" + url = f"audio/{fn}" + self.tts.tts_to_file(self.connections[client_id]["generated_text"], Path(self.personality.audio_samples[0]).name, f"{fn}", language=language) + fl = f"\n".join([ + f"' + ]) + 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]) - 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") - """ + """ + self.info("Creating audio output",10) + self.personality.step_start("Creating audio output") + if not PackageManager.check_package_installed("tortoise"): + PackageManager.install_package("tortoise-tts") + from tortoise import utils, api + import sounddevice as sd + if self.tts is None: + self.tts = api.TextToSpeech( kv_cache=True, half=True) + 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: - ASCIIColors.error("Couldn't read") - trace_exception(ex) - print() - ASCIIColors.success("## Done Generation ##") - print() - except Exception as ex: - trace_exception(ex) - print() - ASCIIColors.error("## Generation Error ##") - print() + except Exception as ex: + ASCIIColors.error("Couldn't read") + trace_exception(ex) + print() + ASCIIColors.success("## Done Generation ##") + print() + except Exception as ex: + trace_exception(ex) + print() + ASCIIColors.error("## Generation Error ##") + print() - self.cancel_gen = False + self.cancel_gen = False - # Send final message - if self.config.activate_internet_search: - from lollms.internet import get_favicon_url, get_root_url - sources_text = '
"+eo(n[e].content)+`
`};es.fence=function(n,e,t,i,s){var r=n[e],o=r.info?Afe(r.info).trim():"",a="",l="",c,d,_,h,m;return o&&(_=o.split(/(\s+)/g),a=_[0],l=_.slice(2).join("")),t.highlight?c=t.highlight(r.content,a,l)||eo(r.content):c=eo(r.content),c.indexOf(""+c+`
@@ -30,7 +30,7 @@
`:">",r)};Fa.prototype.renderInline=function(n,e,t){for(var i,s="",r=this.rules,o=0,a=n.length;o\s]/i.test(n)}function Pfe(n){return/^<\/a\s*>/i.test(n)}var Ufe=function(e){var t,i,s,r,o,a,l,c,d,_,h,m,f,E,b,g,v=e.tokens,y;if(e.md.options.linkify){for(i=0,s=v.length;i=P,E.push(e.bsCount[h]),e.bsCount[h]=e.sCount[h]+1+(T?1:0),v.push(e.sCount[h]),e.sCount[h]=m-l,y.push(e.tShift[h]),e.tShift[h]=A-e.bMarks[h];continue}if(d)break;for(C=!1,a=0,c=x.length;a =P,E.push(e.bsCount[h]),e.bsCount[h]=e.sCount[h]+1+(T?1:0),v.push(e.sCount[h]),e.sCount[h]=m-l,y.push(e.tShift[h]),e.tShift[h]=A-e.bMarks[h];continue}if(d)break;for(C=!1,a=0,c=x.length;a?@[]^_`{|}~-".split("").forEach(function(n){zb[n.charCodeAt(0)]=1});var Bme=function(e,t){var i,s,r,o,a,l=e.pos,c=e.posMax;if(e.src.charCodeAt(l)!==92||(l++,l>=c))return!1;if(i=e.src.charCodeAt(l),i===10){for(t||e.push("hardbreak","br",0),l++;l=0;t--)i=e[t],!(i.marker!==95&&i.marker!==42)&&i.end!==-1&&(s=e[i.end],a=t>0&&e[t-1].end===i.end+1&&e[t-1].marker===i.marker&&e[t-1].token===i.token-1&&e[i.end+1].token===s.token+1,o=String.fromCharCode(i.marker),r=n.tokens[i.token],r.type=a?"strong_open":"em_open",r.tag=a?"strong":"em",r.nesting=1,r.markup=a?o+o:o,r.content="",r=n.tokens[s.token],r.type=a?"strong_close":"em_close",r.tag=a?"strong":"em",r.nesting=-1,r.markup=a?o+o:o,r.content="",a&&(n.tokens[e[t-1].token].content="",n.tokens[e[i.end+1].token].content="",t--))}Yu.postProcess=function(e){var t,i=e.tokens_meta,s=e.tokens_meta.length;for(GS(e,e.delimiters),t=0;t=E)return!1;if(b=l,c=e.md.helpers.parseLinkDestination(e.src,l,e.posMax),c.ok){for(h=e.md.normalizeLink(c.str),e.md.validateLink(h)?l=c.pos:h="",b=l;l0&&s++,r[t].type==="text"&&t+1?@[]^_`{|}~-".split("").forEach(function(n){zb[n.charCodeAt(0)]=1});var Bme=function(e,t){var i,s,r,o,a,l=e.pos,c=e.posMax;if(e.src.charCodeAt(l)!==92||(l++,l>=c))return!1;if(i=e.src.charCodeAt(l),i===10){for(t||e.push("hardbreak","br",0),l++;l=0;t--)i=e[t],!(i.marker!==95&&i.marker!==42)&&i.end!==-1&&(s=e[i.end],a=t>0&&e[t-1].end===i.end+1&&e[t-1].marker===i.marker&&e[t-1].token===i.token-1&&e[i.end+1].token===s.token+1,o=String.fromCharCode(i.marker),r=n.tokens[i.token],r.type=a?"strong_open":"em_open",r.tag=a?"strong":"em",r.nesting=1,r.markup=a?o+o:o,r.content="",r=n.tokens[s.token],r.type=a?"strong_close":"em_close",r.tag=a?"strong":"em",r.nesting=-1,r.markup=a?o+o:o,r.content="",a&&(n.tokens[e[t-1].token].content="",n.tokens[e[i.end+1].token].content="",t--))}Yu.postProcess=function(e){var t,i=e.tokens_meta,s=e.tokens_meta.length;for(GS(e,e.delimiters),t=0;t=E)return!1;if(b=l,c=e.md.helpers.parseLinkDestination(e.src,l,e.posMax),c.ok){for(h=e.md.normalizeLink(c.str),e.md.validateLink(h)?l=c.pos:h="",b=l;l0&&s++,r[t].type==="text"&&t+1