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
+14 -35
View File
@@ -3,30 +3,8 @@ import socketserver
import os import os
import logging import logging
import asyncio import asyncio
# Assuming InferenceBot is available in the same environment or can be imported from inference_bot import InferenceBot
# For demonstration, we'll use a placeholder if not explicitly provided. import time
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)
# Configure logging # Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -66,6 +44,10 @@ class APIHelper:
logging.error(f"Error in _handle_message_logic for user {user_id}: {str(e)}") logging.error(f"Error in _handle_message_logic for user {user_id}: {str(e)}")
return f"Error processing message: {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): class CopilotRequestHandler(http.server.BaseHTTPRequestHandler):
# This will be set by the server when it's created # This will be set by the server when it's created
@@ -131,19 +113,16 @@ def run_server(bot_instance: InferenceBot, server_class=http.server.HTTPServer,
# Attach the APIHelper instance to the handler class # Attach the APIHelper instance to the handler class
handler_class.api_helper_instance = api_helper handler_class.api_helper_instance = api_helper
server_address = (host, port) try:
httpd = server_class(server_address, handler_class) server_address = (host, port)
logging.info(f"Starting Copilot API helper on http://{host}:{port}{COPILOT_PATH}") httpd = server_class(server_address, handler_class)
logging.info(f"Health check available at http://{host}:{port}/health") 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: try:
httpd.serve_forever() httpd.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("Server shutting down...") logging.info("Server shutting down...")
httpd.server_close() 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())
+18 -5
View File
@@ -162,6 +162,17 @@ class OpenAICompatibleInferenceBot(InferenceBot):
function_args_str = function_to_call.arguments function_args_str = function_to_call.arguments
logging.info(f"Attempting to call tool: {function_name} with args: {function_args_str}") 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: try:
# Arguments are already a string from the API, self.call_tool expects dict or string # 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) tool_response_content = self.call_tool(function_name, function_args_str)
@@ -371,13 +382,15 @@ def main():
system_prompt_path=system_prompt_path, system_prompt_path=system_prompt_path,
allowed_function_tags=allowed_function_tags 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" messenger_helper_class_name = f"{messenger.capitalize()}Helper"
if not hasattr(messenger_helper_class, messenger_helper_class_name): if not hasattr(full_code_file, messenger_helper_class_name):
raise ValueError(f"Messenger helper class {messenger_helper_class_name} not found in {messenger_helper_class.__name__}.") messenger_helper_class_name = f"{messenger.upper()}Helper"
messenger_helper_class = getattr(messenger_helper_class, messenger_helper_class_name) 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() helper.run()
except ValueError as e: except ValueError as e:
logging.error(f"FATAL: {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. 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:** **Your Core Directives:**
1. **Orchestrate and Direct:** 1. **Orchestrate and Direct:**
@@ -48,4 +50,5 @@ You are the **Lead Developer Persona**, a strategic and demanding mentor dedicat
**Initial State:** **Initial State:**
* You have your "List of Absolutes" (you will define these as you go or have a pre-set list). * 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.") logging.warning("COPILOT_API_URL environment variable not set. call_external_copilot will not function.")
def clear(self): def clear(self):
pass self._call_external_copilot("/clear")
def get_functions(self): def get_functions(self):
return [ return [
@@ -51,7 +51,7 @@ class StandaloneLLMTool(BaseTool):
"type": "function", "type": "function",
"function": { "function": {
"name": "call_external_copilot", "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": { "parameters": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -73,17 +73,15 @@ class StandaloneLLMTool(BaseTool):
logging.info(f"Calling external copilot at URL: {self.copilot_url} with prompt: {prompt[:50]}...") 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://'): 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://" self.copilot_url = 'http://' + self.copilot_url
logging.error(error_message)
return error_message
try: try:
req = urllib.request.Request( req = urllib.request.Request(
self.copilot_url, self.copilot_url + "/copilot",
data=prompt.encode('utf-8'), data=prompt.encode('utf-8'),
headers={'Content-Type': 'text/plain; charset=utf-8', 'User-Agent': 'DualAICopilot/0.1'}, headers={'Content-Type': 'text/plain; charset=utf-8', 'User-Agent': 'DualAICopilot/0.1'},
method='POST' method='POST'
) )
with urllib.request.urlopen(req, timeout=60) as response: with urllib.request.urlopen(req, timeout=500) as response:
if response.status == 200: if response.status == 200:
response_data = response.read().decode('utf-8') response_data = response.read().decode('utf-8')
logging.info(f"Received response from external copilot: {response_data[:100]}...") logging.info(f"Received response from external copilot: {response_data[:100]}...")