MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / chat

Method chat

crates/opencode-provider/src/perplexity.rs:88–109  ·  view source on GitHub ↗
(&self, request: ChatRequest)

Source from the content-addressed store, hash-verified

86 }
87
88 async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
89 let response = self
90 .client
91 .post(PERPLEXITY_API_URL)
92 .header("Authorization", format!("Bearer {}", self.api_key))
93 .header("Content-Type", "application/json")
94 .json(&request)
95 .send()
96 .await
97 .map_err(|e| ProviderError::NetworkError(e.to_string()))?;
98
99 if !response.status().is_success() {
100 let status = response.status();
101 let body = response.text().await.unwrap_or_default();
102 return Err(ProviderError::ApiError(format!("{}: {}", status, body)));
103 }
104
105 response
106 .json()
107 .await
108 .map_err(|e| ProviderError::ApiError(e.to_string()))
109 }
110
111 async fn chat_stream(&self, request: ChatRequest) -> Result<StreamResult, ProviderError> {
112 let mut stream_request = request;

Callers

nothing calls this directly

Calls 4

ApiErrorEnum · 0.50
sendMethod · 0.45
statusMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected