llm_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 llm_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 llm_chain::traits::Executor;
53        llm_chain_openai::chatgpt::Executor::new()
54    }};
55    (chatgpt, $options:expr) => {{
56        use llm_chain::traits::Executor;
57        llm_chain_openai::chatgpt::Executor::new_with_options($options)
58    }};
59    (llama) => {{
60        use llm_chain::traits::Executor;
61        llm_chain_llama::Executor::new()
62    }};
63    (llama, $options:expr) => {{
64        use llm_chain::traits::Executor;
65        llm_chain_llama::Executor::new_with_options($options)
66    }};
67    (local, $options:expr) => {{
68        use llm_chain::traits::Executor;
69        llm_chain_local::Executor::new_with_options($options)
70    }};
71    (mock) => {{
72        use llm_chain::traits::Executor;
73        llm_chain_mock::Executor::new()
74    }};
75    (sagemaker_endpoint, $options:expr) => {{
76        use llm_chain::traits::Executor;
77        llm_chain_sagemaker_endpoint::Executor::new_with_options($options)
78    }};
79}