Synchronous answer (for non-async contexts).
(&self, context: &str, query: &str)
| 302 | |
| 303 | /// Synchronous answer (for non-async contexts). |
| 304 | pub fn answer_sync(&self, context: &str, query: &str) -> Result<LlmResponse, AiError> { |
| 305 | let rt = tokio::runtime::Builder::new_current_thread() |
| 306 | .enable_all() |
| 307 | .build() |
| 308 | .map_err(|e| AiError::Runtime(e.to_string()))?; |
| 309 | rt.block_on(self.answer(context, query)) |
| 310 | } |
| 311 | |
| 312 | async fn call_anthropic(&self, context: &str, query: &str) -> Result<LlmResponse, AiError> { |
| 313 | let url = format!("{}/messages", self.base_url); |