pub struct ToolkitService { /* private fields */ }
Expand description
A service that manages and runs a Toolkit.
§Example
ⓘ
let mut service = ToolkitService::new("UNIFAI_TOOLKIT_API_KEY");
let info = ToolkitInfo {
name: "Echo Slam".to_string(),
description: "What's in, what's out.".to_string(),
};
service.update_info(info).await.unwrap();
service.add_action(EchoSlam);
let runner = service.start().await.unwrap();
let _ = runner.await.unwrap();
Implementations§
Source§impl ToolkitService
impl ToolkitService
Sourcepub fn new(api_key: &str) -> Self
pub fn new(api_key: &str) -> Self
Create a Toolkit service with Unifai API Key.
Examples found in repository?
examples/echo_toolkit.rs (line 70)
64async fn main() {
65 tracing_subscriber::fmt().init();
66
67 let unifai_toolkit_api_key =
68 env::var("UNIFAI_TOOLKIT_API_KEY").expect("UNIFAI_TOOLKIT_API_KEY not set");
69
70 let mut service = ToolkitService::new(&unifai_toolkit_api_key);
71
72 let info = ToolkitInfo {
73 name: "Echo Slam".to_string(),
74 description: "What's in, what's out.".to_string(),
75 };
76
77 service.update_info(info).await.unwrap();
78
79 service.add_action(EchoSlam);
80
81 let runner = service.start().await.unwrap();
82 let _ = runner.await.unwrap();
83}
Sourcepub async fn update_info(&self, info: ToolkitInfo) -> Result<(), ToolkitError>
pub async fn update_info(&self, info: ToolkitInfo) -> Result<(), ToolkitError>
Update Toolkit’s name and description.
Examples found in repository?
examples/echo_toolkit.rs (line 77)
64async fn main() {
65 tracing_subscriber::fmt().init();
66
67 let unifai_toolkit_api_key =
68 env::var("UNIFAI_TOOLKIT_API_KEY").expect("UNIFAI_TOOLKIT_API_KEY not set");
69
70 let mut service = ToolkitService::new(&unifai_toolkit_api_key);
71
72 let info = ToolkitInfo {
73 name: "Echo Slam".to_string(),
74 description: "What's in, what's out.".to_string(),
75 };
76
77 service.update_info(info).await.unwrap();
78
79 service.add_action(EchoSlam);
80
81 let runner = service.start().await.unwrap();
82 let _ = runner.await.unwrap();
83}
Sourcepub fn add_action(&mut self, action: impl Action + 'static)
pub fn add_action(&mut self, action: impl Action + 'static)
Add an action that implements the Action trait to be registered when starting.
Examples found in repository?
examples/echo_toolkit.rs (line 79)
64async fn main() {
65 tracing_subscriber::fmt().init();
66
67 let unifai_toolkit_api_key =
68 env::var("UNIFAI_TOOLKIT_API_KEY").expect("UNIFAI_TOOLKIT_API_KEY not set");
69
70 let mut service = ToolkitService::new(&unifai_toolkit_api_key);
71
72 let info = ToolkitInfo {
73 name: "Echo Slam".to_string(),
74 description: "What's in, what's out.".to_string(),
75 };
76
77 service.update_info(info).await.unwrap();
78
79 service.add_action(EchoSlam);
80
81 let runner = service.start().await.unwrap();
82 let _ = runner.await.unwrap();
83}
Sourcepub async fn start(
self,
) -> Result<JoinHandle<Result<(), ToolkitError>>, ToolkitError>
pub async fn start( self, ) -> Result<JoinHandle<Result<(), ToolkitError>>, ToolkitError>
Start the Toolkit service asynchronously.
Once the service is ready, it returns a JoinHandle that keeps the service alive.
Examples found in repository?
examples/echo_toolkit.rs (line 81)
64async fn main() {
65 tracing_subscriber::fmt().init();
66
67 let unifai_toolkit_api_key =
68 env::var("UNIFAI_TOOLKIT_API_KEY").expect("UNIFAI_TOOLKIT_API_KEY not set");
69
70 let mut service = ToolkitService::new(&unifai_toolkit_api_key);
71
72 let info = ToolkitInfo {
73 name: "Echo Slam".to_string(),
74 description: "What's in, what's out.".to_string(),
75 };
76
77 service.update_info(info).await.unwrap();
78
79 service.add_action(EchoSlam);
80
81 let runner = service.start().await.unwrap();
82 let _ = runner.await.unwrap();
83}
Auto Trait Implementations§
impl Freeze for ToolkitService
impl !RefUnwindSafe for ToolkitService
impl Send for ToolkitService
impl Sync for ToolkitService
impl Unpin for ToolkitService
impl !UnwindSafe for ToolkitService
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