()
| 135 | #[tokio::test] |
| 136 | #[ignore = "Requires Perplexity API key"] |
| 137 | async fn test_perplexity_llm() { |
| 138 | if !has_perplexity_key() { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | let config = llm::LlmConfig::Perplexity { |
| 143 | api_key: std::env::var("PERPLEXITY_API_KEY").unwrap(), |
| 144 | model: "sonar".to_string(), |
| 145 | base_url: None, |
| 146 | }; |
| 147 | |
| 148 | let provider = llm::LlmProviderFactory::create_provider(config).unwrap(); |
| 149 | let request = llm::LlmRequest::new("What is 2+2?") |
| 150 | .with_max_tokens(50) // Increased to avoid length truncation |
| 151 | .with_temperature(0.0); |
| 152 | |
| 153 | let result = provider.complete(request).await; |
| 154 | if let Err(e) = &result { |
| 155 | println!("Perplexity API call failed: {:?}", e); |
| 156 | } |
| 157 | assert!(result.is_ok()); |
| 158 | |
| 159 | let response = result.unwrap(); |
| 160 | println!("Perplexity finish reason: {:?}", response.finish_reason); |
| 161 | // Accept both natural stop and length truncation as valid completions |
| 162 | assert!( |
| 163 | response.finish_reason.is_natural_stop() || response.finish_reason.is_truncated(), |
| 164 | "Expected natural stop or length truncation, got: {:?}", |
| 165 | response.finish_reason |
| 166 | ); |
| 167 | } |
| 168 | |
| 169 | #[tokio::test] |
| 170 | #[ignore = "Tests Perplexity authentication failure"] |
nothing calls this directly
no test coverage detected