Change ToolOutput
to ToolView
(#11682)
Additionally, the internal `ToolView` trait used by the registry is now called `InternalToolView`. This should make it a bit easier to understand that the `ToolView` is intended for a `gpui::View` (implementing `Render`). It does still feel like more could be merged here but I think the built tools are now a bit clearer. Release Notes: - N/A
This commit is contained in:
parent
5515ba6043
commit
c71cfd5da4
5 changed files with 17 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assistant_tooling::{LanguageModelTool, ProjectContext, ToolOutput};
|
use assistant_tooling::{LanguageModelTool, ProjectContext, ToolView};
|
||||||
use editor::{
|
use editor::{
|
||||||
display_map::{BlockContext, BlockDisposition, BlockProperties, BlockStyle},
|
display_map::{BlockContext, BlockDisposition, BlockProperties, BlockStyle},
|
||||||
Editor, MultiBuffer,
|
Editor, MultiBuffer,
|
||||||
|
@ -230,7 +230,7 @@ impl Render for AnnotationResultView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolOutput for AnnotationResultView {
|
impl ToolView for AnnotationResultView {
|
||||||
type Input = AnnotationInput;
|
type Input = AnnotationInput;
|
||||||
type SerializedState = Option<String>;
|
type SerializedState = Option<String>;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use assistant_tooling::{LanguageModelTool, ProjectContext, ToolOutput};
|
use assistant_tooling::{LanguageModelTool, ProjectContext, ToolView};
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use gpui::{prelude::*, Model, Task, View, WeakView};
|
use gpui::{prelude::*, Model, Task, View, WeakView};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
|
@ -65,7 +65,7 @@ impl Render for CreateBufferView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolOutput for CreateBufferView {
|
impl ToolView for CreateBufferView {
|
||||||
type Input = CreateBufferInput;
|
type Input = CreateBufferInput;
|
||||||
|
|
||||||
type SerializedState = ();
|
type SerializedState = ();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assistant_tooling::{LanguageModelTool, ToolOutput};
|
use assistant_tooling::{LanguageModelTool, ToolView};
|
||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
use file_icons::FileIcons;
|
use file_icons::FileIcons;
|
||||||
use gpui::{prelude::*, AnyElement, Model, Task};
|
use gpui::{prelude::*, AnyElement, Model, Task};
|
||||||
|
@ -232,7 +232,7 @@ impl Render for ProjectIndexView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolOutput for ProjectIndexView {
|
impl ToolView for ProjectIndexView {
|
||||||
type Input = CodebaseQuery;
|
type Input = CodebaseQuery;
|
||||||
type SerializedState = SerializedState;
|
type SerializedState = SerializedState;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,6 @@ pub use attachment_registry::{
|
||||||
};
|
};
|
||||||
pub use project_context::ProjectContext;
|
pub use project_context::ProjectContext;
|
||||||
pub use tool_registry::{
|
pub use tool_registry::{
|
||||||
LanguageModelTool, SavedToolFunctionCall, ToolFunctionCall, ToolFunctionDefinition, ToolOutput,
|
LanguageModelTool, SavedToolFunctionCall, ToolFunctionCall, ToolFunctionDefinition,
|
||||||
ToolRegistry,
|
ToolRegistry, ToolView,
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,11 +31,11 @@ enum ToolFunctionCallState {
|
||||||
#[default]
|
#[default]
|
||||||
Initializing,
|
Initializing,
|
||||||
NoSuchTool,
|
NoSuchTool,
|
||||||
KnownTool(Box<dyn ToolView>),
|
KnownTool(Box<dyn InternalToolView>),
|
||||||
ExecutedTool(Box<dyn ToolView>),
|
ExecutedTool(Box<dyn InternalToolView>),
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ToolView {
|
trait InternalToolView {
|
||||||
fn view(&self) -> AnyView;
|
fn view(&self) -> AnyView;
|
||||||
fn generate(&self, project: &mut ProjectContext, cx: &mut WindowContext) -> String;
|
fn generate(&self, project: &mut ProjectContext, cx: &mut WindowContext) -> String;
|
||||||
fn try_set_input(&self, input: &str, cx: &mut WindowContext);
|
fn try_set_input(&self, input: &str, cx: &mut WindowContext);
|
||||||
|
@ -69,7 +69,7 @@ pub struct ToolFunctionDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LanguageModelTool {
|
pub trait LanguageModelTool {
|
||||||
type View: ToolOutput;
|
type View: ToolView;
|
||||||
|
|
||||||
/// Returns the name of the tool.
|
/// Returns the name of the tool.
|
||||||
///
|
///
|
||||||
|
@ -85,7 +85,7 @@ pub trait LanguageModelTool {
|
||||||
|
|
||||||
/// Returns the OpenAI Function definition for the tool, for direct use with OpenAI's API.
|
/// Returns the OpenAI Function definition for the tool, for direct use with OpenAI's API.
|
||||||
fn definition(&self) -> ToolFunctionDefinition {
|
fn definition(&self) -> ToolFunctionDefinition {
|
||||||
let root_schema = schema_for!(<Self::View as ToolOutput>::Input);
|
let root_schema = schema_for!(<Self::View as ToolView>::Input);
|
||||||
|
|
||||||
ToolFunctionDefinition {
|
ToolFunctionDefinition {
|
||||||
name: self.name(),
|
name: self.name(),
|
||||||
|
@ -98,7 +98,7 @@ pub trait LanguageModelTool {
|
||||||
fn view(&self, cx: &mut WindowContext) -> View<Self::View>;
|
fn view(&self, cx: &mut WindowContext) -> View<Self::View>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToolOutput: Render {
|
pub trait ToolView: Render {
|
||||||
/// The input type that will be passed in to `execute` when the tool is called
|
/// The input type that will be passed in to `execute` when the tool is called
|
||||||
/// by the language model.
|
/// by the language model.
|
||||||
type Input: DeserializeOwned + JsonSchema;
|
type Input: DeserializeOwned + JsonSchema;
|
||||||
|
@ -121,7 +121,7 @@ pub trait ToolOutput: Render {
|
||||||
struct RegisteredTool {
|
struct RegisteredTool {
|
||||||
enabled: AtomicBool,
|
enabled: AtomicBool,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
build_view: Box<dyn Fn(&mut WindowContext) -> Box<dyn ToolView>>,
|
build_view: Box<dyn Fn(&mut WindowContext) -> Box<dyn InternalToolView>>,
|
||||||
definition: ToolFunctionDefinition,
|
definition: ToolFunctionDefinition,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ impl ToolRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ToolOutput> ToolView for View<T> {
|
impl<T: ToolView> InternalToolView for View<T> {
|
||||||
fn view(&self) -> AnyView {
|
fn view(&self) -> AnyView {
|
||||||
self.clone().into()
|
self.clone().into()
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolOutput for WeatherView {
|
impl ToolView for WeatherView {
|
||||||
type Input = WeatherQuery;
|
type Input = WeatherQuery;
|
||||||
|
|
||||||
type SerializedState = WeatherResult;
|
type SerializedState = WeatherResult;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue