Dedupe PromptBuilder
construction (#23496)
This PR dedupes the construction of the `PromptBuilder`. Previously this was constructed by both `assistant` and `assistant2`, but now we construct it outside and pass it in. Release Notes: - N/A
This commit is contained in:
parent
aad04e078a
commit
51fcb710d7
5 changed files with 36 additions and 35 deletions
|
@ -19,11 +19,10 @@ use gpui::{actions, AppContext, Global, UpdateGlobal};
|
||||||
use language_model::{
|
use language_model::{
|
||||||
LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, LanguageModelResponseMessage,
|
LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, LanguageModelResponseMessage,
|
||||||
};
|
};
|
||||||
use prompt_library::{PromptBuilder, PromptLoadingParams};
|
use prompt_library::PromptBuilder;
|
||||||
use semantic_index::{CloudEmbeddingProvider, SemanticDb};
|
use semantic_index::{CloudEmbeddingProvider, SemanticDb};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use settings::{Settings, SettingsStore};
|
use settings::{Settings, SettingsStore};
|
||||||
use util::ResultExt;
|
|
||||||
|
|
||||||
pub use crate::assistant_panel::{AssistantPanel, AssistantPanelEvent};
|
pub use crate::assistant_panel::{AssistantPanel, AssistantPanelEvent};
|
||||||
pub(crate) use crate::inline_assistant::*;
|
pub(crate) use crate::inline_assistant::*;
|
||||||
|
@ -93,9 +92,9 @@ impl Assistant {
|
||||||
pub fn init(
|
pub fn init(
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
stdout_is_a_pty: bool,
|
prompt_builder: Arc<PromptBuilder>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) -> Arc<PromptBuilder> {
|
) {
|
||||||
cx.set_global(Assistant::default());
|
cx.set_global(Assistant::default());
|
||||||
AssistantSettings::register(cx);
|
AssistantSettings::register(cx);
|
||||||
SlashCommandSettings::register(cx);
|
SlashCommandSettings::register(cx);
|
||||||
|
@ -135,16 +134,6 @@ pub fn init(
|
||||||
assistant_panel::init(cx);
|
assistant_panel::init(cx);
|
||||||
context_server::init(cx);
|
context_server::init(cx);
|
||||||
|
|
||||||
let prompt_builder = PromptBuilder::new(Some(PromptLoadingParams {
|
|
||||||
fs: fs.clone(),
|
|
||||||
repo_path: stdout_is_a_pty
|
|
||||||
.then(|| std::env::current_dir().log_err())
|
|
||||||
.flatten(),
|
|
||||||
cx,
|
|
||||||
}))
|
|
||||||
.log_err()
|
|
||||||
.map(Arc::new)
|
|
||||||
.unwrap_or_else(|| Arc::new(PromptBuilder::new(None).unwrap()));
|
|
||||||
register_slash_commands(Some(prompt_builder.clone()), cx);
|
register_slash_commands(Some(prompt_builder.clone()), cx);
|
||||||
inline_assistant::init(
|
inline_assistant::init(
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
|
@ -175,8 +164,6 @@ pub fn init(
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
prompt_builder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_language_model_settings(cx: &mut AppContext) {
|
fn init_language_model_settings(cx: &mut AppContext) {
|
||||||
|
|
|
@ -25,9 +25,8 @@ use command_palette_hooks::CommandPaletteFilter;
|
||||||
use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
|
use feature_flags::{Assistant2FeatureFlag, FeatureFlagAppExt};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{actions, AppContext};
|
use gpui::{actions, AppContext};
|
||||||
use prompt_library::{PromptBuilder, PromptLoadingParams};
|
use prompt_library::PromptBuilder;
|
||||||
use settings::Settings as _;
|
use settings::Settings as _;
|
||||||
use util::ResultExt;
|
|
||||||
|
|
||||||
pub use crate::assistant_panel::{AssistantPanel, ConcreteAssistantPanelDelegate};
|
pub use crate::assistant_panel::{AssistantPanel, ConcreteAssistantPanelDelegate};
|
||||||
pub use crate::inline_assistant::InlineAssistant;
|
pub use crate::inline_assistant::InlineAssistant;
|
||||||
|
@ -60,20 +59,15 @@ actions!(
|
||||||
const NAMESPACE: &str = "assistant2";
|
const NAMESPACE: &str = "assistant2";
|
||||||
|
|
||||||
/// Initializes the `assistant2` crate.
|
/// Initializes the `assistant2` crate.
|
||||||
pub fn init(fs: Arc<dyn Fs>, client: Arc<Client>, stdout_is_a_pty: bool, cx: &mut AppContext) {
|
pub fn init(
|
||||||
|
fs: Arc<dyn Fs>,
|
||||||
|
client: Arc<Client>,
|
||||||
|
prompt_builder: Arc<PromptBuilder>,
|
||||||
|
cx: &mut AppContext,
|
||||||
|
) {
|
||||||
AssistantSettings::register(cx);
|
AssistantSettings::register(cx);
|
||||||
assistant_panel::init(cx);
|
assistant_panel::init(cx);
|
||||||
|
|
||||||
let prompt_builder = PromptBuilder::new(Some(PromptLoadingParams {
|
|
||||||
fs: fs.clone(),
|
|
||||||
repo_path: stdout_is_a_pty
|
|
||||||
.then(|| std::env::current_dir().log_err())
|
|
||||||
.flatten(),
|
|
||||||
cx,
|
|
||||||
}))
|
|
||||||
.log_err()
|
|
||||||
.map(Arc::new)
|
|
||||||
.unwrap_or_else(|| Arc::new(PromptBuilder::new(None).unwrap()));
|
|
||||||
inline_assistant::init(
|
inline_assistant::init(
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
prompt_builder.clone(),
|
prompt_builder.clone(),
|
||||||
|
|
|
@ -2,7 +2,7 @@ use anyhow::Result;
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::AssetSource;
|
use gpui::{AppContext, AssetSource};
|
||||||
use handlebars::{Handlebars, RenderError};
|
use handlebars::{Handlebars, RenderError};
|
||||||
use language::{BufferSnapshot, LanguageName, Point};
|
use language::{BufferSnapshot, LanguageName, Point};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
@ -56,6 +56,19 @@ pub struct PromptBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PromptBuilder {
|
impl PromptBuilder {
|
||||||
|
pub fn load(fs: Arc<dyn Fs>, stdout_is_a_pty: bool, cx: &mut AppContext) -> Arc<Self> {
|
||||||
|
Self::new(Some(PromptLoadingParams {
|
||||||
|
fs: fs.clone(),
|
||||||
|
repo_path: stdout_is_a_pty
|
||||||
|
.then(|| std::env::current_dir().log_err())
|
||||||
|
.flatten(),
|
||||||
|
cx,
|
||||||
|
}))
|
||||||
|
.log_err()
|
||||||
|
.map(Arc::new)
|
||||||
|
.unwrap_or_else(|| Arc::new(Self::new(None).unwrap()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(loading_params: Option<PromptLoadingParams>) -> Result<Self> {
|
pub fn new(loading_params: Option<PromptLoadingParams>) -> Result<Self> {
|
||||||
let mut handlebars = Handlebars::new();
|
let mut handlebars = Handlebars::new();
|
||||||
Self::register_built_in_templates(&mut handlebars)?;
|
Self::register_built_in_templates(&mut handlebars)?;
|
||||||
|
|
|
@ -25,6 +25,7 @@ use gpui::{
|
||||||
use http_client::{read_proxy_from_env, Uri};
|
use http_client::{read_proxy_from_env, Uri};
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
|
use prompt_library::PromptBuilder;
|
||||||
use reqwest_client::ReqwestClient;
|
use reqwest_client::ReqwestClient;
|
||||||
|
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
|
@ -443,16 +444,17 @@ fn main() {
|
||||||
app_state.user_store.clone(),
|
app_state.user_store.clone(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
let prompt_builder = assistant::init(
|
let prompt_builder = PromptBuilder::load(app_state.fs.clone(), stdout_is_a_pty(), cx);
|
||||||
|
assistant::init(
|
||||||
app_state.fs.clone(),
|
app_state.fs.clone(),
|
||||||
app_state.client.clone(),
|
app_state.client.clone(),
|
||||||
stdout_is_a_pty(),
|
prompt_builder.clone(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
assistant2::init(
|
assistant2::init(
|
||||||
app_state.fs.clone(),
|
app_state.fs.clone(),
|
||||||
app_state.client.clone(),
|
app_state.client.clone(),
|
||||||
stdout_is_a_pty(),
|
prompt_builder.clone(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
assistant_tools::init(cx);
|
assistant_tools::init(cx);
|
||||||
|
|
|
@ -3833,8 +3833,13 @@ mod tests {
|
||||||
app_state.fs.clone(),
|
app_state.fs.clone(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
let prompt_builder =
|
let prompt_builder = PromptBuilder::load(app_state.fs.clone(), false, cx);
|
||||||
assistant::init(app_state.fs.clone(), app_state.client.clone(), false, cx);
|
assistant::init(
|
||||||
|
app_state.fs.clone(),
|
||||||
|
app_state.client.clone(),
|
||||||
|
prompt_builder.clone(),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
repl::init(app_state.fs.clone(), cx);
|
repl::init(app_state.fs.clone(), cx);
|
||||||
repl::notebook::init(cx);
|
repl::notebook::init(cx);
|
||||||
tasks_ui::init(cx);
|
tasks_ui::init(cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue