|
34 | 34 | * |
35 | 35 | * Basic usage workflow: |
36 | 36 | * @code |
37 | | - * // 1. Create session |
| 37 | + * // 1. Create session with callback |
38 | 38 | * ml_lxm_session_h session; |
39 | | - * ml_lxm_session_create("/path/to/config.json", NULL, &session); |
| 39 | + * ml_lxm_session_create("/path/to/config.json", NULL, token_handler, NULL, &session); |
40 | 40 | * |
41 | 41 | * // 2. Create prompt |
42 | 42 | * ml_lxm_prompt_h prompt; |
43 | 43 | * ml_lxm_prompt_create(&prompt); |
44 | 44 | * ml_lxm_prompt_append_text(prompt, "Hello AI"); |
45 | 45 | * |
46 | | - * // 3. Set callback using ml_lxm_session_set_event_cb |
47 | | - * ml_lxm_session_set_event_cb(session, token_handler, NULL); |
48 | | - * |
49 | | - * // 4. Generate response with options |
| 46 | + * // 3. Generate response with options (callback is already set during session creation) |
50 | 47 | * ml_option_h options = NULL; |
51 | 48 | * ml_option_create(&options); |
52 | 49 | * ml_option_set(options, "temperature", g_strdup_printf("%f", 1.0), g_free); |
53 | 50 | * ml_option_set(options, "max_tokens", g_strdup_printf("%zu", (size_t)50), g_free); |
54 | 51 | * ml_lxm_session_respond(session, prompt, options); |
55 | 52 | * ml_option_destroy(options); |
56 | 53 | * |
57 | | - * // 5. Cleanup |
| 54 | + * // 4. Cleanup |
58 | 55 | * ml_lxm_prompt_destroy(prompt); |
59 | 56 | * ml_lxm_session_destroy(session); |
60 | 57 | * @endcode |
|
81 | 78 | * return -1; |
82 | 79 | * } |
83 | 80 | * |
84 | | - * // 1. Create session with config and instructions |
85 | | - * ret = ml_lxm_session_create("/path/to/config.json", "You are a helpful AI assistant", &session); |
| 81 | + * // 1. Create session with config, instructions, and callback |
| 82 | + * ret = ml_lxm_session_create("/path/to/config.json", "You are a helpful AI assistant", token_handler, NULL, &session); |
86 | 83 | * if (ret != ML_ERROR_NONE) { |
87 | 84 | * std::cout << "Failed to create session" << std::endl; |
88 | 85 | * return -1; |
|
105 | 102 | * return -1; |
106 | 103 | * } |
107 | 104 | * |
108 | | - * // 3. Set callback using ml_lxm_session_set_event_cb |
109 | | - * ret = ml_lxm_session_set_event_cb(session, token_handler, NULL); |
110 | | - * if (ret != ML_ERROR_NONE) { |
111 | | - * std::cout << "Failed to set callback" << std::endl; |
112 | | - * ml_lxm_prompt_destroy(prompt); |
113 | | - * ml_lxm_session_destroy(session); |
114 | | - * return -1; |
115 | | - * } |
116 | | - * |
117 | | - * // 4. Generate response with custom options |
| 105 | + * // 3. Generate response with custom options |
118 | 106 | * ml_option_h options = NULL; |
119 | 107 | * ml_option_create(&options); |
120 | 108 | * ml_option_set(options, "temperature", g_strdup_printf("%f", 1.2), g_free); |
|
128 | 116 | * } |
129 | 117 | * std::cout << std::endl; |
130 | 118 | * |
131 | | - * // 5. Cleanup |
| 119 | + * // 4. Cleanup |
132 | 120 | * ml_lxm_prompt_destroy(prompt); |
133 | 121 | * ml_lxm_session_destroy(session); |
134 | 122 | * |
@@ -198,13 +186,16 @@ int ml_lxm_check_availability (ml_lxm_availability_e * status); |
198 | 186 | typedef void *ml_lxm_session_h; |
199 | 187 |
|
200 | 188 | /** |
201 | | - * @brief Creates an LXM session. |
| 189 | + * @brief Creates an LXM session with mandatory callback. |
202 | 190 | * @param[in] config_path Path to configuration file. |
203 | 191 | * @param[in] instructions Initial instructions (optional). |
| 192 | + * @param[in] callback Callback function for session events (mandatory). |
| 193 | + * @param[in] user_data User data to be passed to the callback. |
204 | 194 | * @param[out] session Session handle. |
205 | 195 | * @return ML_ERROR_NONE on success. |
| 196 | + * @note The callback parameter is mandatory and will be set during session creation. |
206 | 197 | */ |
207 | | -int ml_lxm_session_create (const char *config_path, const char *instructions, ml_lxm_session_h * session); |
| 198 | +int ml_lxm_session_create (const char *config_path, const char *instructions, ml_service_event_cb callback, void *user_data, ml_lxm_session_h * session); |
208 | 199 |
|
209 | 200 | /** |
210 | 201 | * @brief Destroys an LXM session. |
@@ -256,15 +247,6 @@ int ml_lxm_prompt_destroy (ml_lxm_prompt_h prompt); |
256 | 247 | */ |
257 | 248 | int ml_lxm_session_set_instructions (ml_lxm_session_h session, const char *instructions); |
258 | 249 |
|
259 | | -/** |
260 | | - * @brief Sets the callback for LXM session events. |
261 | | - * @param[in] session Session handle. |
262 | | - * @param[in] callback Callback function for session events. |
263 | | - * @param[in] user_data User data to be passed to the callback. |
264 | | - * @return ML_ERROR_NONE on success. |
265 | | - * @note This function should be called once per session. Calling it multiple times will return an error. |
266 | | - */ |
267 | | -int ml_lxm_session_set_event_cb (ml_lxm_session_h session, ml_service_event_cb callback, void *user_data); |
268 | 250 |
|
269 | 251 | /** |
270 | 252 | * @brief Generates an token-streamed response. |
|
0 commit comments