forked from ggerganov/llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mike dupont
committed
Dec 9, 2023
1 parent
34cf9d6
commit da1d845
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <stdio.h> | ||
#include <string> | ||
#include <string.h> | ||
#include <metacall/metacall.h> | ||
#include <stdio.h> | ||
|
||
int sum(double a, double b) | ||
{ | ||
// Parameters to be passed to the sum function | ||
void * args[] = | ||
{ | ||
metacall_value_create_double(a), metacall_value_create_double(b) | ||
}; | ||
|
||
void * ret = NULL; | ||
|
||
// Call to sum function | ||
ret = metacallv("sum", args); | ||
|
||
// Clean up arguments | ||
for (size_t it = 0; it < sizeof(args) / sizeof(args[0]); ++it) | ||
{ | ||
metacall_value_destroy(args[it]); | ||
} | ||
|
||
if (ret == NULL) | ||
{ | ||
printf("Function sum returned: NULL\n"); | ||
return 1; | ||
} | ||
|
||
printf("Function sum returned: %f\n", metacall_value_to_double(ret)); | ||
|
||
// Clean up return value | ||
metacall_value_destroy(ret); | ||
|
||
return 0; | ||
} | ||
|
||
class Context { | ||
public: | ||
|
||
struct metacall_log_stdio_type log_stdio = { stdout }; | ||
void* handle = NULL; // function pointer | ||
}; | ||
|
||
static Context context; | ||
|
||
void process_output_plugin_metacall_init() | ||
{ | ||
|
||
|
||
printf(metacall_print_info()); | ||
|
||
// Define log stream | ||
if (metacall_log(METACALL_LOG_STDIO, (void *)&context.log_stdio) != 0) | ||
{ | ||
//return cleanup(1); | ||
} | ||
|
||
// Initialize MetaCall | ||
if (metacall_initialize() != 0) | ||
{ | ||
//return cleanup(2); | ||
} | ||
|
||
// Array of scripts to be loaded by MetaCall | ||
const char * js_scripts[] = | ||
{ | ||
"script.js" | ||
}; | ||
|
||
|
||
|
||
// Load scripts | ||
if (metacall_load_from_file("node", | ||
js_scripts, | ||
sizeof(js_scripts) / sizeof(js_scripts[0]), &context.handle) != 0) | ||
{ | ||
//return cleanup(3); | ||
//return "error loading"; | ||
} | ||
|
||
} | ||
|
||
|
||
std::string process_output_plugin_metacall(const std::string start, | ||
const std::string state, | ||
const std::string input) { | ||
|
||
// NodeJS | ||
|
||
// Execute sum function | ||
if (sum(3, 4) != 0) | ||
{ | ||
return "error executing"; | ||
} | ||
|
||
|
||
|
||
|
||
return "OK"; | ||
|
||
} | ||
|
||
|
||
void process_output_plugin_metacall_destroy() | ||
{ | ||
|
||
metacall_clear(context.handle); | ||
//if ( | ||
metacall_destroy(); | ||
//!= 0) | ||
//{ | ||
//return code != 0 ? -code : -255; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
void process_output_plugin_metacall_init(); | ||
void process_output_plugin_metacall_destroy(); | ||
|
||
std::string process_output_plugin_metacall(const std::string start, | ||
const std::string state, | ||
const std::string input); |