pub struct ToolSchema {
pub name: String,
pub context: Value,
pub embedding_docs: Vec<String>,
}
Expand description
Embeddable document that is used as an intermediate representation of a tool when RAGging tools.
Fields§
§name: String
§context: Value
§embedding_docs: Vec<String>
Implementations§
Source§impl ToolSchema
impl ToolSchema
Sourcepub fn try_from(tool: &dyn ToolEmbeddingDyn) -> Result<Self, EmbedError>
pub fn try_from(tool: &dyn ToolEmbeddingDyn) -> Result<Self, EmbedError>
Convert item that implements ToolEmbeddingDyn to an ToolSchema.
§Example
use rig::{
completion::ToolDefinition,
embeddings::ToolSchema,
tool::{Tool, ToolEmbedding, ToolEmbeddingDyn},
};
use serde_json::json;
#[derive(Debug, thiserror::Error)]
#[error("Math error")]
struct NothingError;
#[derive(Debug, thiserror::Error)]
#[error("Init error")]
struct InitError;
struct Nothing;
impl Tool for Nothing {
const NAME: &'static str = "nothing";
type Error = NothingError;
type Args = ();
type Output = ();
async fn definition(&self, _prompt: String) -> ToolDefinition {
serde_json::from_value(json!({
"name": "nothing",
"description": "nothing",
"parameters": {}
}))
.expect("Tool Definition")
}
async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
Ok(())
}
}
impl ToolEmbedding for Nothing {
type InitError = InitError;
type Context = ();
type State = ();
fn init(_state: Self::State, _context: Self::Context) -> Result<Self, Self::InitError> {
Ok(Nothing)
}
fn embedding_docs(&self) -> Vec<String> {
vec!["Do nothing.".into()]
}
fn context(&self) -> Self::Context {}
}
let tool = ToolSchema::try_from(&Nothing).unwrap();
assert_eq!(tool.name, "nothing".to_string());
assert_eq!(tool.embedding_docs, vec!["Do nothing.".to_string()]);
Trait Implementations§
Source§impl Clone for ToolSchema
impl Clone for ToolSchema
Source§fn clone(&self) -> ToolSchema
fn clone(&self) -> ToolSchema
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for ToolSchema
impl Default for ToolSchema
Source§fn default() -> ToolSchema
fn default() -> ToolSchema
Returns the “default value” for a type. Read more
Source§impl Embed for ToolSchema
impl Embed for ToolSchema
fn embed(&self, embedder: &mut TextEmbedder) -> Result<(), EmbedError>
Source§impl PartialEq for ToolSchema
impl PartialEq for ToolSchema
Source§impl Serialize for ToolSchema
impl Serialize for ToolSchema
impl Eq for ToolSchema
impl StructuralPartialEq for ToolSchema
Auto Trait Implementations§
impl Freeze for ToolSchema
impl RefUnwindSafe for ToolSchema
impl Send for ToolSchema
impl Sync for ToolSchema
impl Unpin for ToolSchema
impl UnwindSafe for ToolSchema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more