Added better instructions

This commit is contained in:
2025-06-03 17:32:19 -05:00
parent c40e700184
commit 67f83fd3c7
4 changed files with 42 additions and 49 deletions
+15 -36
View File
@@ -3,30 +3,8 @@ import socketserver
import os
import logging
import asyncio
# Assuming InferenceBot is available in the same environment or can be imported
# For demonstration, we'll use a placeholder if not explicitly provided.
try:
from inference_bot import InferenceBot
except ImportError:
logging.warning("InferenceBot not found. Using a placeholder for APIHelper.")
class InferenceBot:
def __init__(self):
self.history = {}
self.status_message = "Bot is operational."
self.processing_status = {}
async def start(self): return "Placeholder Bot started."
def clear_conversation_history(self, user_id): self.history[user_id] = []
def get_bot_status(self): return self.status_message
async def switch_model(self): return "Placeholder model switched."
async def handle_message(self, user_id, message):
self.history.setdefault(user_id, []).append(f"User: {message}")
response = f"Placeholder Bot received: {message}"
self.history[user_id].append(f"Bot: {response}")
return response
async def abort_processing(self, user_id): return "Placeholder processing aborted."
def set_processing_status(self, user_id, message_id): self.processing_status[user_id] = message_id
def clear_processing_status(self, user_id): self.processing_status.pop(user_id, None)
from inference_bot import InferenceBot
import time
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -65,6 +43,10 @@ class APIHelper:
except Exception as e:
logging.error(f"Error in _handle_message_logic for user {user_id}: {str(e)}")
return f"Error processing message: {str(e)}"
def run(self):
run_server(self.bot)
logging.info("APIHelper is running. Ready to handle requests.")
class CopilotRequestHandler(http.server.BaseHTTPRequestHandler):
@@ -131,19 +113,16 @@ def run_server(bot_instance: InferenceBot, server_class=http.server.HTTPServer,
# Attach the APIHelper instance to the handler class
handler_class.api_helper_instance = api_helper
server_address = (host, port)
httpd = server_class(server_address, handler_class)
logging.info(f"Starting Copilot API helper on http://{host}:{port}{COPILOT_PATH}")
logging.info(f"Health check available at http://{host}:{port}/health")
try:
server_address = (host, port)
httpd = server_class(server_address, handler_class)
logging.info(f"Starting Copilot API helper on http://{host}:{port}{COPILOT_PATH}")
logging.info(f"Health check available at http://{host}:{port}/health")
except Exception as e:
logging.error(f"Error during server setup: {e}")
return # Exit if server setup fails
try:
httpd.serve_forever()
except KeyboardInterrupt:
logging.info("Server shutting down...")
httpd.server_close()
if __name__ == '__main__':
# In a real deployment, you would pass a properly configured InferenceBot instance here.
# For standalone execution, we instantiate the placeholder InferenceBot.
logging.warning("Running api_helper.py in standalone mode with a placeholder InferenceBot.")
logging.warning("Ensure a proper InferenceBot instance is passed when integrating into a larger system.")
run_server(bot_instance=InferenceBot())
httpd.server_close()