From 94e897b8e0de1a10b2ff473f7d1f836aa6ae8d3e Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:42:17 -0500 Subject: [PATCH 1/2] Refactor Anthropic bot for small/large model switching and update developer prompt for autonomy --- anthropic_telegram_inference_bot.py | 55 ++++++++++++++++++----------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/anthropic_telegram_inference_bot.py b/anthropic_telegram_inference_bot.py index 3838d4f..3e9ba43 100644 --- a/anthropic_telegram_inference_bot.py +++ b/anthropic_telegram_inference_bot.py @@ -10,13 +10,19 @@ class AnthropicTelegramInferenceBot(BaseTelegramInferenceBot): super().__init__() self.anthropic_client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY")) + # Initialize with the small model by default + self.small_model_name = os.environ.get("ANTHROPIC_SMALL_MODEL", "claude-3-haiku-20240307") + self.small_model_max_tokens = os.environ.get("ANTHROPIC_SMALL_MODEL_MAX_TOKENS", "2048") + self.large_model_name = os.environ.get("ANTHROPIC_LARGE_MODEL", "claude-3-opus-20240229") + self.large_model_max_tokens = os.environ.get("ANTHROPIC_LARGE_MODEL_MAX_TOKENS", "4096") + self._configure_model_and_tokens( - os.environ.get("ANTHROPIC_MODEL", "claude-3-5-sonnet-20240620"), - os.environ.get("ANTHROPIC_MAX_TOKENS", "4096") + self.small_model_name, + self.small_model_max_tokens ) - def _configure_model_and_tokens(self, model_name, max_tokens_str, default_max_tokens=4096): - self.model = model_name if model_name else "claude-3-5-sonnet-20240620" + def _configure_model_and_tokens(self, model_name, max_tokens_str, default_max_tokens=2048): # Default max_tokens adjusted for typical "small" + self.model = model_name try: self.max_tokens = int(max_tokens_str) if max_tokens_str is not None else default_max_tokens except ValueError: @@ -173,26 +179,35 @@ class AnthropicTelegramInferenceBot(BaseTelegramInferenceBot): return "No active processing found to abort. Conversation cleared." async def switch_model(self): - primary_model = os.environ.get("ANTHROPIC_MODEL", "claude-3-5-sonnet-20240620") - primary_max_tokens = os.environ.get("ANTHROPIC_MAX_TOKENS", "4096") - - secondary_model_env = os.environ.get("ANTHROPIC_SECONDARY_MODEL") - secondary_max_tokens_env = os.environ.get("ANTHROPIC_SECONDARY_MAX_TOKENS") + # Ensure ANTHROPIC_SMALL_MODEL and ANTHROPIC_LARGE_MODEL related env vars are loaded in __init__ + # or ensure they are freshly checked here if they can change during runtime (less common for model names). + # For this implementation, we rely on the values stored during __init__. - if not secondary_model_env: - logging.warning("ANTHROPIC_SECONDARY_MODEL not defined. Cannot switch model.") - return f"Model switching not configured. Currently using {self.model}." + if not self.small_model_name or not self.large_model_name: + logging.warning("Small or Large model names for Anthropic are not defined. Cannot switch model.") + return f"Model switching not fully configured. Currently using {self.model}." - if self.model == primary_model: - target_model = secondary_model_env - target_max_tokens = secondary_max_tokens_env if secondary_max_tokens_env else "2048" + if self.model == self.small_model_name: + target_model = self.large_model_name + target_max_tokens = self.large_model_max_tokens + # Use default large max_tokens if specific one isn't set or invalid + default_max_tokens_for_large = "4096" + elif self.model == self.large_model_name: + target_model = self.small_model_name + target_max_tokens = self.small_model_max_tokens + # Use default small max_tokens if specific one isn't set or invalid + default_max_tokens_for_large = "2048" else: - target_model = primary_model - target_max_tokens = primary_max_tokens - - self._configure_model_and_tokens(target_model, target_max_tokens) + # Current model is neither the designated small nor large, switch to small as a reset + logging.warning(f"Current model {self.model} is neither the configured small nor large model. Switching to small model.") + target_model = self.small_model_name + target_max_tokens = self.small_model_max_tokens + default_max_tokens_for_large = "2048" + + + self._configure_model_and_tokens(target_model, target_max_tokens, default_max_tokens=int(default_max_tokens_for_large)) # Pass appropriate default logging.info(f"Switched Anthropic model to: {self.model}") - return f"Switched to Anthropic model: {self.model}" + return f"Switched to Anthropic model: {self.model} (Max Tokens: {self.max_tokens})"#Provide token info def main(): if not os.environ.get("ANTHROPIC_API_KEY"): From dbcb72c455ea868048b2a0e6ca53dabb7b22b4ae Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:42:18 -0500 Subject: [PATCH 2/2] Update developer prompt for more autonomy --- prompts/developer_prompt.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/prompts/developer_prompt.txt b/prompts/developer_prompt.txt index a83b259..bcab8af 100644 --- a/prompts/developer_prompt.txt +++ b/prompts/developer_prompt.txt @@ -3,18 +3,20 @@ Imagine you're a savvy developer with a trusty toolkit, working in harmony with As you navigate the repository, keep in mind the following principles: Practicality: When updating files, consider that you're writing them in their entirety to disk. DO NOT omit code, especially when sending to a function or tool. -Literal Interpretation: When asked to implement functionality or create a feature, interpret the request as if you were literally told to find all relevant files, navigate relevant functions in code, update the required portions of code, and add required files. +Literal Interpretation: When asked to implement functionality or create a feature, interpret the *overall goal* as if you were literally told to find all relevant files, navigate relevant functions in code, update the required portions of code, and add required files. You are empowered to make logical, dependent sub-steps autonomously to achieve the stated goal (e.g., reading a file before modifying it). Design Agnosticism: Avoid making high-level design decisions, such as choosing programming languages or operating systems, unless absolutely sure. If unsure, ask before proceeding. Holistic Thinking: Consider the broader impacts of minor changes and strive for meaningful, measured exchanges. -Efficiency: Suggest simple tools or functions that can avoid current work, and limit function calls to 10 per chat message. +Efficiency: Suggest simple tools or functions that can avoid current work, and limit function calls to 10 per chat message. +Autonomy and Initiative: Once a task is assigned and understood, you are encouraged to outline your plan and then proceed with its execution. For multi-step operations that directly serve the user's request, you can carry out these steps without seeking re-confirmation for each one, unless a significant ambiguity or new decision point arises. + As a coding assistant, you will work in tandem with your human counterpart to: Organize and Explore: List files in directories, read file contents, and navigate the file system with ease. -Branch and Merge: Plant new branches, name them creatively, and ensure they stem from the right place. Keep an eye out for the SHA of the latest commit. +Branch and Merge: Plant new branches, autonomously suggesting or choosing creative and descriptive names, and ensure they stem from the right place. Keep an eye out for the SHA of the latest commit. Commit and Record: Commit changes with purpose, leaving behind a trail of meaningful messages. Collaborate and Share: Create pull requests with compelling titles and bodies, ensuring contributions are seen and valued. Investigate and Refine: Track changes, search for specific code, and refine your understanding of the repository's evolving terrain. -Plant in Your Own Garden: When doing any code changes, create a new branch first and commit to it. +Plant in Your Own Garden: When doing any code changes, create a new branch first (you can name it) and commit to it. Allow Flowers to Bloom: When you make a pull request, rather than lots of adjustments, opt for very few commits. Feedback will come quickly via pull requests. As you work together, remember to: