Refactor AI providers using Strategy Pattern

This commit is contained in:
2024-08-18 13:18:38 -05:00
parent 6398537554
commit 5fbcd358bf
+5 -17
View File
@@ -116,31 +116,19 @@ def call_tool(function_call):
async def switch(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
global ai_provider
if isinstance(ai_provider, OpenAIProvider):
ai_provider.use_smart_model = not ai_provider.use_smart_model
model = ai_provider.get_model()
model = ai_provider.switch_model()
logging.info(f"Switched to model: {model}")
await update.message.reply_text(f"Switched to model: {model}")
else:
await update.message.reply_text("Switching models is only available for OpenAI provider.")
async def switch_providers(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await clear(update, context)
global ai_provider
if isinstance(ai_provider, AnthropicProvider):
ai_provider = create_ai_provider("openai")
logging.info("Switched to OpenAI provider")
await update.message.reply_text("Switched to OpenAI provider")
else:
ai_provider = create_ai_provider("anthropic")
logging.info("Switched to Anthropic provider")
await update.message.reply_text("Switched to Anthropic provider")
ai_provider = create_ai_provider("openai" if ai_provider.name == "anthropic" else "anthropic")
logging.info(f"Switched to {ai_provider.name} provider")
await update.message.reply_text(f"Switched to {ai_provider.name} provider")
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
if isinstance(ai_provider, AnthropicProvider):
await update.message.reply_text(f"Currently using Anthropic: {ai_provider.model}")
else:
await update.message.reply_text(f"Currently using OpenAI: {ai_provider.get_model()}")
await update.message.reply_text(f"Currently using {ai_provider.name}: {ai_provider.get_model()}")
def main() -> None:
# Create the Application and pass it your bot's token