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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// ************************************************************************** //
// //
// ::: :::::::: //
// llm.rs :+: :+: :+: //
// +:+ +:+ +:+ //
// By: dfine <coding@dfine.tech> +#+ +:+ +#+ //
// +#+#+#+#+#+ +#+ //
// Created: 2025/05/10 19:12:36 by dfine #+# #+# //
// Updated: 2025/05/10 19:12:37 by dfine ### ########.fr //
// //
// ************************************************************************** //
use ;
use ;
use Error;
/// Sends a prompt to the OpenAI chat API and returns the generated response as a string.
///
/// This function uses the `async-openai` crate to interact with a chat completion endpoint
/// (e.g., GPT-4, GPT-4o, GPT-3.5-turbo). The base URL can be overridden via the
/// `OPENAI_BASE_URL` environment variable.
///
/// # Arguments
///
/// * `prompt` - The text prompt to send to the model.
/// * `model` - The model ID to use (e.g., `"gpt-4o"`, `"gpt-3.5-turbo"`).
/// * `max_token` - Maximum number of tokens allowed in the response.
///
/// # Returns
///
/// A `Result` containing the generated string response on success, or an error on failure.
///
/// # Errors
///
/// This function will return an error if the request fails, the environment variable
/// is misconfigured, or if the response cannot be parsed correctly.
///
/// # Example
///
/// ```no_run
/// use git_commit_helper::call_openai;
///
/// #[tokio::main]
/// async fn main() {
/// let prompt = "Summarize the following diff...";
/// let model = "gpt-4o";
/// let max_token = 2048;
///
/// match call_openai(prompt, model, max_token).await {
/// Ok(response) => println!("LLM response: {}", response),
/// Err(e) => eprintln!("Error calling OpenAI: {}", e),
/// }
/// }
/// ```
pub async
/// Sends a prompt to the Ollama API and returns the generated response as a string.
///
/// This function uses the `ollama_rs` crate to interact with Ollama's generation endpoint.
/// The base URL can be overridden via the `OLLAMA_BASE_URL` environment variable.
///
/// # Arguments
///
/// * `prompt` - The text prompt to send to the model.
/// * `model` - The model ID to use for the request.
/// * `_max_token` - Currently unused parameter (to maintain function signature consistency).
///
/// # Returns
///
/// A `Result` containing the generated string response on success, or an error on failure.
///
/// # Errors
///
/// This function will return an error if the request fails, the environment variable
/// is misconfigured, or if the response cannot be handled correctly.
pub async
pub async