chatgpt/functions/traits.rs
1use schemars::JsonSchema;
2use serde::de::DeserializeOwned;
3
4// deserialize -> parsing result from API
5// schema -> providing description
6/// This trait represents an object containing ChatGPT function arguments.
7/// To use this trait, just derive [JsonSchema] and [Deserialize]
8pub trait FunctionArgument: DeserializeOwned + JsonSchema + Sized {}
9
10impl<T: DeserializeOwned + JsonSchema> FunctionArgument for T {}
11
12/// This trait represents a struct containing actual ChatGPT function handling logic
13#[async_trait::async_trait]
14pub trait CallableAsyncFunction<A> {
15 /// Invokes this function. This method should not be called outside of internal logic.
16 async fn invoke(arguments: A) -> crate::Result<serde_json::Value>;
17}