1 /* 2 * Copyright (C) 2021-2023 Alibaba Group Holding Limited 3 */ 4 5 6 #include <stdio.h> 7 #include <string.h> 8 #include "ulog/ulog.h" 9 #include "aos/kernel.h" 10 #include "aiconfig.h" 11 #include "aiagent_service.h" 12 #include "aiagent_engine.h" 13 14 #define TAG "AIAGENT_SERVICE" 15 16 /* 17 * Initialize the ai agent service 18 */ aiagent_service_init(const char * engine_name,ai_model_t model)19int32_t aiagent_service_init(const char *engine_name, ai_model_t model) 20 { 21 aiagent_engine_t *eng = aiagent_engine_init(engine_name); 22 if (!eng) { 23 LOGE(TAG, "ai agent service init fail\n"); 24 return -1; 25 } 26 27 eng->model = model; 28 return 0; 29 } 30 31 /* 32 * Uninitialize the ai agent service 33 */ aiagent_service_uninit(void)34int32_t aiagent_service_uninit(void) 35 { 36 return aiagent_engine_uninit(); 37 } 38 39 /* 40 * Config the ai agent service 41 */ aiagent_service_config(ai_config_t * config)42void aiagent_service_config(ai_config_t *config) 43 { 44 aiagent_engine_config(config); 45 } 46 47 /* 48 * Do ai vision model inference 49 */ aiagent_service_model_infer(char * src1,char * src2,ai_engine_cb_t cb)50int32_t aiagent_service_model_infer(char *src1, char *src2, ai_engine_cb_t cb) 51 { 52 int32_t ret; 53 aiagent_engine_t *eng = aiagent_get_engine(); 54 if (!eng) { 55 LOGE(TAG, "aiagent get engine name fail\n"); 56 return -1; 57 } 58 59 eng->callback = cb; 60 eng->src1 = src1; 61 eng->src2 = src2; 62 ret = eng->ai_engine_model_infer(eng); 63 64 LOG("aiagent_service_model_infer done\n"); 65 return ret; 66 } 67 68 /* 69 * Get current ai agent model 70 */ aiagent_service_get_cur_model(void)71ai_model_t aiagent_service_get_cur_model(void) 72 { 73 aiagent_engine_t *eng = aiagent_get_engine(); 74 if (!eng) { 75 LOGE(TAG, "aiagent get engine name fail\n"); 76 return -1; 77 } 78 return eng->model; 79 } 80