Skip to content
Snippets Groups Projects
Commit 541e88f9 authored by mhby1g21's avatar mhby1g21
Browse files

fixed cloud api and added home button to all pages, but need to fix response...

fixed cloud api and added home button to all pages, but need to fix response flow and background task etc for cloud
parent ba731dc8
Branches
No related tags found
No related merge requests found
...@@ -15,8 +15,7 @@ from response_manager import ResponseManager ...@@ -15,8 +15,7 @@ from response_manager import ResponseManager
from sentiment_analyzer import FastSentimentAnalyzer from sentiment_analyzer import FastSentimentAnalyzer
from background_tasks import BackgroundTaskManager from background_tasks import BackgroundTaskManager
from stt_tts import record_audio, speak_text, initialize_audio_logging from stt_tts import record_audio, speak_text, initialize_audio_logging
import config_manager from config_manager import config_manager
# Initialize components # Initialize components
print("Initializing LLM handler...") print("Initializing LLM handler...")
llm = LLMHandler(model_name="gemma3:1b") llm = LLMHandler(model_name="gemma3:1b")
...@@ -62,7 +61,7 @@ background_manager = BackgroundTaskManager(llm, response_manager) ...@@ -62,7 +61,7 @@ background_manager = BackgroundTaskManager(llm, response_manager)
# the version would be main.0.08 (first 0) is for every hundreds # the version would be main.0.08 (first 0) is for every hundreds
# commits which should technically have lots of changes # commits which should technically have lots of changes
# use 'git rev-list --count HEAD' to get commit number # use 'git rev-list --count HEAD' to get commit number
version = "ui_updates.1.119." version = "ui_updates.1.120."
class SimpleHardwareSimulator: class SimpleHardwareSimulator:
"""Simple hardware state simulator for UI display""" """Simple hardware state simulator for UI display"""
......
...@@ -302,12 +302,40 @@ Only include this field when the user explicitly requests movement.""" ...@@ -302,12 +302,40 @@ Only include this field when the user explicitly requests movement."""
"max_tokens": 1024 "max_tokens": 1024
} }
# Send request to cloud API # Send request to cloud API with increased timeout
response = requests.post(self.cloud_api_url, json=payload, headers=headers, timeout=15) response = requests.post(
self.cloud_api_url,
json=payload,
headers=headers,
timeout=30 # Increased timeout to 30 seconds
)
response.raise_for_status() response.raise_for_status()
# Extract response content # Print API response for debugging
cloud_response_text = response.json()['choices'][0]['message']['content'] print(f"Cloud API Response: {response.status_code}")
# Parse the JSON response
response_data = response.json()
# Extract the message content - Fix for DeepSeek API response format
if 'choices' in response_data and len(response_data['choices']) > 0:
# Get the actual message content
message = response_data['choices'][0].get('message', {})
# For DeepSeek API, the message content is in the 'content' field
cloud_response_text = message.get('content', '')
if not cloud_response_text:
# Try alternative formats
if 'text' in message:
cloud_response_text = message['text']
elif 'content' in response_data:
cloud_response_text = response_data['content']
else:
raise ValueError("Could not extract response content from API response")
print(f"Extracted message: {cloud_response_text[:100]}...")
else:
raise ValueError("No choices in API response")
# Parse JSON response # Parse JSON response
try: try:
...@@ -357,6 +385,7 @@ Only include this field when the user explicitly requests movement.""" ...@@ -357,6 +385,7 @@ Only include this field when the user explicitly requests movement."""
return response_data return response_data
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
print(f"Cloud API timeout after {30} seconds")
return { return {
"response": "I'm having trouble connecting to my cloud brain. It seems to be taking too long to respond.", "response": "I'm having trouble connecting to my cloud brain. It seems to be taking too long to respond.",
"chain_of_thought": "Cloud API timeout occurred", "chain_of_thought": "Cloud API timeout occurred",
...@@ -366,6 +395,7 @@ Only include this field when the user explicitly requests movement.""" ...@@ -366,6 +395,7 @@ Only include this field when the user explicitly requests movement."""
"type": "error" "type": "error"
} }
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print(f"Cloud API request error: {e}")
return { return {
"response": f"I'm having trouble connecting to my cloud brain. There seems to be a network issue.", "response": f"I'm having trouble connecting to my cloud brain. There seems to be a network issue.",
"chain_of_thought": f"Cloud API error: {str(e)}", "chain_of_thought": f"Cloud API error: {str(e)}",
......
...@@ -336,3 +336,8 @@ ...@@ -336,3 +336,8 @@
padding: 10px 0; padding: 10px 0;
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
} }
.nav-buttons {
display: flex;
gap: 10px;
}
\ No newline at end of file
...@@ -209,3 +209,12 @@ ...@@ -209,3 +209,12 @@
right: 10px; right: 10px;
z-index: 100; z-index: 100;
} }
.nav-buttons {
position: absolute;
top: 10px;
left: 10px;
display: flex;
gap: 10px;
z-index: 10;
}
\ No newline at end of file
...@@ -102,6 +102,14 @@ class DeveloperModeController extends UIController { ...@@ -102,6 +102,14 @@ class DeveloperModeController extends UIController {
}); });
} }
// Home Button
const homeButton = document.getElementById('home-button');
if (homeButton) {
homeButton.addEventListener('click', () => {
window.location.href = '/';
});
}
// Buttons // Buttons
const sendButton = document.getElementById('send-button'); const sendButton = document.getElementById('send-button');
if (sendButton) { if (sendButton) {
......
...@@ -53,6 +53,14 @@ class RobotModeController extends UIController { ...@@ -53,6 +53,14 @@ class RobotModeController extends UIController {
this.switchMode('developer'); this.switchMode('developer');
}); });
} }
// Home button handler
const homeButton = document.getElementById('home-button');
if (homeButton) {
homeButton.addEventListener('click', () => {
window.location.href = '/';
});
}
} }
/** /**
......
...@@ -13,8 +13,11 @@ ...@@ -13,8 +13,11 @@
<div class="dev-header"> <div class="dev-header">
<div class="dev-title">Robot Developer Interface</div> <div class="dev-title">Robot Developer Interface</div>
<div id="cloud-toggle-container"></div> <div id="cloud-toggle-container"></div>
<div class="nav-buttons">
<button id="home-button" class="mode-switch">Home</button>
<button id="mode-switch" class="mode-switch">Robot Mode</button> <button id="mode-switch" class="mode-switch">Robot Mode</button>
</div> </div>
</div>
<div class="dev-robot-display"> <div class="dev-robot-display">
<h3>Robot State</h3> <h3>Robot State</h3>
......
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
</head> </head>
<body class="robot-mode"> <body class="robot-mode">
<div class="robot-face-container"> <div class="robot-face-container">
<button id="mode-switch" class="mode-switch">Developer Mode</button> <div class="nav-buttons">
<button id="home-button" class="mode-switch">Home</button>
<!-- <button id="mode-switch" class="mode-switch">Developer Mode</button> -->
</div>
<div class="status-indicator listening">👂</div> <div class="status-indicator listening">👂</div>
<div class="status-indicator thinking">🤔</div> <div class="status-indicator thinking">🤔</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment