llm_chain/
executor.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Utilities for working with executors
//!
/// A macro that creates a new executor for a specified model.
///
/// This macro makes it easy to create a new executor for a specific model without having to
/// directly call the constructor functions of the respective executor structs. The macro
/// supports creating executors for ChatGPT and LLaMA models.
///
/// # Usage
///
/// ```ignore
/// # use llm_chain::executor;
/// executor!(); // Creates a ChatGPT executor with default options.
/// ```
///
/// # Examples
///
/// ```ignore
/// // Create a ChatGPT executor with default options.
/// let chatgpt_executor = executor!();
///
/// // Create a ChatGPT executor with custom per-executor options.
/// let chatgpt_executor_with_options = executor!(chatgpt, per_executor_options);
///
/// // Create a ChatGPT executor with custom per-executor and per-invocation options.
/// let chatgpt_executor_with_both_options = executor!(chatgpt, per_executor_options, per_invocation_options);
///
/// // Create a LLaMA executor with default options.
/// let llama_executor = executor!(llama);
///
/// // Create a LLaMA executor with custom per-executor options.
/// let llama_executor_with_options = executor!(llama, per_executor_options);
///
/// // Create a LLaMA executor with custom per-executor and per-invocation options.
/// let llama_executor_with_both_options = executor!(llama, per_executor_options, per_invocation_options);
/// ```
///
/// # Parameters
///
/// - `()` or `chatgpt`: Creates a ChatGPT executor with default options.
/// - `chatgpt, per_executor_options`: Creates a ChatGPT executor with custom per-executor options.
/// - `chatgpt, per_executor_options, per_invocation_options`: Creates a ChatGPT executor with custom per-executor and per-invocation options.
/// - `llama`: Creates a LLaMA executor with default options.
/// - `llama, per_executor_options`: Creates a LLaMA executor with custom per-executor options.
/// - `llama, per_executor_options, per_invocation_options`: Creates a LLaMA executor with custom per-executor and per-invocation options.s
#[macro_export]
macro_rules! executor {
    () => {
        executor!(chatgpt)
    };
    (chatgpt) => {{
        use llm_chain::traits::Executor;
        llm_chain_openai::chatgpt::Executor::new()
    }};
    (chatgpt, $options:expr) => {{
        use llm_chain::traits::Executor;
        llm_chain_openai::chatgpt::Executor::new_with_options($options)
    }};
    (llama) => {{
        use llm_chain::traits::Executor;
        llm_chain_llama::Executor::new()
    }};
    (llama, $options:expr) => {{
        use llm_chain::traits::Executor;
        llm_chain_llama::Executor::new_with_options($options)
    }};
    (local, $options:expr) => {{
        use llm_chain::traits::Executor;
        llm_chain_local::Executor::new_with_options($options)
    }};
    (mock) => {{
        use llm_chain::traits::Executor;
        llm_chain_mock::Executor::new()
    }};
    (sagemaker_endpoint, $options:expr) => {{
        use llm_chain::traits::Executor;
        llm_chain_sagemaker_endpoint::Executor::new_with_options($options)
    }};
}