MCPcopy
hub / github.com/dnhkng/GLaDOS / process_LLM

Method process_LLM

glados.py:455–516  ·  view source on GitHub ↗

Processes the detected text using the LLM model.

(self)

Source from the content-addressed store, hash-verified

453 return interrupted, percentage_played
454
455 def process_LLM(self):
456 """
457 Processes the detected text using the LLM model.
458
459 """
460 while not self.shutdown_event.is_set():
461 try:
462 detected_text = self.llm_queue.get(timeout=0.1)
463
464 self.messages.append({"role": "user", "content": detected_text})
465
466 prompt = self.template.render(
467 messages=self.messages,
468 bos_token="<|begin_of_text|>",
469 add_generation_prompt=True,
470 )
471
472 logger.debug(f"{prompt=}")
473
474 data = {
475 "stream": True,
476 "prompt": prompt,
477 }
478 logger.debug(f"starting request on {self.messages=}")
479 logger.debug("Performing request to LLM server...")
480
481 # Perform the request and process the stream
482
483 with requests.post(
484 self.completion_url,
485 headers=self.prompt_headers,
486 json=data,
487 stream=True,
488 ) as response:
489 sentence = []
490 for line in response.iter_lines():
491 if self.processing is False:
492 break # If the stop flag is set from new voice input, halt processing
493 if line: # Filter out empty keep-alive new lines
494 line = self._clean_raw_bytes(line)
495 next_token = self._process_line(line)
496 if next_token:
497 sentence.append(next_token)
498 # If there is a pause token, send the sentence to the TTS queue
499 if next_token in [
500 ".",
501 "!",
502 "?",
503 ":",
504 ";",
505 "?!",
506 "\n",
507 "\n\n",
508 ]:
509 self._process_sentence(sentence)
510 sentence = []
511 if self.processing:
512 if sentence:

Callers

nothing calls this directly

Calls 4

_clean_raw_bytesMethod · 0.95
_process_lineMethod · 0.95
_process_sentenceMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected