assistant_tool: Add a source
to the Tool
trait (#26471)
This PR adds a `source` method to the `Tool` trait. This will allow us to track where a tool is coming from. Release Notes: - N/A
This commit is contained in:
parent
2021ca5bff
commit
9cce5a650e
2 changed files with 21 additions and 2 deletions
|
@ -4,7 +4,7 @@ mod tool_working_set;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::{App, Entity, Task};
|
use gpui::{App, Entity, SharedString, Task};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
|
|
||||||
pub use crate::tool_registry::*;
|
pub use crate::tool_registry::*;
|
||||||
|
@ -14,6 +14,14 @@ pub fn init(cx: &mut App) {
|
||||||
ToolRegistry::default_global(cx);
|
ToolRegistry::default_global(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
pub enum ToolSource {
|
||||||
|
/// A native tool built-in to Zed.
|
||||||
|
Native,
|
||||||
|
/// A tool provided by a context server.
|
||||||
|
ContextServer { id: SharedString },
|
||||||
|
}
|
||||||
|
|
||||||
/// A tool that can be used by a language model.
|
/// A tool that can be used by a language model.
|
||||||
pub trait Tool: 'static + Send + Sync {
|
pub trait Tool: 'static + Send + Sync {
|
||||||
/// Returns the name of the tool.
|
/// Returns the name of the tool.
|
||||||
|
@ -22,6 +30,11 @@ pub trait Tool: 'static + Send + Sync {
|
||||||
/// Returns the description of the tool.
|
/// Returns the description of the tool.
|
||||||
fn description(&self) -> String;
|
fn description(&self) -> String;
|
||||||
|
|
||||||
|
/// Returns the source of the tool.
|
||||||
|
fn source(&self) -> ToolSource {
|
||||||
|
ToolSource::Native
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the JSON schema that describes the tool's input.
|
/// Returns the JSON schema that describes the tool's input.
|
||||||
fn input_schema(&self) -> serde_json::Value {
|
fn input_schema(&self) -> serde_json::Value {
|
||||||
serde_json::Value::Object(serde_json::Map::default())
|
serde_json::Value::Object(serde_json::Map::default())
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use assistant_tool::Tool;
|
use assistant_tool::{Tool, ToolSource};
|
||||||
use gpui::{App, Entity, Task};
|
use gpui::{App, Entity, Task};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
|
|
||||||
|
@ -37,6 +37,12 @@ impl Tool for ContextServerTool {
|
||||||
self.tool.description.clone().unwrap_or_default()
|
self.tool.description.clone().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn source(&self) -> ToolSource {
|
||||||
|
ToolSource::ContextServer {
|
||||||
|
id: self.server_id.clone().into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn input_schema(&self) -> serde_json::Value {
|
fn input_schema(&self) -> serde_json::Value {
|
||||||
match &self.tool.input_schema {
|
match &self.tool.input_schema {
|
||||||
serde_json::Value::Null => {
|
serde_json::Value::Null => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue