Refactor AI providers using Strategy Pattern
This commit is contained in:
@@ -116,31 +116,19 @@ def call_tool(function_call):
|
|||||||
|
|
||||||
async def switch(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def switch(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
global ai_provider
|
global ai_provider
|
||||||
if isinstance(ai_provider, OpenAIProvider):
|
model = ai_provider.switch_model()
|
||||||
ai_provider.use_smart_model = not ai_provider.use_smart_model
|
|
||||||
model = ai_provider.get_model()
|
|
||||||
logging.info(f"Switched to model: {model}")
|
logging.info(f"Switched to model: {model}")
|
||||||
await update.message.reply_text(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:
|
async def switch_providers(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
await clear(update, context)
|
await clear(update, context)
|
||||||
global ai_provider
|
global ai_provider
|
||||||
if isinstance(ai_provider, AnthropicProvider):
|
ai_provider = create_ai_provider("openai" if ai_provider.name == "anthropic" else "anthropic")
|
||||||
ai_provider = create_ai_provider("openai")
|
logging.info(f"Switched to {ai_provider.name} provider")
|
||||||
logging.info("Switched to OpenAI provider")
|
await update.message.reply_text(f"Switched to {ai_provider.name} 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")
|
|
||||||
|
|
||||||
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
if isinstance(ai_provider, AnthropicProvider):
|
await update.message.reply_text(f"Currently using {ai_provider.name}: {ai_provider.get_model()}")
|
||||||
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()}")
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
# Create the Application and pass it your bot's token
|
# Create the Application and pass it your bot's token
|
||||||
|
|||||||
Reference in New Issue
Block a user