ai_chain/executor.rs
1//! Utilities for working with executors
2//!
3/// A macro that creates a new executor for a specified model.
4///
5/// This macro makes it easy to create a new executor for a specific model without having to
6/// directly call the constructor functions of the respective executor structs. The macro
7/// supports creating executors for ChatGPT and LLaMA models.
8///
9/// # Usage
10///
11/// ```ignore
12/// # use ai_chain::executor;
13/// executor!(); // Creates a ChatGPT executor with default options.
14/// ```
15///
16/// # Examples
17///
18/// ```ignore
19/// // Create a ChatGPT executor with default options.
20/// let chatgpt_executor = executor!();
21///
22/// // Create a ChatGPT executor with custom per-executor options.
23/// let chatgpt_executor_with_options = executor!(chatgpt, per_executor_options);
24///
25/// // Create a ChatGPT executor with custom per-executor and per-invocation options.
26/// let chatgpt_executor_with_both_options = executor!(chatgpt, per_executor_options, per_invocation_options);
27///
28/// // Create a LLaMA executor with default options.
29/// let llama_executor = executor!(llama);
30///
31/// // Create a LLaMA executor with custom per-executor options.
32/// let llama_executor_with_options = executor!(llama, per_executor_options);
33///
34/// // Create a LLaMA executor with custom per-executor and per-invocation options.
35/// let llama_executor_with_both_options = executor!(llama, per_executor_options, per_invocation_options);
36/// ```
37///
38/// # Parameters
39///
40/// - `()` or `chatgpt`: Creates a ChatGPT executor with default options.
41/// - `chatgpt, per_executor_options`: Creates a ChatGPT executor with custom per-executor options.
42/// - `chatgpt, per_executor_options, per_invocation_options`: Creates a ChatGPT executor with custom per-executor and per-invocation options.
43/// - `llama`: Creates a LLaMA executor with default options.
44/// - `llama, per_executor_options`: Creates a LLaMA executor with custom per-executor options.
45/// - `llama, per_executor_options, per_invocation_options`: Creates a LLaMA executor with custom per-executor and per-invocation options.s
46#[macro_export]
47macro_rules! executor {
48 () => {
49 executor!(chatgpt)
50 };
51 (chatgpt) => {{
52 use ai_chain::traits::Executor;
53 ai_chain_openai::chatgpt::Executor::new()
54 }};
55 (chatgpt, $options:expr) => {{
56 use ai_chain::traits::Executor;
57 ai_chain_openai::chatgpt::Executor::new_with_options($options)
58 }};
59 (mooonshot) => {{
60 use ai_chain::traits::Executor;
61 ai_chain_moonshot::chatgpt::Executor::new()
62 }};
63 (mooonshot, $options:expr) => {{
64 use ai_chain::traits::Executor;
65 ai_chain_moonshot::chatgpt::Executor::new_with_options($options)
66 }};
67 (glm) => {{
68 use ai_chain::traits::Executor;
69 ai_chain_glm::chatgpt::Executor::new()
70 }};
71 (glm, $options:expr) => {{
72 use ai_chain::traits::Executor;
73 ai_chain_glm::chatgpt::Executor::new_with_options($options)
74 }};
75 (qwen) => {{
76 use ai_chain::traits::Executor;
77 ai_chain_qwen::chatgpt::Executor::new()
78 }};
79 (qwen, $options:expr) => {{
80 use ai_chain::traits::Executor;
81 ai_chain_qwen::chatgpt::Executor::new_with_options($options)
82 }};
83 (gemma, $options:expr) => {{
84 use ai_chain::traits::Executor;
85 ai_chain_gemma::Executor::new_with_options($options)
86 }};
87 (llama) => {{
88 use ai_chain::traits::Executor;
89 ai_chain_llama::Executor::new()
90 }};
91 (llama, $options:expr) => {{
92 use ai_chain::traits::Executor;
93 ai_chain_llama::Executor::new_with_options($options)
94 }};
95 (local, $options:expr) => {{
96 use ai_chain::traits::Executor;
97 ai_chain_local::Executor::new_with_options($options)
98 }};
99 (mock) => {{
100 use ai_chain::traits::Executor;
101 ai_chain_mock::Executor::new()
102 }};
103 (sagemaker_endpoint, $options:expr) => {{
104 use ai_chain::traits::Executor;
105 ai_chain_sagemaker_endpoint::Executor::new_with_options($options)
106 }};
107 (deno, $options:expr) => {{
108 use ai_chain::traits::Executor;
109 deno_executor::Executor::new_with_options($options)
110 }};
111 (wasmtime, $options:expr) => {{
112 use ai_chain::traits::Executor;
113 wasmtime_executor::Executor::new_with_options($options)
114 }};
115 (custom, $model:ident) => {{
116 use ai_chain::traits::Executor;
117 $model::chatgpt::Executor::new()
118 }};
119 (custom, $model:ident, $options:expr) => {{
120 use ai_chain::traits::Executor;
121 $model::chatgpt::Executor::new_with_options($options)
122 }};
123}