Skip to content

Commit

Permalink
fix/client/wrong url, add from_env method
Browse files Browse the repository at this point in the history
  • Loading branch information
marieaurore123 committed Sep 11, 2024
1 parent 76dacd7 commit ba312a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rig-core/src/providers/perplexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use serde_json::json;
// ================================================================
// Main Cohere Client
// ================================================================
const PERPLEXITY_API_BASE_URL: &str = "https://api.perplexity.ai/chat/completions";
const PERPLEXITY_API_BASE_URL: &str = "https://api.perplexity.ai";

#[derive(Clone)]
pub struct Client {
Expand All @@ -39,6 +39,13 @@ impl Client {
Self::from_url(api_key, PERPLEXITY_API_BASE_URL)
}

/// Create a new Perplexity client from the `PERPLEXITY_API_KEY` environment variable.
/// Panics if the environment variable is not set.
pub fn from_env() -> Self {
let api_key = std::env::var("PERPLEXITY_API_KEY").expect("PERPLEXITY_API_KEY not set");
Self::new(&api_key)
}

pub fn from_url(api_key: &str, base_url: &str) -> Self {
Self {
base_url: base_url.to_string(),
Expand Down

0 comments on commit ba312a1

Please sign in to comment.