mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
changed provider pare , add model and dialogue box to englih
This commit is contained in:
parent
eb4b6bfecc
commit
c5aff8874b
4 changed files with 33 additions and 8 deletions
|
|
@ -19,9 +19,9 @@ import opuslib
|
||||||
|
|
||||||
# --- Configuration ---
|
# --- Configuration ---
|
||||||
|
|
||||||
SERVER_IP = "192.168.1.105" # !!! UPDATE with your server's local IP address !!!
|
SERVER_IP = "192.168.1.4" # !!! UPDATE with your server's local IP address !!!
|
||||||
OTA_PORT = 8003
|
OTA_PORT = 8003
|
||||||
MQTT_BROKER_HOST = "192.168.1.105" # MQTT gateway IP
|
MQTT_BROKER_HOST = "192.168.1.4" # MQTT gateway IP
|
||||||
|
|
||||||
|
|
||||||
MQTT_BROKER_PORT = 1883
|
MQTT_BROKER_PORT = 1883
|
||||||
|
|
@ -87,7 +87,7 @@ class TestClient:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mqtt_client = None
|
self.mqtt_client = None
|
||||||
# Generate a unique MAC address for this client instance
|
# Generate a unique MAC address for this client instance
|
||||||
self.device_mac_formatted = generate_unique_mac()
|
self.device_mac_formatted = "00:16:3e:ac:b5:38"
|
||||||
print(f"Generated unique MAC address: {self.device_mac_formatted}")
|
print(f"Generated unique MAC address: {self.device_mac_formatted}")
|
||||||
|
|
||||||
# MQTT credentials will be set from OTA response
|
# MQTT credentials will be set from OTA response
|
||||||
|
|
|
||||||
|
|
@ -46,18 +46,26 @@ def get_config_from_api(config):
|
||||||
"""Get configuration from Java API"""
|
"""Get configuration from Java API"""
|
||||||
# Initialize API client
|
# Initialize API client
|
||||||
init_service(config)
|
init_service(config)
|
||||||
|
|
||||||
# Get server configuration
|
# Get server configuration
|
||||||
config_data = get_server_config()
|
config_data = get_server_config()
|
||||||
if config_data is None:
|
if config_data is None:
|
||||||
raise Exception("Failed to fetch server config from API")
|
raise Exception("Failed to fetch server config from API")
|
||||||
|
|
||||||
|
# Print the configuration received from API
|
||||||
|
print("=" * 80)
|
||||||
|
print("CONFIGURATION RECEIVED FROM API:")
|
||||||
|
print("=" * 80)
|
||||||
|
import json
|
||||||
|
print(json.dumps(config_data, indent=2, ensure_ascii=False))
|
||||||
|
print("=" * 80)
|
||||||
|
|
||||||
config_data["read_config_from_api"] = True
|
config_data["read_config_from_api"] = True
|
||||||
config_data["manager-api"] = {
|
config_data["manager-api"] = {
|
||||||
"url": config["manager-api"].get("url", ""),
|
"url": config["manager-api"].get("url", ""),
|
||||||
"secret": config["manager-api"].get("secret", ""),
|
"secret": config["manager-api"].get("secret", ""),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use local server configuration as priority
|
# Use local server configuration as priority
|
||||||
if config.get("server"):
|
if config.get("server"):
|
||||||
config_data["server"] = {
|
config_data["server"] = {
|
||||||
|
|
@ -67,7 +75,12 @@ def get_config_from_api(config):
|
||||||
"vision_explain": config["server"].get("vision_explain", ""),
|
"vision_explain": config["server"].get("vision_explain", ""),
|
||||||
"auth_key": config["server"].get("auth_key", ""),
|
"auth_key": config["server"].get("auth_key", ""),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("FINAL MERGED CONFIGURATION:")
|
||||||
|
print("=" * 80)
|
||||||
|
print(json.dumps(config_data, indent=2, ensure_ascii=False))
|
||||||
|
print("=" * 80)
|
||||||
|
|
||||||
return config_data
|
return config_data
|
||||||
|
|
||||||
def get_private_config_from_api(config, device_id, client_id):
|
def get_private_config_from_api(config, device_id, client_id):
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,13 @@ def setup_logging():
|
||||||
log_format_file = log_format_file.replace("{version}", SERVER_VERSION)
|
log_format_file = log_format_file.replace("{version}", SERVER_VERSION)
|
||||||
|
|
||||||
log_level = log_config.get("log_level", "INFO")
|
log_level = log_config.get("log_level", "INFO")
|
||||||
|
|
||||||
|
# Validate log level - if it's not a valid log level, default to INFO
|
||||||
|
valid_log_levels = ["TRACE", "DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"]
|
||||||
|
if log_level not in valid_log_levels:
|
||||||
|
logger.warning(f"Invalid log level '{log_level}' found in config, defaulting to INFO")
|
||||||
|
log_level = "INFO"
|
||||||
|
|
||||||
log_dir = log_config.get("log_dir", "tmp")
|
log_dir = log_config.get("log_dir", "tmp")
|
||||||
log_file = log_config.get("log_file", "server.log")
|
log_file = log_config.get("log_file", "server.log")
|
||||||
data_dir = log_config.get("data_dir", "data")
|
data_dir = log_config.get("data_dir", "data")
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,9 @@ class LLMProvider(LLMProviderBase):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"Error in response generation: {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}]"
|
||||||
|
|
||||||
|
|
||||||
def response_with_functions(self, session_id, dialogue, functions=None):
|
def response_with_functions(self, session_id, dialogue, functions=None):
|
||||||
|
|
@ -123,4 +126,6 @@ class LLMProvider(LLMProviderBase):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"Error in function call streaming: {e}")
|
logger.bind(tag=TAG).error(f"Error in function call streaming: {e}")
|
||||||
yield f"[OpenAI Service Response Exception: {e}]", None
|
# 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
|
||||||
Loading…
Reference in a new issue