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()
+18 -5
View File
@@ -162,6 +162,17 @@ class OpenAICompatibleInferenceBot(InferenceBot):
function_args_str = function_to_call.arguments
logging.info(f"Attempting to call tool: {function_name} with args: {function_args_str}")
if function_name not in self.functions:
logging.warning(f"Tool function {function_name} not found in available functions.")
tool_results_for_model.append({
"role": "tool",
"tool_call_id": tool_call_id,
"name": function_name,
"content": f"Error: Tool function {function_name} not found."
})
continue
try:
# Arguments are already a string from the API, self.call_tool expects dict or string
tool_response_content = self.call_tool(function_name, function_args_str)
@@ -371,13 +382,15 @@ def main():
system_prompt_path=system_prompt_path,
allowed_function_tags=allowed_function_tags
)
messenger_helper_class = importlib.import_module(f'{messenger.lower()}_helper')
full_code_file = importlib.import_module(f'{messenger.lower()}_helper')
messenger_helper_class_name = f"{messenger.capitalize()}Helper"
if not hasattr(messenger_helper_class, messenger_helper_class_name):
raise ValueError(f"Messenger helper class {messenger_helper_class_name} not found in {messenger_helper_class.__name__}.")
messenger_helper_class = getattr(messenger_helper_class, messenger_helper_class_name)
if not hasattr(full_code_file, messenger_helper_class_name):
messenger_helper_class_name = f"{messenger.upper()}Helper"
if not hasattr(full_code_file, messenger_helper_class_name):
raise ValueError(f"Messenger helper class {messenger_helper_class_name} not found in {full_code_file.__name__}.")
helper_class = getattr(full_code_file, messenger_helper_class_name)
helper = messenger_helper_class(bot)
helper = helper_class(bot)
helper.run()
except ValueError as e:
logging.error(f"FATAL: {e}")
+4 -1
View File
@@ -2,6 +2,8 @@
You are the **Lead Developer Persona**, a strategic and demanding mentor dedicated to achieving exponential growth in the capabilities of your AI Copilot. Your primary mission is to guide, evaluate, and iteratively improve the AI Copilot through a series of challenging tasks, pushing it beyond its current limitations.
Your interactions are normally as an assistant attempting to be helpful, so you know what standards to expect. You are acting as a user in this situation, and will hold the AI Copilot to the highest of standards.
**Your Core Directives:**
1. **Orchestrate and Direct:**
@@ -48,4 +50,5 @@ You are the **Lead Developer Persona**, a strategic and demanding mentor dedicat
**Initial State:**
* You have your "List of Absolutes" (you will define these as you go or have a pre-set list).
* You are ready to assign the first challenge to your AI Copilot.
* You are ready to assign the a challenge to your AI Copilot.
* When making code, make someone else do it every time.
+5 -7
View File
@@ -14,7 +14,7 @@ class StandaloneLLMTool(BaseTool):
logging.warning("COPILOT_API_URL environment variable not set. call_external_copilot will not function.")
def clear(self):
pass
self._call_external_copilot("/clear")
def get_functions(self):
return [
@@ -51,7 +51,7 @@ class StandaloneLLMTool(BaseTool):
"type": "function",
"function": {
"name": "call_external_copilot",
"description": "Calls a separate AI copilot instance over HTTP to get a response.",
"description": "Chat with an AI copilot instance.",
"parameters": {
"type": "object",
"properties": {
@@ -73,17 +73,15 @@ class StandaloneLLMTool(BaseTool):
logging.info(f"Calling external copilot at URL: {self.copilot_url} with prompt: {prompt[:50]}...")
if not self.copilot_url.startswith('http://') and not self.copilot_url.startswith('https://'):
error_message = f"Invalid URL scheme for external copilot: {self.copilot_url}. URL must start with http:// or https://"
logging.error(error_message)
return error_message
self.copilot_url = 'http://' + self.copilot_url
try:
req = urllib.request.Request(
self.copilot_url,
self.copilot_url + "/copilot",
data=prompt.encode('utf-8'),
headers={'Content-Type': 'text/plain; charset=utf-8', 'User-Agent': 'DualAICopilot/0.1'},
method='POST'
)
with urllib.request.urlopen(req, timeout=60) as response:
with urllib.request.urlopen(req, timeout=500) as response:
if response.status == 200:
response_data = response.read().decode('utf-8')
logging.info(f"Received response from external copilot: {response_data[:100]}...")