agent: Expose web search tool to beta users (#29273)
This gives all beta users access to the web search tool Release Notes: - agent: Added `web_search` tool
This commit is contained in:
parent
09db31288a
commit
822b6f837d
10 changed files with 67 additions and 40 deletions
|
@ -14,7 +14,6 @@ path = "src/web_search_providers.rs"
|
|||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
client.workspace = true
|
||||
feature_flags.workspace = true
|
||||
futures.workspace = true
|
||||
gpui.workspace = true
|
||||
http_client.workspace = true
|
||||
|
|
|
@ -50,9 +50,11 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
pub const ZED_WEB_SEARCH_PROVIDER_ID: &'static str = "zed.dev";
|
||||
|
||||
impl WebSearchProvider for CloudWebSearchProvider {
|
||||
fn id(&self) -> WebSearchProviderId {
|
||||
WebSearchProviderId("zed.dev".into())
|
||||
WebSearchProviderId(ZED_WEB_SEARCH_PROVIDER_ID.into())
|
||||
}
|
||||
|
||||
fn search(&self, query: String, cx: &mut App) -> Task<Result<WebSearchResponse>> {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
mod cloud;
|
||||
|
||||
use client::Client;
|
||||
use feature_flags::{FeatureFlagAppExt, ZedProWebSearchTool};
|
||||
use gpui::{App, Context};
|
||||
use language_model::LanguageModelRegistry;
|
||||
use std::sync::Arc;
|
||||
use web_search::WebSearchRegistry;
|
||||
use web_search::{WebSearchProviderId, WebSearchRegistry};
|
||||
|
||||
pub fn init(client: Arc<Client>, cx: &mut App) {
|
||||
let registry = WebSearchRegistry::global(cx);
|
||||
|
@ -18,18 +18,27 @@ fn register_web_search_providers(
|
|||
client: Arc<Client>,
|
||||
cx: &mut Context<WebSearchRegistry>,
|
||||
) {
|
||||
cx.observe_flag::<ZedProWebSearchTool, _>({
|
||||
let client = client.clone();
|
||||
move |is_enabled, cx| {
|
||||
if is_enabled {
|
||||
WebSearchRegistry::global(cx).update(cx, |registry, cx| {
|
||||
registry.register_provider(
|
||||
cx.subscribe(
|
||||
&LanguageModelRegistry::global(cx),
|
||||
move |this, registry, event, cx| match event {
|
||||
language_model::Event::DefaultModelChanged => {
|
||||
let using_zed_provider = registry
|
||||
.read(cx)
|
||||
.default_model()
|
||||
.map_or(false, |default| default.is_provided_by_zed());
|
||||
if using_zed_provider {
|
||||
this.register_provider(
|
||||
cloud::CloudWebSearchProvider::new(client.clone(), cx),
|
||||
cx,
|
||||
);
|
||||
});
|
||||
)
|
||||
} else {
|
||||
this.unregister_provider(WebSearchProviderId(
|
||||
cloud::ZED_WEB_SEARCH_PROVIDER_ID.into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
_ => {}
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue