From 5ff772e7def1eff76f0097a6927e04adf5ce3cc2 Mon Sep 17 00:00:00 2001 From: Vishnu Kakaraparthi Date: Wed, 26 Mar 2025 16:27:27 -0700 Subject: [PATCH 1/4] Added Perplexity url and models to config.py --- config/config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/config.py b/config/config.py index cebc032..f711ff9 100644 --- a/config/config.py +++ b/config/config.py @@ -57,6 +57,12 @@ "api_key": "", # User must provide "models": ["grok-1", "grok-2"], }, + "perplexity": { + "name": "Perplexity AI", + "base_url": "https://api.perplexity.ai", + "api_key": "", # User must provide + "models": ["sonar", "sonar-pro"], # Example model names + }, } # Topic list From 6ff292b70bbbe8ccd59073ebdde6a763f266c7e2 Mon Sep 17 00:00:00 2001 From: Vishnu Kakaraparthi Date: Wed, 26 Mar 2025 16:28:07 -0700 Subject: [PATCH 2/4] Update llm_service.py for perplexity --- modules/llm_service.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/llm_service.py b/modules/llm_service.py index 8641df3..ece1145 100644 --- a/modules/llm_service.py +++ b/modules/llm_service.py @@ -33,6 +33,7 @@ # Grok uses the OpenAI client with a different base URL GROK_AVAILABLE = OPENAI_AVAILABLE +PERPLEXITY_AVAILABLE = OPENAI_AVAILABLE from config import config @@ -58,7 +59,7 @@ def __init__( Initialize the LLM service. Args: - provider: LLM provider (e.g., 'lmstudio', 'openai', 'anthropic', 'google', 'grok') + provider: LLM provider (e.g., 'lmstudio', 'openai', 'anthropic', 'google', 'grok', 'perplexity') base_url: Base URL for the LLM API api_key: API key for authentication (if None, will use provider-specific key) model: Model identifier to use @@ -79,6 +80,8 @@ def __init__( self.api_key = config.GOOGLE_API_KEY elif provider == "grok": self.api_key = config.GROK_API_KEY + elif provider == "perplexity": + self.api_key = config.PERPLEXITY_API_KEY else: # lmstudio or other self.api_key = config.LLM_API_KEY else: @@ -87,9 +90,10 @@ def __init__( # Initialize client based on provider self.client = None - if provider in ["lmstudio", "openai", "grok"]: + if provider in ["lmstudio", "openai", "grok", "perplexity"]: if OPENAI_AVAILABLE: try: + print(base_url, self.api_key) self.client = OpenAI(base_url=base_url, api_key=self.api_key) logger.info(f"Initialized {provider} client with model {model}") except Exception as e: @@ -126,6 +130,16 @@ def __init__( logger.warning( "Google Generative AI package not installed or API key missing. Falling back to direct API calls." ) + elif provider == "perplexity": + if PERPLEXITY_AVAILABLE and self.api_key: + try: + self.client = OpenAI(api_key=self.api_key, base_url=self.base_url) + print(self.base_url) + logger.info("Initialized Perplexity client with model %s", model) + except Exception as e: + logger.warning("Error initializing Perplexity client: %s", e) + logger.info("Falling back to direct API calls via requests") + def generate_response( self, @@ -161,7 +175,7 @@ def generate_response( for attempt in range(max_retries): try: # Handle different providers - if self.provider in ["lmstudio", "openai", "grok"]: + if self.provider in ["lmstudio", "openai", "grok", "perplexity"]: if self.client is not None: # Use the OpenAI client response = self.client.chat.completions.create( From e393f865b9be80937683ef44e25aa59515cb0364 Mon Sep 17 00:00:00 2001 From: Vishnu Kakaraparthi Date: Wed, 26 Mar 2025 16:28:48 -0700 Subject: [PATCH 3/4] Update .env.example to add perplexity key --- config/.env.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/.env.example b/config/.env.example index bef32a9..d7b0593 100644 --- a/config/.env.example +++ b/config/.env.example @@ -12,3 +12,6 @@ # Grok API Key (required for Grok provider) # GROK_API_KEY=your_grok_key_here + +# Perplexity API Key (required for Perplexity provider) +PERPLEXITY_API_KEY=your_perplexity_key_here From bafe5fd583551f1022b02b0beffe569f1df0b749 Mon Sep 17 00:00:00 2001 From: Vishnu Kakaraparthi Date: Wed, 26 Mar 2025 16:34:49 -0700 Subject: [PATCH 4/4] removed unnecessary print statement --- modules/llm_service.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/llm_service.py b/modules/llm_service.py index ece1145..fca07de 100644 --- a/modules/llm_service.py +++ b/modules/llm_service.py @@ -93,7 +93,6 @@ def __init__( if provider in ["lmstudio", "openai", "grok", "perplexity"]: if OPENAI_AVAILABLE: try: - print(base_url, self.api_key) self.client = OpenAI(base_url=base_url, api_key=self.api_key) logger.info(f"Initialized {provider} client with model {model}") except Exception as e: