This commit is contained in:
saloui 2023-05-26 14:01:21 +02:00
parent af64396178
commit 179c79adb0
2 changed files with 14 additions and 12 deletions

View File

@ -248,10 +248,7 @@ class ModelProcess:
self._set_config_result['binding_status'] ='failed' self._set_config_result['binding_status'] ='failed'
self._set_config_result['errors'].append(f"couldn't build binding:{ex}") self._set_config_result['errors'].append(f"couldn't build binding:{ex}")
def step_callback(self, text, message_type):
self.generation_queue.put((text,self.id, message_type))
def _run(self): def _run(self):
self._rebuild_model() self._rebuild_model()
self._rebuild_personality() self._rebuild_personality()
@ -286,8 +283,8 @@ class ModelProcess:
if "custom_workflow" in self.personality.processor_cfg: if "custom_workflow" in self.personality.processor_cfg:
if self.personality.processor_cfg["custom_workflow"]: if self.personality.processor_cfg["custom_workflow"]:
print("Running workflow") print("Running workflow")
output = self.personality.processor.run_workflow(self._generate, command[1], command[0], self.step_callback) output = self.personality.processor.run_workflow(self._generate, command[1], command[0], self._callback)
self._callback(output) self._callback(output, 0)
self.is_generating.value = 0 self.is_generating.value = 0
continue continue
@ -338,13 +335,13 @@ class ModelProcess:
output = "" output = ""
return output return output
def _callback(self, text): def _callback(self, text, text_type=0):
if not self.ready: if not self.ready:
print(".",end="", flush=True) print(".",end="", flush=True)
return True return True
else: else:
# Stream the generated text to the main process # Stream the generated text to the main process
self.generation_queue.put((text,self.id, 0)) self.generation_queue.put((text,self.id, text_type))
self._check_set_config_queue() self._check_set_config_queue()
self._check_cancel_queue() self._check_cancel_queue()
self._check_clear_queue() self._check_clear_queue()
@ -702,7 +699,8 @@ class GPT4AllAPI():
self.bot_says = self.remove_text_from_string(self.bot_says, self.personality.user_message_prefix.strip()) self.bot_says = self.remove_text_from_string(self.bot_says, self.personality.user_message_prefix.strip())
self.process.cancel_generation() self.process.cancel_generation()
print("The model is halucinating") print("The model is halucinating")
self.current_discussion.update_message(self.current_ai_message_id, self.bot_says)
def start_message_generation(self, message, message_id): def start_message_generation(self, message, message_id):
bot_says = "" bot_says = ""
@ -732,9 +730,12 @@ class GPT4AllAPI():
self.process.generate(self.discussion_messages, self.current_message, message_id, n_predict = self.config['n_predict']) self.process.generate(self.discussion_messages, self.current_message, message_id, n_predict = self.config['n_predict'])
self.process.started_queue.get() self.process.started_queue.get()
while(self.process.is_generating.value): # Simulating other commands being issued while(self.process.is_generating.value): # Simulating other commands being issued
chunk, tok, message_type = self.process.generation_queue.get() try:
if chunk!="": chunk, tok, message_type = self.process.generation_queue.get(False, 2)
self.process_chunk(chunk, message_type) if chunk!="":
self.process_chunk(chunk, message_type)
except:
time.sleep(1)
print() print()
print("## Done ##") print("## Done ##")

View File

@ -20,6 +20,7 @@ __license__ = "Apache 2.0"
class LLMBinding: class LLMBinding:
file_extension='*.bin' file_extension='*.bin'
binding_path = Path(__file__).parent binding_path = Path(__file__).parent
def __init__(self, config:dict, inline:bool) -> None: def __init__(self, config:dict, inline:bool) -> None: