language_model: Return AuthenticateError
s from LanguageModelProvider::authenticate
(#25126)
This PR updates the `LanguageModelProvider::authenticate` method to return an `AuthenticateError` instead of an `anyhow::Error`. This allows us to model the "credentials not found" state explicitly as `AuthenticateError::CredentialsNotFound`, which enables the caller to check for this state and act accordingly. Planning to use this in #25123 to silence errors about missing credentials when authenticating providers in the background. Release Notes: - N/A
This commit is contained in:
parent
2627a5fdbe
commit
7a6b652ebc
14 changed files with 230 additions and 184 deletions
|
@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
|
|||
use futures::{future::BoxFuture, stream::BoxStream, FutureExt, StreamExt};
|
||||
use gpui::{AnyView, App, AsyncApp, Context, Subscription, Task};
|
||||
use http_client::HttpClient;
|
||||
use language_model::LanguageModelCompletionEvent;
|
||||
use language_model::{AuthenticateError, LanguageModelCompletionEvent};
|
||||
use language_model::{
|
||||
LanguageModel, LanguageModelId, LanguageModelName, LanguageModelProvider,
|
||||
LanguageModelProviderId, LanguageModelProviderName, LanguageModelProviderState,
|
||||
|
@ -90,12 +90,13 @@ impl State {
|
|||
self.fetch_model_task.replace(task);
|
||||
}
|
||||
|
||||
fn authenticate(&mut self, cx: &mut Context<Self>) -> Task<Result<()>> {
|
||||
fn authenticate(&mut self, cx: &mut Context<Self>) -> Task<Result<(), AuthenticateError>> {
|
||||
if self.is_authenticated() {
|
||||
Task::ready(Ok(()))
|
||||
} else {
|
||||
self.fetch_models(cx)
|
||||
return Task::ready(Ok(()));
|
||||
}
|
||||
|
||||
let fetch_models_task = self.fetch_models(cx);
|
||||
cx.spawn(|_this, _cx| async move { Ok(fetch_models_task.await?) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,7 +202,7 @@ impl LanguageModelProvider for LmStudioLanguageModelProvider {
|
|||
self.state.read(cx).is_authenticated()
|
||||
}
|
||||
|
||||
fn authenticate(&self, cx: &mut App) -> Task<Result<()>> {
|
||||
fn authenticate(&self, cx: &mut App) -> Task<Result<(), AuthenticateError>> {
|
||||
self.state.update(cx, |state, cx| state.authenticate(cx))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue