@runanywhere/core 0.17.8 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -2
- package/RunAnywhereCore.podspec +1 -0
- package/android/CMakeLists.txt +24 -2
- package/android/build.gradle +61 -9
- package/android/src/main/cpp/cpp-adapter.cpp +51 -3
- package/android/src/main/include/rac/backends/rac_vlm_llamacpp.h +216 -0
- package/android/src/main/include/rac/core/capabilities/rac_lifecycle.h +3 -1
- package/android/src/main/include/rac/core/rac_core.h +11 -0
- package/android/src/main/include/rac/core/rac_types.h +8 -6
- package/android/src/main/include/rac/features/diffusion/rac_diffusion.h +22 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_component.h +263 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_model_registry.h +358 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_service.h +187 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_tokenizer.h +167 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_types.h +454 -0
- package/android/src/main/include/rac/features/llm/rac_tool_calling.h +373 -0
- package/android/src/main/include/rac/features/platform/rac_diffusion_platform.h +305 -0
- package/android/src/main/include/rac/features/vad/rac_vad_energy.h +1 -1
- package/android/src/main/include/rac/features/vlm/rac_vlm.h +16 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_component.h +168 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_service.h +206 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_types.h +417 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_registry.h +15 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_types.h +3 -0
- package/android/src/main/include/rac/utils/rac_image_utils.h +215 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/PlatformAdapterBridge.kt +201 -1
- package/android/src/main/jniLibs/arm64-v8a/libc++_shared.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libomp.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librac_commons.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librunanywhere_jni.so +0 -0
- package/android/src/main/jniLibs/x86_64/libc++_shared.so +0 -0
- package/android/src/main/jniLibs/x86_64/libomp.so +0 -0
- package/android/src/main/jniLibs/x86_64/librac_commons.so +0 -0
- package/android/src/main/jniLibs/x86_64/librunanywhere_jni.so +0 -0
- package/cpp/HybridRunAnywhereCore.cpp +263 -163
- package/cpp/HybridRunAnywhereCore.hpp +11 -0
- package/cpp/bridges/InitBridge.cpp +234 -3
- package/cpp/bridges/PlatformDownloadBridge.h +44 -0
- package/cpp/bridges/ToolCallingBridge.cpp +188 -0
- package/cpp/bridges/ToolCallingBridge.hpp +98 -0
- package/cpp/third_party/nlohmann/json.hpp +24765 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/RACommons.h +18 -4
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_core.h +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion.h +22 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_endpoints.h +3 -17
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_image_utils.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_lifecycle.h +3 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_assignment.h +4 -20
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_registry.h +15 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_types.h +3 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tool_calling.h +373 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_types.h +8 -6
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_energy.h +1 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm.h +16 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_component.h +168 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_service.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_types.h +417 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/RACommons +0 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/RACommons.h +18 -4
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_core.h +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion.h +22 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_endpoints.h +3 -17
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_image_utils.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_lifecycle.h +3 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_assignment.h +4 -20
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_registry.h +15 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_types.h +3 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tool_calling.h +373 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_types.h +8 -6
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_energy.h +1 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm.h +16 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_component.h +168 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_service.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_types.h +417 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/RACommons +0 -0
- package/ios/PlatformAdapterBridge.h +24 -1
- package/ios/PlatformAdapterBridge.m +243 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.hpp +4 -0
- package/package.json +8 -4
- package/src/Foundation/Security/SecureStorageService.ts +12 -6
- package/src/Public/Extensions/RunAnywhere+Models.ts +5 -3
- package/src/Public/Extensions/RunAnywhere+STT.ts +7 -2
- package/src/Public/Extensions/RunAnywhere+ToolCalling.ts +472 -0
- package/src/Public/Extensions/index.ts +16 -0
- package/src/Public/RunAnywhere.ts +18 -0
- package/src/index.ts +0 -1
- package/src/services/Network/index.ts +0 -1
- package/src/services/index.ts +0 -1
- package/src/specs/RunAnywhereCore.nitro.ts +72 -0
- package/src/types/ToolCallingTypes.ts +198 -0
- package/src/types/index.ts +13 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_vlm_component.h
|
|
3
|
+
* @brief RunAnywhere Commons - VLM Capability Component
|
|
4
|
+
*
|
|
5
|
+
* Actor-based VLM capability that owns model lifecycle and generation.
|
|
6
|
+
* Uses lifecycle manager for unified lifecycle + analytics handling.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef RAC_VLM_COMPONENT_H
|
|
10
|
+
#define RAC_VLM_COMPONENT_H
|
|
11
|
+
|
|
12
|
+
#include <RACommons/rac_lifecycle.h>
|
|
13
|
+
#include <RACommons/rac_error.h>
|
|
14
|
+
#include <RACommons/rac_vlm_types.h>
|
|
15
|
+
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
extern "C" {
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// VLM COMPONENT API
|
|
22
|
+
// =============================================================================
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @brief Create a VLM capability component
|
|
26
|
+
*
|
|
27
|
+
* @param out_handle Output: Handle to the component
|
|
28
|
+
* @return RAC_SUCCESS or error code
|
|
29
|
+
*/
|
|
30
|
+
RAC_API rac_result_t rac_vlm_component_create(rac_handle_t* out_handle);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @brief Configure the VLM component
|
|
34
|
+
*
|
|
35
|
+
* @param handle Component handle
|
|
36
|
+
* @param config Configuration
|
|
37
|
+
* @return RAC_SUCCESS or error code
|
|
38
|
+
*/
|
|
39
|
+
RAC_API rac_result_t rac_vlm_component_configure(rac_handle_t handle,
|
|
40
|
+
const rac_vlm_config_t* config);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @brief Check if model is loaded
|
|
44
|
+
*
|
|
45
|
+
* @param handle Component handle
|
|
46
|
+
* @return RAC_TRUE if loaded, RAC_FALSE otherwise
|
|
47
|
+
*/
|
|
48
|
+
RAC_API rac_bool_t rac_vlm_component_is_loaded(rac_handle_t handle);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @brief Get current model ID
|
|
52
|
+
*
|
|
53
|
+
* @param handle Component handle
|
|
54
|
+
* @return Current model ID (NULL if not loaded)
|
|
55
|
+
*/
|
|
56
|
+
RAC_API const char* rac_vlm_component_get_model_id(rac_handle_t handle);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @brief Load a VLM model
|
|
60
|
+
*
|
|
61
|
+
* @param handle Component handle
|
|
62
|
+
* @param model_path File path to the main model (LLM weights) - REQUIRED
|
|
63
|
+
* @param mmproj_path File path to the vision projector (required for llama.cpp, NULL for MLX)
|
|
64
|
+
* @param model_id Model identifier for telemetry (optional: if NULL, defaults to model_path)
|
|
65
|
+
* @param model_name Human-readable model name (optional: if NULL, defaults to model_id)
|
|
66
|
+
* @return RAC_SUCCESS or error code
|
|
67
|
+
*/
|
|
68
|
+
RAC_API rac_result_t rac_vlm_component_load_model(rac_handle_t handle, const char* model_path,
|
|
69
|
+
const char* mmproj_path, const char* model_id,
|
|
70
|
+
const char* model_name);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @brief Unload the current model
|
|
74
|
+
*
|
|
75
|
+
* @param handle Component handle
|
|
76
|
+
* @return RAC_SUCCESS or error code
|
|
77
|
+
*/
|
|
78
|
+
RAC_API rac_result_t rac_vlm_component_unload(rac_handle_t handle);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @brief Cleanup and reset the component
|
|
82
|
+
*
|
|
83
|
+
* @param handle Component handle
|
|
84
|
+
* @return RAC_SUCCESS or error code
|
|
85
|
+
*/
|
|
86
|
+
RAC_API rac_result_t rac_vlm_component_cleanup(rac_handle_t handle);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @brief Cancel ongoing generation
|
|
90
|
+
*
|
|
91
|
+
* Best-effort cancellation.
|
|
92
|
+
*
|
|
93
|
+
* @param handle Component handle
|
|
94
|
+
* @return RAC_SUCCESS or error code
|
|
95
|
+
*/
|
|
96
|
+
RAC_API rac_result_t rac_vlm_component_cancel(rac_handle_t handle);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @brief Process an image with text prompt (non-streaming)
|
|
100
|
+
*
|
|
101
|
+
* @param handle Component handle
|
|
102
|
+
* @param image Image input
|
|
103
|
+
* @param prompt Text prompt
|
|
104
|
+
* @param options Generation options (can be NULL for defaults)
|
|
105
|
+
* @param out_result Output: Generation result
|
|
106
|
+
* @return RAC_SUCCESS or error code
|
|
107
|
+
*/
|
|
108
|
+
RAC_API rac_result_t rac_vlm_component_process(rac_handle_t handle, const rac_vlm_image_t* image,
|
|
109
|
+
const char* prompt, const rac_vlm_options_t* options,
|
|
110
|
+
rac_vlm_result_t* out_result);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @brief Check if streaming is supported
|
|
114
|
+
*
|
|
115
|
+
* @param handle Component handle
|
|
116
|
+
* @return RAC_TRUE if streaming supported, RAC_FALSE otherwise
|
|
117
|
+
*/
|
|
118
|
+
RAC_API rac_bool_t rac_vlm_component_supports_streaming(rac_handle_t handle);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @brief Process an image with streaming
|
|
122
|
+
*
|
|
123
|
+
* @param handle Component handle
|
|
124
|
+
* @param image Image input
|
|
125
|
+
* @param prompt Text prompt
|
|
126
|
+
* @param options Generation options (can be NULL for defaults)
|
|
127
|
+
* @param token_callback Called for each generated token
|
|
128
|
+
* @param complete_callback Called when generation completes
|
|
129
|
+
* @param error_callback Called on error
|
|
130
|
+
* @param user_data User context passed to callbacks
|
|
131
|
+
* @return RAC_SUCCESS or error code
|
|
132
|
+
*/
|
|
133
|
+
RAC_API rac_result_t rac_vlm_component_process_stream(
|
|
134
|
+
rac_handle_t handle, const rac_vlm_image_t* image, const char* prompt,
|
|
135
|
+
const rac_vlm_options_t* options, rac_vlm_component_token_callback_fn token_callback,
|
|
136
|
+
rac_vlm_component_complete_callback_fn complete_callback,
|
|
137
|
+
rac_vlm_component_error_callback_fn error_callback, void* user_data);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @brief Get lifecycle state
|
|
141
|
+
*
|
|
142
|
+
* @param handle Component handle
|
|
143
|
+
* @return Current lifecycle state
|
|
144
|
+
*/
|
|
145
|
+
RAC_API rac_lifecycle_state_t rac_vlm_component_get_state(rac_handle_t handle);
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @brief Get lifecycle metrics
|
|
149
|
+
*
|
|
150
|
+
* @param handle Component handle
|
|
151
|
+
* @param out_metrics Output: Lifecycle metrics
|
|
152
|
+
* @return RAC_SUCCESS or error code
|
|
153
|
+
*/
|
|
154
|
+
RAC_API rac_result_t rac_vlm_component_get_metrics(rac_handle_t handle,
|
|
155
|
+
rac_lifecycle_metrics_t* out_metrics);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @brief Destroy the VLM component
|
|
159
|
+
*
|
|
160
|
+
* @param handle Component handle
|
|
161
|
+
*/
|
|
162
|
+
RAC_API void rac_vlm_component_destroy(rac_handle_t handle);
|
|
163
|
+
|
|
164
|
+
#ifdef __cplusplus
|
|
165
|
+
}
|
|
166
|
+
#endif
|
|
167
|
+
|
|
168
|
+
#endif /* RAC_VLM_COMPONENT_H */
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_vlm_llamacpp.h
|
|
3
|
+
* @brief RunAnywhere Commons - LlamaCPP VLM Backend API
|
|
4
|
+
*
|
|
5
|
+
* Public C API for Vision Language Model inference using llama.cpp's
|
|
6
|
+
* multimodal (mtmd) capabilities. Supports 20+ VLM architectures including
|
|
7
|
+
* Qwen2-VL, Qwen2.5-VL, SmolVLM, LLaVA, MiniCPM-V, and more.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#ifndef RAC_VLM_LLAMACPP_H
|
|
11
|
+
#define RAC_VLM_LLAMACPP_H
|
|
12
|
+
|
|
13
|
+
#include <RACommons/rac_error.h>
|
|
14
|
+
#include <RACommons/rac_types.h>
|
|
15
|
+
#include <RACommons/rac_vlm.h>
|
|
16
|
+
|
|
17
|
+
#ifdef __cplusplus
|
|
18
|
+
extern "C" {
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// EXPORT MACRO
|
|
23
|
+
// =============================================================================
|
|
24
|
+
|
|
25
|
+
#if defined(RAC_LLAMACPP_BUILDING)
|
|
26
|
+
#if defined(_WIN32)
|
|
27
|
+
#define RAC_LLAMACPP_VLM_API __declspec(dllexport)
|
|
28
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
29
|
+
#define RAC_LLAMACPP_VLM_API __attribute__((visibility("default")))
|
|
30
|
+
#else
|
|
31
|
+
#define RAC_LLAMACPP_VLM_API
|
|
32
|
+
#endif
|
|
33
|
+
#else
|
|
34
|
+
#define RAC_LLAMACPP_VLM_API
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
// =============================================================================
|
|
38
|
+
// CONFIGURATION
|
|
39
|
+
// =============================================================================
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* LlamaCPP VLM-specific configuration.
|
|
43
|
+
*/
|
|
44
|
+
typedef struct rac_vlm_llamacpp_config {
|
|
45
|
+
/** Context size (0 = auto-detect from model) */
|
|
46
|
+
int32_t context_size;
|
|
47
|
+
|
|
48
|
+
/** Number of threads for CPU inference (0 = auto-detect) */
|
|
49
|
+
int32_t num_threads;
|
|
50
|
+
|
|
51
|
+
/** Number of layers to offload to GPU (Metal on iOS/macOS, -1 = all) */
|
|
52
|
+
int32_t gpu_layers;
|
|
53
|
+
|
|
54
|
+
/** Batch size for prompt processing */
|
|
55
|
+
int32_t batch_size;
|
|
56
|
+
|
|
57
|
+
/** Number of threads for vision encoder (0 = same as num_threads) */
|
|
58
|
+
int32_t vision_threads;
|
|
59
|
+
|
|
60
|
+
/** Use GPU for vision encoding */
|
|
61
|
+
rac_bool_t use_gpu_vision;
|
|
62
|
+
} rac_vlm_llamacpp_config_t;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Default LlamaCPP VLM configuration.
|
|
66
|
+
*/
|
|
67
|
+
static const rac_vlm_llamacpp_config_t RAC_VLM_LLAMACPP_CONFIG_DEFAULT = {
|
|
68
|
+
.context_size = 0, // Auto-detect
|
|
69
|
+
.num_threads = 0, // Auto-detect
|
|
70
|
+
.gpu_layers = -1, // All layers on GPU
|
|
71
|
+
.batch_size = 512, //
|
|
72
|
+
.vision_threads = 0, // Auto-detect
|
|
73
|
+
.use_gpu_vision = 1 // Use GPU for vision
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// =============================================================================
|
|
77
|
+
// LLAMACPP VLM-SPECIFIC API
|
|
78
|
+
// =============================================================================
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Creates a LlamaCPP VLM service.
|
|
82
|
+
*
|
|
83
|
+
* @param model_path Path to the GGUF LLM model file
|
|
84
|
+
* @param mmproj_path Path to the mmproj vision projector GGUF file
|
|
85
|
+
* @param config LlamaCPP-specific configuration (can be NULL for defaults)
|
|
86
|
+
* @param out_handle Output: Handle to the created service
|
|
87
|
+
* @return RAC_SUCCESS or error code
|
|
88
|
+
*/
|
|
89
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_create(const char* model_path,
|
|
90
|
+
const char* mmproj_path,
|
|
91
|
+
const rac_vlm_llamacpp_config_t* config,
|
|
92
|
+
rac_handle_t* out_handle);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Loads a VLM model into an existing service.
|
|
96
|
+
*
|
|
97
|
+
* @param handle Service handle
|
|
98
|
+
* @param model_path Path to the GGUF LLM model file
|
|
99
|
+
* @param mmproj_path Path to the mmproj vision projector GGUF file
|
|
100
|
+
* @param config LlamaCPP configuration (can be NULL)
|
|
101
|
+
* @return RAC_SUCCESS or error code
|
|
102
|
+
*/
|
|
103
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_load_model(
|
|
104
|
+
rac_handle_t handle, const char* model_path, const char* mmproj_path,
|
|
105
|
+
const rac_vlm_llamacpp_config_t* config);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Unloads the current model.
|
|
109
|
+
*
|
|
110
|
+
* @param handle Service handle
|
|
111
|
+
* @return RAC_SUCCESS or error code
|
|
112
|
+
*/
|
|
113
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_unload_model(rac_handle_t handle);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a model is loaded.
|
|
117
|
+
*
|
|
118
|
+
* @param handle Service handle
|
|
119
|
+
* @return RAC_TRUE if model is loaded, RAC_FALSE otherwise
|
|
120
|
+
*/
|
|
121
|
+
RAC_LLAMACPP_VLM_API rac_bool_t rac_vlm_llamacpp_is_model_loaded(rac_handle_t handle);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Processes an image with a text prompt (blocking).
|
|
125
|
+
*
|
|
126
|
+
* @param handle Service handle
|
|
127
|
+
* @param image Image input (file path, RGB pixels, or base64)
|
|
128
|
+
* @param prompt Text prompt
|
|
129
|
+
* @param options VLM generation options (can be NULL for defaults)
|
|
130
|
+
* @param out_result Output: Generation result (caller must free text with rac_free)
|
|
131
|
+
* @return RAC_SUCCESS or error code
|
|
132
|
+
*/
|
|
133
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_process(rac_handle_t handle,
|
|
134
|
+
const rac_vlm_image_t* image,
|
|
135
|
+
const char* prompt,
|
|
136
|
+
const rac_vlm_options_t* options,
|
|
137
|
+
rac_vlm_result_t* out_result);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Streaming callback for VLM generation.
|
|
141
|
+
*
|
|
142
|
+
* @param token Generated token string
|
|
143
|
+
* @param is_final Whether this is the final token
|
|
144
|
+
* @param user_data User-provided context
|
|
145
|
+
* @return RAC_TRUE to continue, RAC_FALSE to stop
|
|
146
|
+
*/
|
|
147
|
+
typedef rac_bool_t (*rac_vlm_llamacpp_stream_callback_fn)(const char* token, rac_bool_t is_final,
|
|
148
|
+
void* user_data);
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Processes an image with streaming callback.
|
|
152
|
+
*
|
|
153
|
+
* @param handle Service handle
|
|
154
|
+
* @param image Image input
|
|
155
|
+
* @param prompt Text prompt
|
|
156
|
+
* @param options VLM generation options
|
|
157
|
+
* @param callback Callback for each token
|
|
158
|
+
* @param user_data User context passed to callback
|
|
159
|
+
* @return RAC_SUCCESS or error code
|
|
160
|
+
*/
|
|
161
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_process_stream(
|
|
162
|
+
rac_handle_t handle, const rac_vlm_image_t* image, const char* prompt,
|
|
163
|
+
const rac_vlm_options_t* options, rac_vlm_llamacpp_stream_callback_fn callback, void* user_data);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Cancels ongoing generation.
|
|
167
|
+
*
|
|
168
|
+
* @param handle Service handle
|
|
169
|
+
*/
|
|
170
|
+
RAC_LLAMACPP_VLM_API void rac_vlm_llamacpp_cancel(rac_handle_t handle);
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Gets model information as JSON.
|
|
174
|
+
*
|
|
175
|
+
* @param handle Service handle
|
|
176
|
+
* @param out_json Output: JSON string (caller must free with rac_free)
|
|
177
|
+
* @return RAC_SUCCESS or error code
|
|
178
|
+
*/
|
|
179
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_get_model_info(rac_handle_t handle,
|
|
180
|
+
char** out_json);
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Destroys a LlamaCPP VLM service.
|
|
184
|
+
*
|
|
185
|
+
* @param handle Service handle to destroy
|
|
186
|
+
*/
|
|
187
|
+
RAC_LLAMACPP_VLM_API void rac_vlm_llamacpp_destroy(rac_handle_t handle);
|
|
188
|
+
|
|
189
|
+
// =============================================================================
|
|
190
|
+
// BACKEND REGISTRATION
|
|
191
|
+
// =============================================================================
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Registers the LlamaCPP VLM backend with the commons module and service registries.
|
|
195
|
+
*
|
|
196
|
+
* Should be called once during SDK initialization.
|
|
197
|
+
* This registers:
|
|
198
|
+
* - Module: "llamacpp_vlm" with VISION_LANGUAGE capability
|
|
199
|
+
* - Service provider: LlamaCPP VLM provider (priority 100)
|
|
200
|
+
*
|
|
201
|
+
* @return RAC_SUCCESS or error code
|
|
202
|
+
*/
|
|
203
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_backend_llamacpp_vlm_register(void);
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Unregisters the LlamaCPP VLM backend.
|
|
207
|
+
*
|
|
208
|
+
* @return RAC_SUCCESS or error code
|
|
209
|
+
*/
|
|
210
|
+
RAC_LLAMACPP_VLM_API rac_result_t rac_backend_llamacpp_vlm_unregister(void);
|
|
211
|
+
|
|
212
|
+
#ifdef __cplusplus
|
|
213
|
+
}
|
|
214
|
+
#endif
|
|
215
|
+
|
|
216
|
+
#endif /* RAC_VLM_LLAMACPP_H */
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_vlm_service.h
|
|
3
|
+
* @brief RunAnywhere Commons - VLM Service Interface
|
|
4
|
+
*
|
|
5
|
+
* Defines the generic VLM service API and vtable for multi-backend dispatch.
|
|
6
|
+
* Backends (LlamaCpp VLM, MLX VLM) implement the vtable and register
|
|
7
|
+
* with the service registry.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#ifndef RAC_VLM_SERVICE_H
|
|
11
|
+
#define RAC_VLM_SERVICE_H
|
|
12
|
+
|
|
13
|
+
#include <RACommons/rac_error.h>
|
|
14
|
+
#include <RACommons/rac_vlm_types.h>
|
|
15
|
+
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
extern "C" {
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// SERVICE VTABLE - Backend implementations provide this
|
|
22
|
+
// =============================================================================
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* VLM Service operations vtable.
|
|
26
|
+
* Each backend implements these functions and provides a static vtable.
|
|
27
|
+
*/
|
|
28
|
+
typedef struct rac_vlm_service_ops {
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the service with model path(s).
|
|
31
|
+
* @param impl Backend implementation handle
|
|
32
|
+
* @param model_path Path to the main model file (LLM weights)
|
|
33
|
+
* @param mmproj_path Path to vision projector (required for llama.cpp, NULL for MLX)
|
|
34
|
+
* @return RAC_SUCCESS or error code
|
|
35
|
+
*/
|
|
36
|
+
rac_result_t (*initialize)(void* impl, const char* model_path, const char* mmproj_path);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Process an image with a text prompt (blocking).
|
|
40
|
+
* @param impl Backend implementation handle
|
|
41
|
+
* @param image Image input
|
|
42
|
+
* @param prompt Text prompt
|
|
43
|
+
* @param options Generation options (can be NULL for defaults)
|
|
44
|
+
* @param out_result Output result (caller must free with rac_vlm_result_free)
|
|
45
|
+
* @return RAC_SUCCESS or error code
|
|
46
|
+
*/
|
|
47
|
+
rac_result_t (*process)(void* impl, const rac_vlm_image_t* image, const char* prompt,
|
|
48
|
+
const rac_vlm_options_t* options, rac_vlm_result_t* out_result);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Process an image with streaming callback.
|
|
52
|
+
* @param impl Backend implementation handle
|
|
53
|
+
* @param image Image input
|
|
54
|
+
* @param prompt Text prompt
|
|
55
|
+
* @param options Generation options (can be NULL for defaults)
|
|
56
|
+
* @param callback Token callback
|
|
57
|
+
* @param user_data User context for callback
|
|
58
|
+
* @return RAC_SUCCESS or error code
|
|
59
|
+
*/
|
|
60
|
+
rac_result_t (*process_stream)(void* impl, const rac_vlm_image_t* image, const char* prompt,
|
|
61
|
+
const rac_vlm_options_t* options,
|
|
62
|
+
rac_vlm_stream_callback_fn callback, void* user_data);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get service information.
|
|
66
|
+
* @param impl Backend implementation handle
|
|
67
|
+
* @param out_info Output info structure
|
|
68
|
+
* @return RAC_SUCCESS or error code
|
|
69
|
+
*/
|
|
70
|
+
rac_result_t (*get_info)(void* impl, rac_vlm_info_t* out_info);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Cancel ongoing generation.
|
|
74
|
+
* @param impl Backend implementation handle
|
|
75
|
+
* @return RAC_SUCCESS or error code
|
|
76
|
+
*/
|
|
77
|
+
rac_result_t (*cancel)(void* impl);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Cleanup/unload model (keeps service alive).
|
|
81
|
+
* @param impl Backend implementation handle
|
|
82
|
+
* @return RAC_SUCCESS or error code
|
|
83
|
+
*/
|
|
84
|
+
rac_result_t (*cleanup)(void* impl);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Destroy the service.
|
|
88
|
+
* @param impl Backend implementation handle
|
|
89
|
+
*/
|
|
90
|
+
void (*destroy)(void* impl);
|
|
91
|
+
} rac_vlm_service_ops_t;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* VLM Service instance.
|
|
95
|
+
* Contains vtable pointer and backend-specific implementation.
|
|
96
|
+
*/
|
|
97
|
+
typedef struct rac_vlm_service {
|
|
98
|
+
/** Vtable with backend operations */
|
|
99
|
+
const rac_vlm_service_ops_t* ops;
|
|
100
|
+
|
|
101
|
+
/** Backend-specific implementation handle */
|
|
102
|
+
void* impl;
|
|
103
|
+
|
|
104
|
+
/** Model ID for reference */
|
|
105
|
+
const char* model_id;
|
|
106
|
+
} rac_vlm_service_t;
|
|
107
|
+
|
|
108
|
+
// =============================================================================
|
|
109
|
+
// PUBLIC API - Generic service functions
|
|
110
|
+
// =============================================================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @brief Create a VLM service
|
|
114
|
+
*
|
|
115
|
+
* Routes through service registry to find appropriate backend.
|
|
116
|
+
*
|
|
117
|
+
* @param model_id Model identifier (registry ID or path to model file)
|
|
118
|
+
* @param out_handle Output: Handle to the created service
|
|
119
|
+
* @return RAC_SUCCESS or error code
|
|
120
|
+
*/
|
|
121
|
+
RAC_API rac_result_t rac_vlm_create(const char* model_id, rac_handle_t* out_handle);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @brief Initialize a VLM service with model paths
|
|
125
|
+
*
|
|
126
|
+
* @param handle Service handle
|
|
127
|
+
* @param model_path Path to the main model file
|
|
128
|
+
* @param mmproj_path Path to vision projector (can be NULL for some backends)
|
|
129
|
+
* @return RAC_SUCCESS or error code
|
|
130
|
+
*/
|
|
131
|
+
RAC_API rac_result_t rac_vlm_initialize(rac_handle_t handle, const char* model_path,
|
|
132
|
+
const char* mmproj_path);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @brief Process an image with a text prompt
|
|
136
|
+
*
|
|
137
|
+
* @param handle Service handle
|
|
138
|
+
* @param image Image input
|
|
139
|
+
* @param prompt Text prompt describing what to analyze
|
|
140
|
+
* @param options Generation options (can be NULL for defaults)
|
|
141
|
+
* @param out_result Output: Generation result (caller must free with rac_vlm_result_free)
|
|
142
|
+
* @return RAC_SUCCESS or error code
|
|
143
|
+
*/
|
|
144
|
+
RAC_API rac_result_t rac_vlm_process(rac_handle_t handle, const rac_vlm_image_t* image,
|
|
145
|
+
const char* prompt, const rac_vlm_options_t* options,
|
|
146
|
+
rac_vlm_result_t* out_result);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @brief Process an image with streaming response
|
|
150
|
+
*
|
|
151
|
+
* @param handle Service handle
|
|
152
|
+
* @param image Image input
|
|
153
|
+
* @param prompt Text prompt
|
|
154
|
+
* @param options Generation options (can be NULL for defaults)
|
|
155
|
+
* @param callback Callback for each generated token
|
|
156
|
+
* @param user_data User context passed to callback
|
|
157
|
+
* @return RAC_SUCCESS or error code
|
|
158
|
+
*/
|
|
159
|
+
RAC_API rac_result_t rac_vlm_process_stream(rac_handle_t handle, const rac_vlm_image_t* image,
|
|
160
|
+
const char* prompt, const rac_vlm_options_t* options,
|
|
161
|
+
rac_vlm_stream_callback_fn callback, void* user_data);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @brief Get service information
|
|
165
|
+
*
|
|
166
|
+
* @param handle Service handle
|
|
167
|
+
* @param out_info Output: Service information
|
|
168
|
+
* @return RAC_SUCCESS or error code
|
|
169
|
+
*/
|
|
170
|
+
RAC_API rac_result_t rac_vlm_get_info(rac_handle_t handle, rac_vlm_info_t* out_info);
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @brief Cancel ongoing generation
|
|
174
|
+
*
|
|
175
|
+
* @param handle Service handle
|
|
176
|
+
* @return RAC_SUCCESS or error code
|
|
177
|
+
*/
|
|
178
|
+
RAC_API rac_result_t rac_vlm_cancel(rac_handle_t handle);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @brief Cleanup and release model resources
|
|
182
|
+
*
|
|
183
|
+
* @param handle Service handle
|
|
184
|
+
* @return RAC_SUCCESS or error code
|
|
185
|
+
*/
|
|
186
|
+
RAC_API rac_result_t rac_vlm_cleanup(rac_handle_t handle);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @brief Destroy a VLM service instance
|
|
190
|
+
*
|
|
191
|
+
* @param handle Service handle to destroy
|
|
192
|
+
*/
|
|
193
|
+
RAC_API void rac_vlm_destroy(rac_handle_t handle);
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @brief Free a VLM result
|
|
197
|
+
*
|
|
198
|
+
* @param result Result to free
|
|
199
|
+
*/
|
|
200
|
+
RAC_API void rac_vlm_result_free(rac_vlm_result_t* result);
|
|
201
|
+
|
|
202
|
+
#ifdef __cplusplus
|
|
203
|
+
}
|
|
204
|
+
#endif
|
|
205
|
+
|
|
206
|
+
#endif /* RAC_VLM_SERVICE_H */
|