From e1e909192f2cd0061ee9249f8f452fab7a40fc72 Mon Sep 17 00:00:00 2001 From: karthikeyareddy183 Date: Fri, 5 Sep 2025 17:19:24 +0530 Subject: [PATCH] fixed timezone bug and openai expectation --- main/xiaozhi-server/core/connection.py | 54 ++++--------------- .../core/providers/llm/openai/openai.py | 10 ++-- .../core/providers/vad/silero_onnx.py | 4 +- 3 files changed, 16 insertions(+), 52 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index e7f572667..b956974b4 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -662,28 +662,11 @@ # # Use mem_local_short mode # elif memory_type == "mem_local_short": # self.logger.bind(tag=TAG).info("Memory module initialized: LOCAL STORAGE (mem_local_short)") -# memory_llm_name = memory_config[self.config["selected_module"]["Memory"]][ -# "llm" -# ] -# if memory_llm_name and memory_llm_name in self.config["LLM"]: -# # If a dedicated LLM is configured, create an independent LLM instance -# from core.utils import llm as llm_utils - -# memory_llm_config = self.config["LLM"][memory_llm_name] -# memory_llm_type = memory_llm_config.get( -# "type", memory_llm_name) -# memory_llm = llm_utils.create_instance( -# memory_llm_type, memory_llm_config -# ) -# self.logger.bind(tag=TAG).info( -# f"Created a dedicated LLM for memory summary: {memory_llm_name}, type: {memory_llm_type}" -# ) -# self.memory.set_llm(memory_llm) -# else: -# # Otherwise use main LLM -# self.memory.set_llm(self.llm) -# self.logger.bind(tag=TAG).info( -# "Using main LLM as memory model") +# # ALWAYS use the main LLM for memory operations +# # This ensures consistency and avoids configuration issues +# self.memory.set_llm(self.llm) +# self.logger.bind(tag=TAG).info( +# f"Using main LLM ({self.config['selected_module']['LLM']}) for memory operations") # elif memory_type == "mem0ai": # self.logger.bind(tag=TAG).info("Memory module initialized: MEM0 CLOUD (mem0ai)") # else: @@ -1884,28 +1867,11 @@ class ConnectionHandler: # Use mem_local_short mode elif memory_type == "mem_local_short": self.logger.bind(tag=TAG).info("Memory module initialized: LOCAL STORAGE (mem_local_short)") - memory_llm_name = memory_config[self.config["selected_module"]["Memory"]][ - "llm" - ] - if memory_llm_name and memory_llm_name in self.config["LLM"]: - # If a dedicated LLM is configured, create an independent LLM instance - from core.utils import llm as llm_utils - - memory_llm_config = self.config["LLM"][memory_llm_name] - memory_llm_type = memory_llm_config.get( - "type", memory_llm_name) - memory_llm = llm_utils.create_instance( - memory_llm_type, memory_llm_config - ) - self.logger.bind(tag=TAG).info( - f"Created a dedicated LLM for memory summary: {memory_llm_name}, type: {memory_llm_type}" - ) - self.memory.set_llm(memory_llm) - else: - # Otherwise use main LLM - self.memory.set_llm(self.llm) - self.logger.bind(tag=TAG).info( - "Using main LLM as memory model") + # ALWAYS use the main LLM for memory operations + # This ensures consistency and avoids configuration issues + self.memory.set_llm(self.llm) + self.logger.bind(tag=TAG).info( + f"Using main LLM ({self.config['selected_module']['LLM']}) for memory operations") elif memory_type == "mem0ai": self.logger.bind(tag=TAG).info("Memory module initialized: MEM0 CLOUD (mem0ai)") else: diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index 1f31082cb..381cae06a 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -96,9 +96,8 @@ class LLMProvider(LLMProviderBase): except Exception as e: logger.bind(tag=TAG).error(f"Error in response generation: {e}") - # Ensure the error message is properly encoded - error_msg = str(e).encode('utf-8', errors='ignore').decode('utf-8') - yield f"[OpenAI Service Response Exception: {error_msg}]" + # Send user-friendly message instead of technical error details + yield "Server is busy! Will get back soon." def response_with_functions(self, session_id, dialogue, functions=None): @@ -126,6 +125,5 @@ class LLMProvider(LLMProviderBase): except Exception as e: logger.bind(tag=TAG).error(f"Error in function call streaming: {e}") - # Ensure the error message is properly encoded - error_msg = str(e).encode('utf-8', errors='ignore').decode('utf-8') - yield f"[OpenAI Service Response Exception: {error_msg}]", None \ No newline at end of file + # Send user-friendly message instead of technical error details + yield "Server is busy! Will get back soon.", None \ No newline at end of file diff --git a/main/xiaozhi-server/core/providers/vad/silero_onnx.py b/main/xiaozhi-server/core/providers/vad/silero_onnx.py index aa608a5bd..ca7ae3052 100644 --- a/main/xiaozhi-server/core/providers/vad/silero_onnx.py +++ b/main/xiaozhi-server/core/providers/vad/silero_onnx.py @@ -201,7 +201,7 @@ class SileroVADAnalyzer(VADAnalyzer): if self._confidence_log_counter % 100 == 0: # Log every 100th frame (reduced from 10) audio_rms = float(np.sqrt(np.mean(audio_float32 ** 2))) - confidence_val = float(new_confidence) + confidence_val = float(new_confidence.item()) # Use .item() to extract scalar from numpy array logger.debug(f"VAD confidence: {confidence_val:.3f}, RMS: {audio_rms:.4f}") # Reset model periodically to prevent memory growth @@ -211,7 +211,7 @@ class SileroVADAnalyzer(VADAnalyzer): self._model.reset_states() self._last_reset_time = curr_time - return float(new_confidence) + return float(new_confidence.item()) # Use .item() to extract scalar from numpy array except Exception as e: logger.error(f"Error analyzing audio with Silero ONNX VAD: {e}") return 0.0