ohos-libqos-sys 0.1.0

Raw bindings to the QoS (thread priority scheduling) API and Gewu on-device LLM inference APIs of OpenHarmony
Documentation
// automatically generated by rust-bindgen 0.71.1

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub const OH_QOS_GEWU_INVALID_SESSION_ID: OH_QoS_GewuSession = 0xffff_ffff;
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub const OH_QOS_GEWU_INVALID_REQUEST_ID: OH_QoS_GewuRequest = 0xffff_ffff;

#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl QoS_Level {
    /// Means the QoS level is background.
    pub const QOS_BACKGROUND: QoS_Level = QoS_Level(0);
    /// Means the QoS level is utility.
    pub const QOS_UTILITY: QoS_Level = QoS_Level(1);
    /// Means the QoS level is default.
    pub const QOS_DEFAULT: QoS_Level = QoS_Level(2);
    /// Means the QoS level is user-initiated.
    pub const QOS_USER_INITIATED: QoS_Level = QoS_Level(3);
    /// Means the QoS level is user-request.
    pub const QOS_DEADLINE_REQUEST: QoS_Level = QoS_Level(4);
    /// Means the QoS level is user-interactive.
    pub const QOS_USER_INTERACTIVE: QoS_Level = QoS_Level(5);
}
#[repr(transparent)]
/// Describes the level of QoS.
///
///
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct QoS_Level(pub ::core::ffi::c_uint);
/// Session id
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_QoS_GewuSession = ::core::ffi::c_uint;
/// Request id
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_QoS_GewuRequest = ::core::ffi::c_uint;
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_QoS_GewuResult = Result<(), OH_QoS_GewuErrorCode>;
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
impl OH_QoS_GewuErrorCode {
    pub const NOPERM: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(201).unwrap() });
    pub const NOMEM: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(203).unwrap() });
    pub const INVAL: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(401).unwrap() });
    pub const EXIST: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(501).unwrap() });
    pub const NOENT: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(502).unwrap() });
    pub const NOSYS: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(801).unwrap() });
    pub const FAULT: OH_QoS_GewuErrorCode =
        OH_QoS_GewuErrorCode(const { core::num::NonZero::new(901).unwrap() });
}
#[repr(transparent)]
/// Gewu error codes.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct OH_QoS_GewuErrorCode(pub core::num::NonZero<::core::ffi::c_uint>);
/// # Arguments
///
/// * `session` - The created session id
///
/// * `error` - Error code of CreateSession
/// - OH_QOS_GEWU_OK will be returned if the session is created successfully.
/// - OH_QOS_GEWU_NOMEM will be returned if the system does not have sufficient memory to
/// create the session.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OH_QoS_GewuCreateSessionResult {
    pub session: OH_QoS_GewuSession,
    pub error: OH_QoS_GewuResult,
}
/// # Arguments
///
/// * `request` - The created request id
///
/// * `error` - Error code of request submission.
/// - OH_QOS_GEWU_OK will be returned if the request is submitted successfully.
/// - OH_QOS_GEWU_NOMEM will be returned if the system does not have sufficient memory to
/// submit the request.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct OH_QoS_GewuSubmitRequestResult {
    pub request: OH_QoS_GewuRequest,
    pub error: OH_QoS_GewuResult,
}
/// Callback to receive response of the request.
///
/// # Arguments
///
/// * `context` - The user context specified when submitting the request.
///
/// * `reponse` - The json string of the response, including the following parameters:
/// - message: A message that contains the following fields.
/// - role: string. Must be "assistant".
/// - content: string. The message generated by the model in response to user messages.
/// - finish_reason: string or null. The reason the inference stopped. Possible values:
/// - null: Not finished yet, only present in streaming mode.
/// - "stop": The model stopped natually.
/// - "abort": The inference request was aborted.
/// - "length": The generated tokens reached the limit.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub type OH_QoS_GewuOnResponse = ::core::option::Option<
    unsafe extern "C" fn(context: *mut ::core::ffi::c_void, response: *const ::core::ffi::c_char),
>;
extern "C" {
    /// Set the QoS level of the current thread.
    ///
    /// # Arguments
    ///
    /// * `level` - Indicates the level to set. Specific level can be referenced [`QoS_Level`].
    ///
    /// # Returns
    ///
    /// * Returns 0 if the operation is successful; returns -1 if level is out of range or
    /// internal error failed.
    /// [`QoS_Level`]
    /// Available since API-level: 12
    #[cfg(feature = "api-12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
    pub fn OH_QoS_SetThreadQoS(level: QoS_Level) -> ::core::ffi::c_int;
    /// Cancel the QoS level of the current thread.
    ///
    ///
    /// # Returns
    ///
    /// * Returns 0 if the operation is successful; returns -1 if not set QoS for current thread
    /// or internal error failed.
    /// [`QoS_Level`]
    /// Available since API-level: 12
    #[cfg(feature = "api-12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
    pub fn OH_QoS_ResetThreadQoS() -> ::core::ffi::c_int;
    /// Obtains the QoS level of the current thread.
    ///
    /// # Arguments
    ///
    /// * `level` - This parameter is the output parameter,
    /// and the QoS level of the thread as a [`QoS_Level`] is written to this variable.
    ///
    /// # Returns
    ///
    /// * Returns 0 if the operation is successful; returns -1 if level is null, not
    /// set QoS for current thread or internal error failed.
    /// [`QoS_Level`]
    /// Available since API-level: 12
    #[cfg(feature = "api-12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
    pub fn OH_QoS_GetThreadQoS(level: *mut QoS_Level) -> ::core::ffi::c_int;
    /// Create a gewu session for inference.
    /// The lifecycle of the returned session object spans from the return of CreateSession
    /// to the call to DestroySession.
    ///
    /// json string of session attributes.
    ///
    /// The json string of session attributes include the following parameters
    /// - model: string. The directory of the model of the session.
    ///
    /// An example of json string of session attributes:
    /// ```json
    /// {
    /// "model": "/data/storage/el2/base/files/qwen2/"
    /// }
    /// ```
    ///
    /// # Arguments
    ///
    /// * `attributes` - The json string of session attributes.
    ///
    ///
    /// # Returns
    ///
    /// * Result of CreateSession.
    ///
    ///
    /// Available since API-level: 20
    #[cfg(feature = "api-20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
    pub fn OH_QoS_GewuCreateSession(
        attributes: *const ::core::ffi::c_char,
    ) -> OH_QoS_GewuCreateSessionResult;
    /// Destroy the specified session.
    /// It is recommended that the client shall wait until all ongoing requests are done before calling
    /// this interface to destroy the session. If there are remaining requests in the session when this
    /// interface is called, those requests will be aborted and no further responses for those requests
    /// will be sent to the client.
    /// Note that after calling this function successfully, the session cannot be used by the user code
    /// any more.
    ///
    /// # Arguments
    ///
    /// * `session` - The session that will be destroyed.
    ///
    ///
    /// # Returns
    ///
    /// * Error code.
    /// - OH_QOS_GEWU_OK will be returned if the session is destroyed successfully.
    /// - OH_QOS_GEWU_NOENT will be returned if the session is not found.
    ///
    ///
    /// Available since API-level: 20
    #[cfg(feature = "api-20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
    pub fn OH_QoS_GewuDestroySession(session: OH_QoS_GewuSession) -> OH_QoS_GewuResult;
    /// Abort the specified request.
    /// Note that after calling this function successfully, the client will not receive further responses
    /// for this request, and the request object cannot be used by the user code any more.
    ///
    /// # Arguments
    ///
    /// * `session` - The session that the request was submitted through.
    ///
    /// * `request` - The request object.
    ///
    ///
    /// # Returns
    ///
    /// * Error code.
    /// - OH_QOS_GEWU_OK will be returned if the request is aborted successfully.
    /// - OH_QOS_GEWU_NOENT will be returned if the request is not found.
    ///
    ///
    /// Available since API-level: 20
    #[cfg(feature = "api-20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
    pub fn OH_QoS_GewuAbortRequest(
        session: OH_QoS_GewuSession,
        request: OH_QoS_GewuRequest,
    ) -> OH_QoS_GewuResult;
    /// Submit a request.
    ///
    /// json string of completion request.
    /// Completion request is a json string that specifies the following parameters:
    /// - messages: array. A list of messages. Each message contains the following fields:
    /// - role: string. The message type, which could be one of the following:
    /// - "developer": Developer-provided instructions.
    /// - "user": User-provided instructions.
    /// - "assistant": Message generated by the model in response to user messages.
    /// - content: string. The message content.
    /// - stream: boolean or null; optional. Enable streaming mode or not. If set to true, partial
    /// responses will be sent. If null or not set, defaults to nonstreaming mode.
    ///
    /// An example of completion request:
    /// ```json
    /// {
    /// "messages": [
    /// {
    /// "role": "developer",
    /// "content": "Your are a helpful assistant."
    /// },
    /// {
    /// "role": "user",
    /// "content": "What is OpenHarmony"
    /// }
    /// ],
    /// "stream": true
    /// }
    /// ```
    ///
    /// # Arguments
    ///
    /// * `session` - The session object that the request should be submitted through.
    ///
    /// * `request` - The json string of request.
    ///
    /// * `callback` - The callback to receive response.
    ///
    /// * `context` - The user context that should be passed to the response callback.
    ///
    ///
    /// # Returns
    ///
    /// * Gewu request submission result.
    /// - OH_QOS_GEWU_OK will be returned if the request is accepted.
    /// - OH_QOS_GEWU_NOMEM will be returned if the system does not have sufficient memory
    /// to accept the request.
    ///
    ///
    /// Available since API-level: 20
    #[cfg(feature = "api-20")]
    #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
    pub fn OH_QoS_GewuSubmitRequest(
        session: OH_QoS_GewuSession,
        request: *const ::core::ffi::c_char,
        callback: OH_QoS_GewuOnResponse,
        context: *mut ::core::ffi::c_void,
    ) -> OH_QoS_GewuSubmitRequestResult;
}