refactor: use explicit dependency injection for groq_api_key
This commit is contained in:
parent
eb20cea668
commit
8989adc9ae
@ -36,10 +36,10 @@ class ChannelManager:
|
|||||||
if self.config.channels.telegram.enabled:
|
if self.config.channels.telegram.enabled:
|
||||||
try:
|
try:
|
||||||
from nanobot.channels.telegram import TelegramChannel
|
from nanobot.channels.telegram import TelegramChannel
|
||||||
# Inject parent config for access to providers
|
|
||||||
self.config.channels.telegram.parent = self.config
|
|
||||||
self.channels["telegram"] = TelegramChannel(
|
self.channels["telegram"] = TelegramChannel(
|
||||||
self.config.channels.telegram, self.bus
|
self.config.channels.telegram,
|
||||||
|
self.bus,
|
||||||
|
groq_api_key=self.config.providers.groq.api_key,
|
||||||
)
|
)
|
||||||
logger.info("Telegram channel enabled")
|
logger.info("Telegram channel enabled")
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -49,8 +49,6 @@ class ChannelManager:
|
|||||||
if self.config.channels.whatsapp.enabled:
|
if self.config.channels.whatsapp.enabled:
|
||||||
try:
|
try:
|
||||||
from nanobot.channels.whatsapp import WhatsAppChannel
|
from nanobot.channels.whatsapp import WhatsAppChannel
|
||||||
# Inject parent config for access to providers
|
|
||||||
self.config.channels.whatsapp.parent = self.config
|
|
||||||
self.channels["whatsapp"] = WhatsAppChannel(
|
self.channels["whatsapp"] = WhatsAppChannel(
|
||||||
self.config.channels.whatsapp, self.bus
|
self.config.channels.whatsapp, self.bus
|
||||||
)
|
)
|
||||||
|
|||||||
@ -85,9 +85,10 @@ class TelegramChannel(BaseChannel):
|
|||||||
|
|
||||||
name = "telegram"
|
name = "telegram"
|
||||||
|
|
||||||
def __init__(self, config: TelegramConfig, bus: MessageBus):
|
def __init__(self, config: TelegramConfig, bus: MessageBus, groq_api_key: str = ""):
|
||||||
super().__init__(config, bus)
|
super().__init__(config, bus)
|
||||||
self.config: TelegramConfig = config
|
self.config: TelegramConfig = config
|
||||||
|
self.groq_api_key = groq_api_key
|
||||||
self._app: Application | None = None
|
self._app: Application | None = None
|
||||||
self._chat_ids: dict[str, int] = {} # Map sender_id to chat_id for replies
|
self._chat_ids: dict[str, int] = {} # Map sender_id to chat_id for replies
|
||||||
|
|
||||||
@ -253,12 +254,7 @@ class TelegramChannel(BaseChannel):
|
|||||||
# Handle voice transcription
|
# Handle voice transcription
|
||||||
if media_type == "voice" or media_type == "audio":
|
if media_type == "voice" or media_type == "audio":
|
||||||
from nanobot.providers.transcription import GroqTranscriptionProvider
|
from nanobot.providers.transcription import GroqTranscriptionProvider
|
||||||
# Try to get Groq API key from config
|
transcriber = GroqTranscriptionProvider(api_key=self.groq_api_key)
|
||||||
groq_key = None
|
|
||||||
if hasattr(self.config, 'parent') and hasattr(self.config.parent, 'providers'):
|
|
||||||
groq_key = self.config.parent.providers.groq.api_key
|
|
||||||
|
|
||||||
transcriber = GroqTranscriptionProvider(api_key=groq_key)
|
|
||||||
transcription = await transcriber.transcribe(file_path)
|
transcription = await transcriber.transcribe(file_path)
|
||||||
if transcription:
|
if transcription:
|
||||||
logger.info(f"Transcribed {media_type}: {transcription[:50]}...")
|
logger.info(f"Transcribed {media_type}: {transcription[:50]}...")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user