added initial working status in inline assistant prompt
This commit is contained in:
parent
933c21f3d3
commit
ec1b4e6f85
4 changed files with 129 additions and 77 deletions
|
@ -290,7 +290,7 @@ impl EmbeddingProvider for OpenAIEmbeddings {
|
||||||
|
|
||||||
let mut request_number = 0;
|
let mut request_number = 0;
|
||||||
let mut rate_limiting = false;
|
let mut rate_limiting = false;
|
||||||
let mut request_timeout: u64 = 15;
|
let mut request_timeout: u64 = 30;
|
||||||
let mut response: Response<AsyncBody>;
|
let mut response: Response<AsyncBody>;
|
||||||
while request_number < MAX_RETRIES {
|
while request_number < MAX_RETRIES {
|
||||||
response = self
|
response = self
|
||||||
|
|
|
@ -24,10 +24,10 @@ use futures::StreamExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
elements::{
|
elements::{
|
||||||
ChildView, Component, Empty, Flex, Label, MouseEventHandler, ParentElement, SafeStylable,
|
ChildView, Component, Empty, Flex, Label, LabelStyle, MouseEventHandler, ParentElement,
|
||||||
Stack, Svg, Text, UniformList, UniformListState,
|
SafeStylable, Stack, Svg, Text, UniformList, UniformListState,
|
||||||
},
|
},
|
||||||
fonts::HighlightStyle,
|
fonts::{HighlightStyle, TextStyle},
|
||||||
geometry::vector::{vec2f, Vector2F},
|
geometry::vector::{vec2f, Vector2F},
|
||||||
platform::{CursorStyle, MouseButton, PromptLevel},
|
platform::{CursorStyle, MouseButton, PromptLevel},
|
||||||
Action, AnyElement, AppContext, AsyncAppContext, ClipboardItem, Element, Entity, ModelContext,
|
Action, AnyElement, AppContext, AsyncAppContext, ClipboardItem, Element, Entity, ModelContext,
|
||||||
|
@ -37,7 +37,7 @@ use gpui::{
|
||||||
use language::{language_settings::SoftWrap, Buffer, LanguageRegistry, ToOffset as _};
|
use language::{language_settings::SoftWrap, Buffer, LanguageRegistry, ToOffset as _};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use search::BufferSearchBar;
|
use search::BufferSearchBar;
|
||||||
use semantic_index::SemanticIndex;
|
use semantic_index::{SemanticIndex, SemanticIndexStatus};
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use std::{
|
use std::{
|
||||||
cell::{Cell, RefCell},
|
cell::{Cell, RefCell},
|
||||||
|
@ -2756,6 +2756,7 @@ struct InlineAssistant {
|
||||||
semantic_index: Option<ModelHandle<SemanticIndex>>,
|
semantic_index: Option<ModelHandle<SemanticIndex>>,
|
||||||
semantic_permissioned: Option<bool>,
|
semantic_permissioned: Option<bool>,
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
|
maintain_rate_limit: Option<Task<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for InlineAssistant {
|
impl Entity for InlineAssistant {
|
||||||
|
@ -2772,8 +2773,7 @@ impl View for InlineAssistant {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_children([Flex::row()
|
||||||
Flex::row()
|
|
||||||
.with_child(
|
.with_child(
|
||||||
Button::action(ToggleIncludeConversation)
|
Button::action(ToggleIncludeConversation)
|
||||||
.with_tooltip("Include Conversation", theme.tooltip.clone())
|
.with_tooltip("Include Conversation", theme.tooltip.clone())
|
||||||
|
@ -2831,8 +2831,7 @@ impl View for InlineAssistant {
|
||||||
max: vec2f(measurements.gutter_width, constraint.max.y()),
|
max: vec2f(measurements.gutter_width, constraint.max.y()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
})])
|
||||||
)
|
|
||||||
.with_child(Empty::new().constrained().dynamically({
|
.with_child(Empty::new().constrained().dynamically({
|
||||||
let measurements = self.measurements.clone();
|
let measurements = self.measurements.clone();
|
||||||
move |constraint, _, _| {
|
move |constraint, _, _| {
|
||||||
|
@ -2855,6 +2854,19 @@ impl View for InlineAssistant {
|
||||||
.left()
|
.left()
|
||||||
.flex(1., true),
|
.flex(1., true),
|
||||||
)
|
)
|
||||||
|
.with_children(if self.retrieve_context {
|
||||||
|
Some(
|
||||||
|
Flex::row()
|
||||||
|
.with_child(Label::new(
|
||||||
|
self.retrieve_context_status(cx),
|
||||||
|
theme.assistant.inline.context_status.text.clone(),
|
||||||
|
))
|
||||||
|
.flex(1., true)
|
||||||
|
.aligned(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(theme.assistant.inline.container)
|
.with_style(theme.assistant.inline.container)
|
||||||
.into_any()
|
.into_any()
|
||||||
|
@ -2896,11 +2908,15 @@ impl InlineAssistant {
|
||||||
editor.set_placeholder_text(placeholder, cx);
|
editor.set_placeholder_text(placeholder, cx);
|
||||||
editor
|
editor
|
||||||
});
|
});
|
||||||
let subscriptions = vec![
|
let mut subscriptions = vec![
|
||||||
cx.observe(&codegen, Self::handle_codegen_changed),
|
cx.observe(&codegen, Self::handle_codegen_changed),
|
||||||
cx.subscribe(&prompt_editor, Self::handle_prompt_editor_events),
|
cx.subscribe(&prompt_editor, Self::handle_prompt_editor_events),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if let Some(semantic_index) = semantic_index.clone() {
|
||||||
|
subscriptions.push(cx.observe(&semantic_index, Self::semantic_index_changed));
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
prompt_editor,
|
prompt_editor,
|
||||||
|
@ -2918,6 +2934,7 @@ impl InlineAssistant {
|
||||||
semantic_permissioned: None,
|
semantic_permissioned: None,
|
||||||
semantic_index,
|
semantic_index,
|
||||||
project,
|
project,
|
||||||
|
maintain_rate_limit: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2947,6 +2964,34 @@ impl InlineAssistant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn semantic_index_changed(
|
||||||
|
&mut self,
|
||||||
|
semantic_index: ModelHandle<SemanticIndex>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
|
let project = self.project.clone();
|
||||||
|
let status = semantic_index.read(cx).status(&project);
|
||||||
|
match status {
|
||||||
|
SemanticIndexStatus::Indexing {
|
||||||
|
rate_limit_expiry: Some(_),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
if self.maintain_rate_limit.is_none() {
|
||||||
|
self.maintain_rate_limit = Some(cx.spawn(|this, mut cx| async move {
|
||||||
|
loop {
|
||||||
|
cx.background().timer(Duration::from_secs(1)).await;
|
||||||
|
this.update(&mut cx, |_, cx| cx.notify()).log_err();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
self.maintain_rate_limit = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_codegen_changed(&mut self, _: ModelHandle<Codegen>, cx: &mut ViewContext<Self>) {
|
fn handle_codegen_changed(&mut self, _: ModelHandle<Codegen>, cx: &mut ViewContext<Self>) {
|
||||||
let is_read_only = !self.codegen.read(cx).idle();
|
let is_read_only = !self.codegen.read(cx).idle();
|
||||||
self.prompt_editor.update(cx, |editor, cx| {
|
self.prompt_editor.update(cx, |editor, cx| {
|
||||||
|
@ -3044,16 +3089,7 @@ impl InlineAssistant {
|
||||||
cx.emit(InlineAssistantEvent::RetrieveContextToggled {
|
cx.emit(InlineAssistantEvent::RetrieveContextToggled {
|
||||||
retrieve_context: this.retrieve_context,
|
retrieve_context: this.retrieve_context,
|
||||||
});
|
});
|
||||||
|
this.index_project(project, cx).log_err();
|
||||||
if this.retrieve_context {
|
|
||||||
let context_status = this.retrieve_context_status(cx);
|
|
||||||
if let Some(workspace) = this.workspace.upgrade(cx) {
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
|
||||||
workspace.show_toast(Toast::new(0, context_status), cx)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -3062,6 +3098,18 @@ impl InlineAssistant {
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn index_project(
|
||||||
|
&self,
|
||||||
|
project: ModelHandle<Project>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
if let Some(semantic_index) = self.semantic_index.clone() {
|
||||||
|
let _ = semantic_index.update(cx, |index, cx| index.index_project(project, cx));
|
||||||
|
}
|
||||||
|
|
||||||
|
anyhow::Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn retrieve_context_status(&self, cx: &mut ViewContext<Self>) -> String {
|
fn retrieve_context_status(&self, cx: &mut ViewContext<Self>) -> String {
|
||||||
let project = self.project.clone();
|
let project = self.project.clone();
|
||||||
if let Some(semantic_index) = self.semantic_index.clone() {
|
if let Some(semantic_index) = self.semantic_index.clone() {
|
||||||
|
@ -3072,23 +3120,23 @@ impl InlineAssistant {
|
||||||
"Not Authenticated!\nPlease ensure you have an `OPENAI_API_KEY` in your environment variables.".to_string()
|
"Not Authenticated!\nPlease ensure you have an `OPENAI_API_KEY` in your environment variables.".to_string()
|
||||||
}
|
}
|
||||||
semantic_index::SemanticIndexStatus::Indexed => {
|
semantic_index::SemanticIndexStatus::Indexed => {
|
||||||
"Indexing for Context Retrieval Complete!".to_string()
|
"Indexing Complete!".to_string()
|
||||||
}
|
}
|
||||||
semantic_index::SemanticIndexStatus::Indexing { remaining_files, rate_limit_expiry } => {
|
semantic_index::SemanticIndexStatus::Indexing { remaining_files, rate_limit_expiry } => {
|
||||||
|
|
||||||
let mut status = format!("Indexing for Context Retrieval...\nRemaining files to index: {remaining_files}");
|
let mut status = format!("Remaining files to index for Context Retrieval: {remaining_files}");
|
||||||
|
|
||||||
if let Some(rate_limit_expiry) = rate_limit_expiry {
|
if let Some(rate_limit_expiry) = rate_limit_expiry {
|
||||||
let remaining_seconds =
|
let remaining_seconds =
|
||||||
rate_limit_expiry.duration_since(Instant::now());
|
rate_limit_expiry.duration_since(Instant::now());
|
||||||
if remaining_seconds > Duration::from_secs(0) {
|
if remaining_seconds > Duration::from_secs(0) {
|
||||||
writeln!(status, "Rate limit resets in {}s", remaining_seconds.as_secs()).unwrap();
|
write!(status, " (rate limit resets in {}s)", remaining_seconds.as_secs()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
_ => {
|
semantic_index::SemanticIndexStatus::NotIndexed => {
|
||||||
"Indexing for Context Retrieval...\nRemaining files to index: 48".to_string()
|
"Not Indexed for Context Retrieval".to_string()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1191,6 +1191,7 @@ pub struct InlineAssistantStyle {
|
||||||
pub pending_edit_background: Color,
|
pub pending_edit_background: Color,
|
||||||
pub include_conversation: ToggleIconButtonStyle,
|
pub include_conversation: ToggleIconButtonStyle,
|
||||||
pub retrieve_context: ToggleIconButtonStyle,
|
pub retrieve_context: ToggleIconButtonStyle,
|
||||||
|
pub context_status: ContainedText,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
||||||
|
|
|
@ -79,6 +79,9 @@ export default function assistant(): any {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pending_edit_background: background(theme.highest, "positive"),
|
pending_edit_background: background(theme.highest, "positive"),
|
||||||
|
context_status: {
|
||||||
|
...text(theme.highest, "mono", "disabled", { size: "sm" }),
|
||||||
|
},
|
||||||
retrieve_context: toggleable({
|
retrieve_context: toggleable({
|
||||||
base: interactive({
|
base: interactive({
|
||||||
base: {
|
base: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue