├── .bazelrc ├── .bazelversion ├── .github └── workflows │ └── ci.yml ├── BUILD.bazel ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md ├── SETUP.md ├── WORKSPACE ├── bazel ├── BUILD ├── curl.BUILD ├── inja.BUILD └── llama_cpp.PATCH ├── genc ├── .cargo │ └── config.toml ├── BUILD ├── __init__.py ├── blazerc ├── c │ ├── interop │ │ └── oak │ │ │ ├── BUILD │ │ │ ├── oak_api.h │ │ │ └── oak_api_test.cc │ └── runtime │ │ ├── BUILD │ │ ├── c_api.cc │ │ ├── c_api.h │ │ ├── c_api_internal.h │ │ ├── c_api_macros.h │ │ ├── gc_buffer.cc │ │ └── gc_buffer.h ├── cc │ ├── authoring │ │ ├── BUILD │ │ ├── constructor.cc │ │ ├── constructor.h │ │ ├── constructor_bindings.cc │ │ ├── constructor_test.cc │ │ ├── smart_chain.cc │ │ ├── smart_chain.h │ │ ├── smart_chain_test.cc │ │ ├── tracing_context.cc │ │ └── tracing_context.h │ ├── base │ │ ├── BUILD │ │ ├── computation.cc │ │ ├── computation.h │ │ ├── computation_test.cc │ │ ├── context.cc │ │ ├── context.h │ │ ├── context_test.cc │ │ ├── read_file.cc │ │ ├── read_file.h │ │ ├── to_from_grpc_status.cc │ │ └── to_from_grpc_status.h │ ├── examples │ │ ├── BUILD │ │ ├── confidential_computing │ │ │ ├── BUILD │ │ │ ├── Dockerfile │ │ │ ├── build_image.sh │ │ │ ├── client.cc │ │ │ ├── config_environment.sh │ │ │ ├── create_debug_vm.sh │ │ │ ├── create_environment.sh │ │ │ ├── debug_attestation.cc │ │ │ ├── enter_tee.sh │ │ │ ├── push_image.sh │ │ │ ├── rebuild_image.sh │ │ │ └── ssh_into_vm.sh │ │ ├── custom_concurrency_interface.cc │ │ ├── executors │ │ │ ├── BUILD │ │ │ ├── android │ │ │ │ ├── BUILD │ │ │ │ ├── android_executor_stacks.cc │ │ │ │ └── android_executor_stacks.h │ │ │ ├── executor_bindings.cc │ │ │ ├── executor_stacks.cc │ │ │ ├── executor_stacks.h │ │ │ ├── executor_stacks_test.cc │ │ │ ├── java_executor_stacks.cc │ │ │ └── java_executor_stacks.h │ │ ├── math_tool_agent.cc │ │ ├── multivariate_prompt_template_test.cc │ │ ├── run_gemini_on_ai_studio.cc │ │ ├── run_gemini_on_vertex.cc │ │ ├── run_llama_on_vertex.cc │ │ ├── run_local_model_with_llamacpp.cc │ │ ├── run_openai.cc │ │ ├── run_wolfram.cc │ │ └── worker │ │ │ ├── BUILD │ │ │ ├── Dockerfile │ │ │ ├── README.md │ │ │ ├── client.cc │ │ │ └── server.cc │ ├── interop │ │ ├── backends │ │ │ ├── BUILD │ │ │ ├── google_ai.cc │ │ │ ├── google_ai.h │ │ │ ├── java │ │ │ │ ├── BUILD │ │ │ │ ├── google_ai.cc │ │ │ │ ├── google_ai.h │ │ │ │ ├── google_ai_client_jni.cc │ │ │ │ ├── google_ai_client_jni.h │ │ │ │ ├── mediapipe_llm_inference.cc │ │ │ │ ├── mediapipe_llm_inference.h │ │ │ │ ├── mediapipe_llm_inference_client_jni.cc │ │ │ │ ├── mediapipe_llm_inference_client_jni.h │ │ │ │ ├── open_ai.cc │ │ │ │ ├── open_ai.h │ │ │ │ ├── open_ai_client_jni.cc │ │ │ │ ├── open_ai_client_jni.h │ │ │ │ ├── wolfram_alpha_client_jni.cc │ │ │ │ ├── wolfram_alpha_client_jni.h │ │ │ │ ├── wolfram_alpha_handler.cc │ │ │ │ └── wolfram_alpha_handler.h │ │ │ ├── llamacpp.cc │ │ │ └── llamacpp.h │ │ ├── confidential_computing │ │ │ ├── BUILD │ │ │ ├── attestation.cc │ │ │ └── attestation.h │ │ ├── networking │ │ │ ├── BUILD │ │ │ ├── cronet_based_android_http_client.cc │ │ │ ├── cronet_based_android_http_client.h │ │ │ ├── curl_based_http_client.cc │ │ │ ├── curl_based_http_client.h │ │ │ └── http_client_interface.h │ │ └── oak │ │ │ ├── BUILD │ │ │ ├── attestation_provider.cc │ │ │ ├── attestation_provider.h │ │ │ ├── client.cc │ │ │ ├── client.h │ │ │ ├── server.cc │ │ │ └── server.h │ ├── intrinsics │ │ ├── BUILD │ │ ├── breakable_chain.cc │ │ ├── breakable_chain.h │ │ ├── conditional.cc │ │ ├── conditional.h │ │ ├── confidential_computation.cc │ │ ├── confidential_computation.h │ │ ├── custom_function.cc │ │ ├── custom_function.h │ │ ├── delegate.cc │ │ ├── delegate.h │ │ ├── fallback.cc │ │ ├── fallback.h │ │ ├── handler_sets.cc │ │ ├── handler_sets.h │ │ ├── inja_template.cc │ │ ├── inja_template.h │ │ ├── inja_template_test.cc │ │ ├── intrinsic_bindings.cc │ │ ├── intrinsic_uris.h │ │ ├── logger.cc │ │ ├── logger.h │ │ ├── logical_not.cc │ │ ├── logical_not.h │ │ ├── model_inference.cc │ │ ├── model_inference.h │ │ ├── model_inference_with_config.cc │ │ ├── model_inference_with_config.h │ │ ├── parallel_map.cc │ │ ├── parallel_map.h │ │ ├── prompt_template.cc │ │ ├── prompt_template.h │ │ ├── regex_partial_match.cc │ │ ├── regex_partial_match.h │ │ ├── repeat.cc │ │ ├── repeat.h │ │ ├── repeated_conditional_chain.cc │ │ ├── repeated_conditional_chain.h │ │ ├── rest_call.cc │ │ ├── rest_call.h │ │ ├── serial_chain.cc │ │ ├── serial_chain.h │ │ ├── while.cc │ │ └── while.h │ ├── modules │ │ ├── agents │ │ │ ├── BUILD │ │ │ ├── react.cc │ │ │ ├── react.h │ │ │ └── react_test.cc │ │ ├── parsers │ │ │ ├── BUILD │ │ │ ├── gemini_parser.cc │ │ │ ├── gemini_parser.h │ │ │ └── gemini_parser_test.cc │ │ ├── retrieval │ │ │ ├── BUILD │ │ │ ├── bi_map.h │ │ │ ├── bi_map_test.cc │ │ │ ├── local_cache.cc │ │ │ ├── local_cache.h │ │ │ └── local_cache_test.cc │ │ ├── templates │ │ │ ├── BUILD │ │ │ ├── inja_status_or.cc │ │ │ └── inja_status_or.h │ │ ├── tools │ │ │ ├── BUILD │ │ │ ├── curl_client.cc │ │ │ ├── curl_client.h │ │ │ ├── wolfram_alpha.cc │ │ │ └── wolfram_alpha.h │ │ └── worker │ │ │ ├── BUILD │ │ │ ├── run_server.cc │ │ │ └── run_server.h │ ├── runtime │ │ ├── BUILD │ │ ├── concurrency.h │ │ ├── concurrency_helpers.h │ │ ├── control_flow_executor.cc │ │ ├── control_flow_executor.h │ │ ├── control_flow_executor_test.cc │ │ ├── executor.cc │ │ ├── executor.h │ │ ├── executor_bindings.cc │ │ ├── executor_service.cc │ │ ├── executor_service.h │ │ ├── executor_stacks.cc │ │ ├── executor_stacks.h │ │ ├── executor_stacks_test.cc │ │ ├── executor_test.cc │ │ ├── inline_executor.cc │ │ ├── inline_executor.h │ │ ├── inline_executor_test.cc │ │ ├── intrinsic_handler.cc │ │ ├── intrinsic_handler.h │ │ ├── remote_executor.cc │ │ ├── remote_executor.h │ │ ├── runner.cc │ │ ├── runner.h │ │ ├── runner_test.cc │ │ ├── status_macros.h │ │ ├── threading.cc │ │ ├── threading.h │ │ └── threading_test.cc │ ├── testing │ │ ├── BUILD │ │ ├── testing_libs.cc │ │ ├── testing_libs.h │ │ └── testing_libs_test.cc │ └── types │ │ ├── BUILD │ │ ├── checking.cc │ │ ├── checking.h │ │ ├── checking_test.cc │ │ ├── inference.cc │ │ ├── inference.h │ │ └── inference_test.cc ├── docs │ ├── android_setup.md │ ├── api.md │ ├── architecture.md │ ├── bazel_plugin_installation.png │ ├── benefits.md │ ├── genc_project_import_in_android_studio.png │ ├── genc_run_configurations_android_studio.png │ ├── ir.md │ ├── models.md │ ├── runtime.md │ └── tutorials │ │ ├── BUILD.bazel │ │ ├── README.md │ │ ├── genc_app_icon.png │ │ ├── genc_app_response.png │ │ ├── genc_app_startup_screen.png │ │ ├── genc_on_device.png │ │ ├── genc_tee.png │ │ ├── jupyter_setup │ │ ├── BUILD.bazel │ │ ├── jupyter.py │ │ ├── launch_jupyter.sh │ │ └── openai_demo.ipynb │ │ ├── private_genai.png │ │ ├── server_log.png │ │ ├── tutorial_1_simple_cascade.ipynb │ │ ├── tutorial_2_custom_routing.ipynb │ │ ├── tutorial_3_custom_runtime.ipynb │ │ ├── tutorial_4_math_tool_agent.ipynb │ │ ├── tutorial_5_langchain_agent.ipynb │ │ ├── tutorial_6_confidential_computing.ipynb │ │ ├── tutorial_7_authoring.ipynb │ │ ├── tutorial_8_android.ipynb │ │ ├── tutorial_8_app_screenshot_1.png │ │ ├── tutorial_8_app_screenshot_2.png │ │ ├── tutorial_9_private_genai.ipynb │ │ ├── tutorial_9_screenshot_1.png │ │ └── tutorial_9_screenshot_2.png ├── java │ ├── BUILD │ └── src │ │ ├── java │ │ └── org │ │ │ └── genc │ │ │ ├── BUILD │ │ │ ├── authoring │ │ │ ├── BUILD │ │ │ └── Constructor.java │ │ │ ├── examples │ │ │ ├── BUILD │ │ │ ├── GeminiOnAiStudioDemo.java │ │ │ ├── GeminiOnVertexAiDemo.java │ │ │ ├── GencDemo.java │ │ │ ├── LocalModelWithLlamacpp.java │ │ │ ├── OpenAiDemo.java │ │ │ ├── WolframAlphaDemo.java │ │ │ ├── apps │ │ │ │ └── gencdemo │ │ │ │ │ ├── .blazeproject │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── BUILD │ │ │ │ │ ├── Computations.java │ │ │ │ │ ├── DefaultAndroidExecutor.java │ │ │ │ │ ├── GencDemo.java │ │ │ │ │ ├── lib │ │ │ │ │ ├── BUILD │ │ │ │ │ ├── jni.cc │ │ │ │ │ └── jni.lds │ │ │ │ │ └── res │ │ │ │ │ ├── layout │ │ │ │ │ └── activity_main.xml │ │ │ │ │ └── values │ │ │ │ │ └── strings.xml │ │ │ └── executors │ │ │ │ ├── BUILD │ │ │ │ └── DefaultExecutor.java │ │ │ ├── interop │ │ │ ├── backends │ │ │ │ ├── googleai │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── BUILD │ │ │ │ │ └── GoogleAiClient.java │ │ │ │ ├── mediapipe │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── BUILD │ │ │ │ │ └── LlmInferenceClient.java │ │ │ │ ├── openai │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── BUILD │ │ │ │ │ └── OpenAiClient.java │ │ │ │ └── wolframalpha │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── BUILD │ │ │ │ │ └── WolframAlphaClient.java │ │ │ └── network │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── BUILD │ │ │ │ ├── CronetEngineProvider.java │ │ │ │ ├── HttpClient.java │ │ │ │ ├── HttpClientImpl.java │ │ │ │ ├── HttpException.java │ │ │ │ ├── JavaHttpClientImpl.java │ │ │ │ ├── SimpleSynchronousHttpClientInterface.java │ │ │ │ └── api │ │ │ │ └── proto │ │ │ │ ├── BUILD │ │ │ │ └── http_request_response.proto │ │ │ └── runtime │ │ │ ├── BUILD │ │ │ ├── Executor.java │ │ │ ├── OwnedValueId.java │ │ │ ├── Runner.java │ │ │ ├── ToFromValueProto.java │ │ │ └── ValueId.java │ │ ├── javatests │ │ └── org │ │ │ └── genc │ │ │ └── interop │ │ │ ├── backends │ │ │ ├── googleai │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── BUILD │ │ │ │ └── GoogleAiClientTest.java │ │ │ ├── mediapipe │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── BUILD │ │ │ │ └── LlmInferenceClientTest.java │ │ │ ├── openai │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── BUILD │ │ │ │ └── OpenAiClientTest.java │ │ │ └── wolframalpha │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── BUILD │ │ │ │ └── WolframAlphaClientTest.java │ │ │ └── network │ │ │ ├── AndroidManifest.xml │ │ │ ├── BUILD │ │ │ └── HttpClientImplTest.java │ │ ├── jni │ │ ├── BUILD │ │ ├── jni_utils.cc │ │ └── jni_utils.h │ │ └── native │ │ └── org │ │ └── genc │ │ ├── authoring │ │ ├── BUILD │ │ └── constructor.cc │ │ ├── examples │ │ └── executors │ │ │ ├── BUILD │ │ │ └── default_executor.cc │ │ └── runtime │ │ ├── BUILD │ │ ├── executor.cc │ │ └── owned_value_id.cc ├── proto │ └── v0 │ │ ├── BUILD │ │ ├── computation.proto │ │ └── executor.proto ├── python │ ├── BUILD │ ├── __init__.py │ ├── authoring │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── computation_from_intrinsic.py │ │ ├── constructors.py │ │ ├── constructors_test.py │ │ ├── tracing_context.py │ │ ├── tracing_decorator.py │ │ ├── tracing_intrinsics.py │ │ └── tracing_test.py │ ├── base │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── computation.py │ │ ├── computation_test.py │ │ ├── context.py │ │ ├── context_test.py │ │ ├── embed.py │ │ ├── embed_test.py │ │ ├── to_from_value_proto.py │ │ └── to_from_value_proto_test.py │ ├── examples │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── authoring_demo.py │ │ ├── confidential_computing │ │ │ ├── BUILD │ │ │ └── client.py │ │ ├── executor.py │ │ ├── langchain_agent_demo.py │ │ ├── langchain_demo.py │ │ ├── math_tool_agent.py │ │ ├── openai_demo.py │ │ └── tools_wolfram_demo.py │ ├── interop │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── gemini │ │ │ ├── BUILD │ │ │ ├── __init__.py │ │ │ ├── create_config.py │ │ │ └── create_config_test.py │ │ ├── langchain │ │ │ ├── BUILD │ │ │ ├── __init__.py │ │ │ ├── create_computation.py │ │ │ ├── create_computation_test.py │ │ │ ├── custom_agent.py │ │ │ ├── custom_agent_test.py │ │ │ ├── custom_chain.py │ │ │ ├── custom_chain_test.py │ │ │ ├── custom_model.py │ │ │ ├── custom_model_test.py │ │ │ ├── custom_tool.py │ │ │ ├── custom_tool_test.py │ │ │ ├── model_cascade.py │ │ │ └── model_cascade_test.py │ │ └── llamacpp │ │ │ ├── BUILD │ │ │ ├── __init__.py │ │ │ ├── create_config.py │ │ │ ├── create_config_test.py │ │ │ ├── model_inference.py │ │ │ └── model_inference_test.py │ └── runtime │ │ ├── BUILD │ │ ├── __init__.py │ │ ├── runner.py │ │ ├── runner_test.py │ │ ├── synchronous_context.py │ │ └── synchronous_context_test.py ├── rust │ └── interop │ │ └── oak │ │ ├── BUILD │ │ ├── Cargo.toml │ │ └── src │ │ └── lib.rs └── wasm │ └── examples │ └── genc_demo │ ├── BUILD │ └── genc_demo.cc ├── genc_diagram.png ├── platform_mappings ├── platforms.bzl ├── requirements.txt └── setup_android_build_env.sh /.bazelversion: -------------------------------------------------------------------------------- 1 | 6.3.2 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | name: GenC Continuous Integration 15 | on: [pull_request] 16 | jobs: 17 | Continuous-Integration-Linux: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Check out repository code 21 | uses: actions/checkout@v4 22 | - name: Build Docker Container 23 | run: docker build -t ci:latest $PWD 24 | - name: Run CI 25 | run: docker run --rm -v $PWD:/genc ci:latest bash -c "cd genc; bash ./setup_android_build_env.sh ~/Android/Sdk ~/Android/Sdk/ndk-bundle r21e --accept-licenses; bazel build genc/...; bazel test genc/..." 26 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("//:platforms.bzl", "config_setting_and_platform") 16 | 17 | package( 18 | default_visibility = ["//visibility:public"], 19 | ) 20 | 21 | licenses(["notice"]) 22 | 23 | py_library( 24 | name = "python", 25 | srcs = ["__init__.py"], 26 | visibility = ["//visibility:private"], 27 | deps = [ 28 | "//genc/python/authoring", 29 | "//genc/python/examples", 30 | "//genc/python/interop", 31 | "//genc/python/runtime", 32 | ], 33 | ) 34 | 35 | # Generic Android 36 | config_setting( 37 | name = "android", 38 | constraint_values = [ 39 | "@platforms//os:android", 40 | ], 41 | visibility = ["//visibility:public"], 42 | ) 43 | 44 | # Android ARM64. 45 | config_setting_and_platform( 46 | name = "android_arm64", 47 | constraint_values = [ 48 | "@platforms//os:android", 49 | "@platforms//cpu:arm64", 50 | ], 51 | visibility = ["//visibility:public"], 52 | ) 53 | -------------------------------------------------------------------------------- /bazel/BUILD: -------------------------------------------------------------------------------- 1 | # Empty build file to allow referencing files from this directory 2 | package( 3 | default_visibility = ["//visibility:public"], 4 | ) 5 | 6 | licenses(["notice"]) 7 | -------------------------------------------------------------------------------- /bazel/inja.BUILD: -------------------------------------------------------------------------------- 1 | # BUILD for inja, a C++ template engine. 2 | 3 | cc_library( 4 | name = "inja", 5 | hdrs = ["include/inja/inja.hpp"], 6 | copts = ["-Wno-implicit-fallthrough"], 7 | deps = [ 8 | ":internal", 9 | "@nlohmann_json//:json", 10 | ], 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | cc_library( 15 | name = "internal", 16 | includes = ["include"], 17 | textual_hdrs = glob( 18 | ["include/inja/*.hpp"], 19 | exclude = ["include/inja/inja.hpp"], 20 | ), 21 | visibility = ["//visibility:private"], 22 | ) 23 | 24 | -------------------------------------------------------------------------------- /bazel/llama_cpp.PATCH: -------------------------------------------------------------------------------- 1 | Subject: [PATCH] Add Bazel files 2 | 3 | --- 4 | BUILD | 21 +++++++++++++++++++++ 5 | MODULE.bazel | 4 ++++ 6 | 2 files changed, 25 insertions(+) 7 | create mode 100644 BUILD 8 | create mode 100644 MODULE.bazel 9 | 10 | diff --git a/BUILD b/BUILD 11 | new file mode 100644 12 | index 0000000..cd47b1a 13 | --- /dev/null 14 | +++ b/BUILD 15 | @@ -0,0 +1,21 @@ 16 | +cc_library( 17 | + name = "llama_cpp", 18 | + visibility = ["//visibility:public"], 19 | + srcs = [ 20 | + "ggml.c", 21 | + "ggml-alloc.c", 22 | + "ggml-backend.c", 23 | + "ggml-quants.c", 24 | + "llama.cpp", 25 | + ], 26 | + hdrs = [ 27 | + "ggml.h", 28 | + "ggml-alloc.h", 29 | + "ggml-backend.h", 30 | + "ggml-backend-impl.h", 31 | + "ggml-impl.h", 32 | + "ggml-quants.h", 33 | + "llama.h", 34 | + "unicode.h", 35 | + ], 36 | +) 37 | diff --git a/MODULE.bazel b/MODULE.bazel 38 | new file mode 100644 39 | index 0000000..70ddc3d 40 | --- /dev/null 41 | +++ b/MODULE.bazel 42 | @@ -0,0 +1,4 @@ 43 | +module( 44 | + name = "llama_cpp", 45 | + repo_name = "org_llama_cpp", 46 | +) 47 | -- 48 | 2.43.0.472.g3155946c3a-goog 49 | -------------------------------------------------------------------------------- /genc/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License 14 | # ============================================================================== 15 | 16 | [target.x86_64-unknown-linux-gnu] 17 | rustflags = [ 18 | "-C", 19 | "link-args=-Xlinker --build-id=none", 20 | "-C", 21 | "target-cpu=x86-64-v3", 22 | "--cfg", 23 | "tokio_unstable", 24 | "link-arg=-Tlinker.ld", 25 | ] 26 | 27 | [build] 28 | target = "x86_64-unknown-linux-gnu" 29 | -------------------------------------------------------------------------------- /genc/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_library") 2 | 3 | # Package genc 4 | 5 | package( 6 | default_visibility = ["//visibility:public"], 7 | ) 8 | 9 | licenses(["notice"]) 10 | 11 | exports_files(["LICENSE"]) 12 | 13 | py_library( 14 | name = "genc", 15 | srcs = ["__init__.py"], 16 | visibility = ["//visibility:public"], 17 | deps = [ 18 | "//genc/python/authoring", 19 | "//genc/python/examples", 20 | "//genc/python/interop", 21 | "//genc/python/runtime", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /genc/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Top-level API for Python.""" 15 | 16 | # pylint: disable=g-importing-member 17 | from genc.python import authoring 18 | from genc.python import examples 19 | from genc.python import interop 20 | from genc.python import runtime 21 | # pylint: enable=g-importing-member 22 | 23 | del python # pylint: disable=undefined-variable 24 | -------------------------------------------------------------------------------- /genc/blazerc: -------------------------------------------------------------------------------- 1 | # Use full protos. Add this file's path in your ~/.blazerc. See b/339557508 for 2 | # instructions. 3 | build --config=force_full_protos 4 | -------------------------------------------------------------------------------- /genc/c/interop/oak/BUILD: -------------------------------------------------------------------------------- 1 | # C API for Oak. 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | cc_library( 10 | name = "oak_api", 11 | srcs = [], 12 | hdrs = ["oak_api.h"], 13 | deps = ["//genc/rust/interop/oak:oak_api"], 14 | ) 15 | 16 | cc_test( 17 | name = "oak_api_test", 18 | srcs = ["oak_api_test.cc"], 19 | deps = [ 20 | ":oak_api", 21 | "@com_google_googletest//:gtest_main", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /genc/c/interop/oak/oak_api_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "googletest/include/gtest/gtest.h" 17 | #include "genc/c/interop/oak/oak_api.h" 18 | 19 | namespace genc { 20 | namespace { 21 | 22 | TEST(OakApiTest, Something) { 23 | // TODO(b/333410413): Replace this with a real test that does something. 24 | OakHpkeKeyPair* x = oak_generate_hpke_key_pair(); 25 | EXPECT_TRUE(x != nullptr); 26 | oak_delete_hpke_key_pair(x); 27 | } 28 | 29 | } // namespace 30 | } // namespace genc 31 | -------------------------------------------------------------------------------- /genc/c/runtime/BUILD: -------------------------------------------------------------------------------- 1 | # C API for GenC. 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | cc_library( 10 | name = "c_api", 11 | srcs = ["c_api.cc"], 12 | hdrs = [ 13 | "c_api.h", 14 | ], 15 | deps = [ 16 | ":c_api_internal", 17 | ":c_api_macros_hdrs", 18 | ":gc_buffer", 19 | "//genc/cc/runtime:executor", 20 | "//genc/cc/runtime:executor_stacks", 21 | "//genc/proto/v0:computation_cc_proto", 22 | "//genc/proto/v0:executor_cc_proto", 23 | "@com_google_absl//absl/status:statusor", 24 | ], 25 | ) 26 | 27 | cc_library( 28 | name = "c_api_macros_hdrs", 29 | hdrs = [ 30 | "c_api_macros.h", 31 | ], 32 | ) 33 | 34 | cc_library( 35 | name = "gc_buffer", 36 | srcs = ["gc_buffer.cc"], 37 | hdrs = [ 38 | "gc_buffer.h", 39 | ], 40 | deps = [":c_api_macros_hdrs"], 41 | ) 42 | 43 | cc_library( 44 | name = "c_api_internal", 45 | hdrs = [ 46 | "c_api_internal.h", 47 | ], 48 | deps = [ 49 | "//genc/cc/runtime:executor", 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /genc/c/runtime/c_api_internal.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_C_RUNTIME_C_API_INTERNAL_H_ 17 | #define GENC_C_RUNTIME_C_API_INTERNAL_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "genc/cc/runtime/executor.h" 23 | 24 | struct GC_Executor { 25 | GC_Executor(std::shared_ptr e) 26 | : executor(e) {} 27 | 28 | std::shared_ptr executor; 29 | }; 30 | 31 | struct GC_OwnedValueId { 32 | GC_OwnedValueId(genc::OwnedValueId v) 33 | : owned_value_id(std::move(v)) {} 34 | 35 | genc::OwnedValueId owned_value_id; 36 | }; 37 | 38 | #endif // GENC_C_RUNTIME_C_API_INTERNAL_H_ 39 | -------------------------------------------------------------------------------- /genc/c/runtime/c_api_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_C_RUNTIME_C_API_MACROS_H_ 17 | #define GENC_C_RUNTIME_C_API_MACROS_H_ 18 | 19 | #ifdef SWIG 20 | #define GC_CAPI_EXPORT 21 | #else 22 | #if defined(_WIN32) 23 | #ifdef GC_COMPILE_LIBRARY 24 | #define GC_CAPI_EXPORT __declspec(dllexport) 25 | #else 26 | #define GC_CAPI_EXPORT __declspec(dllimport) 27 | #endif // GC_COMPILE_LIBRARY 28 | #else 29 | #ifdef GC_CAPI_WEAK 30 | #define GC_CAPI_EXPORT \ 31 | __attribute__((visibility("default"))) __attribute((weak)) 32 | #else 33 | #define GC_CAPI_EXPORT __attribute__((visibility("default"))) 34 | #endif // GC_CAPI_WEAK 35 | #endif // _WIN32 36 | #endif // SWIG 37 | 38 | #endif // GENC_C_RUNTIME_C_API_MACROS_H_ 39 | -------------------------------------------------------------------------------- /genc/c/runtime/gc_buffer.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/c/runtime/gc_buffer.h" 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | extern "C" { 25 | 26 | GC_Buffer* GC_NewBuffer() { return new GC_Buffer{nullptr, 0, nullptr}; } 27 | 28 | GC_Buffer* GC_NewBufferFromString(const void* proto, size_t proto_len) { 29 | void* copy = malloc(proto_len); 30 | if (copy == nullptr) { 31 | return nullptr; 32 | } 33 | std::memcpy(copy, proto, proto_len); 34 | GC_Buffer* buf = new GC_Buffer; 35 | buf->data = copy; 36 | buf->length = proto_len; 37 | buf->data_deallocator = [](void* data, size_t length) { free(data); }; 38 | return buf; 39 | } 40 | 41 | void GC_DeleteBuffer(GC_Buffer* buffer) { 42 | if (buffer == nullptr) return; 43 | if (buffer->data_deallocator != nullptr) { 44 | (*buffer->data_deallocator)(const_cast(buffer->data), 45 | buffer->length); 46 | } 47 | delete buffer; 48 | } 49 | 50 | GC_Buffer GC_GetBuffer(GC_Buffer* buffer) { return *buffer; } 51 | 52 | } // end extern "C" 53 | -------------------------------------------------------------------------------- /genc/cc/authoring/smart_chain.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/authoring/smart_chain.h" 17 | 18 | #include 19 | 20 | #include "absl/status/statusor.h" 21 | #include "genc/cc/authoring/constructor.h" 22 | #include "genc/cc/runtime/status_macros.h" 23 | #include "genc/proto/v0/computation.pb.h" 24 | 25 | namespace genc { 26 | 27 | absl::StatusOr SmartChain::Build() { 28 | v0::Value resulting_chain; 29 | if (num_iteration_ > 1) { 30 | resulting_chain = 31 | GENC_TRY(CreateRepeatedConditionalChain(num_iteration_, chained_ops_)); 32 | } else { 33 | resulting_chain = GENC_TRY(CreateSerialChain(chained_ops_)); 34 | } 35 | 36 | if (is_parallel_) { 37 | resulting_chain = GENC_TRY(CreateParallelMap(resulting_chain)); 38 | } 39 | return resulting_chain; 40 | } 41 | 42 | } // namespace genc 43 | -------------------------------------------------------------------------------- /genc/cc/base/computation.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/base/computation.h" 17 | 18 | #include 19 | 20 | #include "absl/status/statusor.h" 21 | #include "genc/cc/base/context.h" 22 | #include "genc/cc/runtime/status_macros.h" 23 | 24 | namespace genc { 25 | 26 | const v0::Value& Computation::portable_ir() { return portable_ir_; } 27 | 28 | absl::StatusOr Computation::operator()( 29 | const std::vector& args) { 30 | v0::Value result = 31 | GENC_TRY(GetContextStack()->CurrentContext()->Call(portable_ir_, args)); 32 | return Computation(result); 33 | } 34 | } // namespace genc 35 | -------------------------------------------------------------------------------- /genc/cc/base/computation.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_BASE_COMPUTATION_H_ 17 | #define GENC_CC_BASE_COMPUTATION_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | namespace genc { 25 | 26 | // Traced computation to provide make complex workflow authoring easier. 27 | class Computation { 28 | public: 29 | explicit Computation(const v0::Value& portable_ir) 30 | : portable_ir_(portable_ir) {} 31 | 32 | // Returns the PortableIR of the computation. 33 | const v0::Value& portable_ir(); 34 | 35 | // Calls the computation with args. 36 | // Provides a more convenient Python like syntax for authoring. 37 | absl::StatusOr operator()(const std::vector& args); 38 | 39 | private: 40 | v0::Value portable_ir_; 41 | }; 42 | 43 | } // namespace genc 44 | 45 | #endif // GENC_CC_BASE_COMPUTATION_H_ 46 | -------------------------------------------------------------------------------- /genc/cc/base/read_file.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "genc/cc/base/read_file.h" 21 | 22 | namespace genc { 23 | 24 | std::string ReadFile(std::string filename) { 25 | std::ifstream file {filename}; 26 | std::string content { 27 | std::istreambuf_iterator(file), std::istreambuf_iterator()}; 28 | return content; 29 | } 30 | 31 | } // namespace genc 32 | -------------------------------------------------------------------------------- /genc/cc/base/read_file.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_BASE_READ_FILE_H_ 17 | #define GENC_CC_BASE_READ_FILE_H_ 18 | 19 | #include 20 | 21 | namespace genc { 22 | 23 | std::string ReadFile(std::string filename); 24 | 25 | } // namespace genc 26 | 27 | #endif // GENC_CC_BASE_READ_FILE_H_ 28 | -------------------------------------------------------------------------------- /genc/cc/base/to_from_grpc_status.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include 17 | 18 | #include "absl/status/status.h" 19 | #include "genc/cc/base/to_from_grpc_status.h" 20 | #include "include/grpcpp/support/status.h" 21 | 22 | namespace genc { 23 | 24 | grpc::Status AbslToGrpcStatus(absl::Status status) { 25 | if (status.ok()) { 26 | return grpc::Status::OK; 27 | } else { 28 | return grpc::Status(static_cast(status.code()), 29 | std::string(status.message())); 30 | } 31 | } 32 | 33 | absl::Status GrpcToAbslStatus(grpc::Status status) { 34 | if (status.ok()) { 35 | return absl::OkStatus(); 36 | } else { 37 | return absl::Status(static_cast(status.error_code()), 38 | status.error_message()); 39 | } 40 | } 41 | 42 | } // namespace genc 43 | -------------------------------------------------------------------------------- /genc/cc/base/to_from_grpc_status.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_BASE_TO_FROM_GRPC_STATUS_H_ 17 | #define GENC_CC_BASE_TO_FROM_GRPC_STATUS_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "include/grpcpp/support/status.h" 21 | 22 | namespace genc { 23 | 24 | grpc::Status AbslToGrpcStatus(absl::Status status); 25 | absl::Status GrpcToAbslStatus(grpc::Status status); 26 | 27 | } // namespace genc 28 | 29 | #endif // GENC_CC_BASE_TO_FROM_GRPC_STATUS_H_ 30 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_binary( 8 | name = "client", 9 | srcs = ["client.cc"], 10 | deps = [ 11 | "//genc/cc/runtime:status_macros", 12 | "@com_github_grpc_grpc//:grpc++", 13 | "@com_google_absl//absl/flags:flag", 14 | "@com_google_absl//absl/flags:parse", 15 | "@com_google_absl//absl/status", 16 | "@com_google_absl//absl/status:statusor", 17 | "@com_google_absl//absl/strings", 18 | "@com_google_protobuf//:protobuf", 19 | "@oak//proto/session:service_unary_cc_grpc", 20 | ], 21 | ) 22 | 23 | cc_binary( 24 | name = "debug_attestation", 25 | srcs = ["debug_attestation.cc"], 26 | deps = [ 27 | "//genc/cc/interop/confidential_computing:attestation", 28 | "//genc/cc/interop/oak:attestation_provider", 29 | "//genc/cc/runtime:status_macros", 30 | "@com_google_absl//absl/flags:flag", 31 | "@com_google_absl//absl/flags:parse", 32 | "@com_google_absl//absl/status", 33 | "@com_google_absl//absl/status:statusor", 34 | "@oak//cc/crypto:common", 35 | "@oak//cc/crypto:encryption_key", 36 | "@oak//cc/crypto:server_encryptor", 37 | "@tink_cc//tink/jwt:verified_jwt", 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/build_image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Builds or rebuilds a worker image. 19 | 20 | source config_environment.sh 21 | 22 | docker build \ 23 | -t us-docker.pkg.dev/${WORKER_PROJECT}/${WORKER_REPO}/${WORKER_IMAGE}:latest \ 24 | . 25 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/config_environment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Configures the environment with project, VM, account, etc., names, for use 19 | # by all the included scripts. Note that these are just examples. You will need 20 | # to modify these names for use in your project. 21 | 22 | export WORKER_PROJECT="genc-testing" 23 | export WORKER_ZONE="us-west1-b" 24 | export WORKER_VM="worker" 25 | export WORKER_REPO="genc-repo" 26 | export WORKER_IMAGE="genc-cc" 27 | export WORKER_ACCOUNT="worker-account" 28 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/create_debug_vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Creates a debug VM on GCP with a Confidential Space image running a worker. 19 | 20 | source config_environment.sh 21 | 22 | gcloud compute instances create ${WORKER_VM} \ 23 | --confidential-compute \ 24 | --shielded-secure-boot \ 25 | --scopes=cloud-platform \ 26 | --zone=${WORKER_ZONE} \ 27 | --image-project=confidential-space-images \ 28 | --image-family=confidential-space-debug \ 29 | --metadata="^~^tee-image-reference=us-docker.pkg.dev/${WORKER_PROJECT}/${WORKER_REPO}/${WORKER_IMAGE}:latest~tee-container-log-redirect=true" \ 30 | --machine-type="n2d-standard-4" \ 31 | --min-cpu-platform="AMD Milan" \ 32 | --tags http-server,https-server \ 33 | --service-account=${WORKER_ACCOUNT}@${WORKER_PROJECT}.iam.gserviceaccount.com 34 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/enter_tee.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Enters the worker TEE, if running a debug image. To be executed once inside 19 | # the worker VM. 20 | 21 | sudo ctr task exec -t --exec-id shell tee-container bash 22 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/push_image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Pushes a worker image to GCP. 19 | 20 | source config_environment.sh 21 | 22 | docker push \ 23 | us-docker.pkg.dev/${WORKER_PROJECT}/${WORKER_REPO}/${WORKER_IMAGE}:latest 24 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/rebuild_image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Builds or rebuilds a worker image. 19 | 20 | source config_environment.sh 21 | 22 | docker build \ 23 | --no-cache \ 24 | -t us-docker.pkg.dev/${WORKER_PROJECT}/${WORKER_REPO}/${WORKER_IMAGE}:latest \ 25 | . 26 | -------------------------------------------------------------------------------- /genc/cc/examples/confidential_computing/ssh_into_vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2023, The GenC Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # ou may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License 16 | # ============================================================================== 17 | # 18 | # Creates a debug VM on GCP with a Confidential Space image running a worker. 19 | 20 | source config_environment.sh 21 | 22 | gcloud compute ssh \ 23 | --project ${WORKER_PROJECT} \ 24 | --zone ${WORKER_ZONE} \ 25 | ${WORKER_VM} 26 | -------------------------------------------------------------------------------- /genc/cc/examples/executors/android/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "android_executor_stacks", 9 | srcs = ["android_executor_stacks.cc"], 10 | hdrs = ["android_executor_stacks.h"], 11 | deps = [ 12 | "//genc/cc/authoring:constructor", 13 | "//genc/cc/interop/backends:llamacpp", 14 | "//genc/cc/interop/backends/java:google_ai", 15 | "//genc/cc/interop/backends/java:mediapipe_llm_inference", 16 | "//genc/cc/interop/backends/java:open_ai", 17 | "//genc/cc/interop/backends/java:wolfram_alpha_handler", 18 | "//genc/cc/interop/networking:cronet_based_android_http_client", 19 | "//genc/cc/intrinsics:handler_sets", 20 | "//genc/cc/intrinsics:model_inference", 21 | "//genc/cc/modules/agents:react", 22 | "//genc/cc/modules/retrieval:local_cache", 23 | "//genc/cc/runtime:executor", 24 | "//genc/cc/runtime:executor_stacks", 25 | "//genc/cc/runtime:status_macros", 26 | "//genc/java/src/jni:copy_jni_hdr_lib", 27 | "//genc/proto/v0:computation_cc_proto", 28 | "@bazel_tools//tools/jdk:jni", 29 | "@com_google_absl//absl/base", 30 | "@com_google_absl//absl/container:flat_hash_map", 31 | "@com_google_absl//absl/log", 32 | "@com_google_absl//absl/status", 33 | "@com_google_absl//absl/status:statusor", 34 | "@com_google_absl//absl/strings", 35 | ], 36 | alwayslink = 1, 37 | ) 38 | -------------------------------------------------------------------------------- /genc/cc/examples/executors/android/android_executor_stacks.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_EXAMPLES_EXECUTORS_ANDROID_ANDROID_EXECUTOR_STACKS_H_ 17 | #define GENC_CC_EXAMPLES_EXECUTORS_ANDROID_ANDROID_EXECUTOR_STACKS_H_ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "absl/status/statusor.h" 24 | #include "genc/cc/runtime/executor.h" 25 | 26 | namespace genc { 27 | 28 | absl::StatusOr> CreateAndroidExecutor( 29 | JavaVM* jvm, 30 | jobject open_ai_client, 31 | jobject google_ai_client, 32 | jobject mediapipe_text_generator_client, 33 | jobject wolfram_alpha_client, 34 | jobject simple_synchronous_http_client_interface); 35 | 36 | } // namespace genc 37 | 38 | #endif // GENC_CC_EXAMPLES_EXECUTORS_ANDROID_ANDROID_EXECUTOR_STACKS_H_ 39 | -------------------------------------------------------------------------------- /genc/cc/examples/executors/executor_stacks.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_EXAMPLES_EXECUTORS_EXECUTOR_STACKS_H_ 17 | #define GENC_CC_EXAMPLES_EXECUTORS_EXECUTOR_STACKS_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/concurrency.h" 23 | #include "genc/cc/runtime/executor.h" 24 | 25 | namespace genc { 26 | 27 | // Creates a default executors with out-of-box components initialized. 28 | // Use this for convenience that can run all the examples, tutorials. For 29 | // advanced uses, use CreateLocalExecutor to setup custom executors. 30 | absl::StatusOr> CreateDefaultExecutor(); 31 | 32 | absl::StatusOr> 33 | CreateDefaultExecutorWithConcurrencyInterface( 34 | std::shared_ptr concurrency_interface); 35 | 36 | } // namespace genc 37 | 38 | #endif // GENC_CC_EXAMPLES_EXECUTORS_EXECUTOR_STACKS_H_ 39 | -------------------------------------------------------------------------------- /genc/cc/examples/executors/java_executor_stacks.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_EXAMPLES_EXECUTORS_JAVA_EXECUTOR_STACKS_H_ 17 | #define GENC_CC_EXAMPLES_EXECUTORS_JAVA_EXECUTOR_STACKS_H_ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "absl/status/statusor.h" 24 | #include "genc/cc/runtime/executor.h" 25 | 26 | namespace genc { 27 | 28 | absl::StatusOr> CreateDefaultExecutor( 29 | JavaVM* jvm, jobject open_ai_client, jobject google_ai_client, 30 | jobject wolfram_alpha_client); 31 | 32 | } // namespace genc 33 | 34 | #endif // GENC_CC_EXAMPLES_EXECUTORS_JAVA_EXECUTOR_STACKS_H_ 35 | -------------------------------------------------------------------------------- /genc/cc/examples/worker/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_binary( 8 | name = "client", 9 | srcs = ["client.cc"], 10 | deps = [ 11 | "//genc/cc/base:read_file", 12 | "//genc/cc/interop/confidential_computing:attestation", 13 | "//genc/cc/interop/oak:client", 14 | "//genc/cc/runtime:executor", 15 | "//genc/cc/runtime:remote_executor", 16 | "//genc/cc/runtime:runner", 17 | "//genc/cc/runtime:status_macros", 18 | "//genc/cc/runtime:threading", 19 | "//genc/proto/v0:executor_cc_grpc_proto", 20 | "//genc/proto/v0:executor_cc_proto", 21 | "@com_github_grpc_grpc//:grpc++", 22 | "@com_google_absl//absl/flags:flag", 23 | "@com_google_absl//absl/flags:parse", 24 | "@com_google_absl//absl/status", 25 | "@com_google_absl//absl/status:statusor", 26 | "@com_google_protobuf//:protobuf", 27 | ], 28 | ) 29 | 30 | cc_binary( 31 | name = "server", 32 | srcs = ["server.cc"], 33 | deps = [ 34 | "//genc/cc/examples/executors:executor_stacks", 35 | "//genc/cc/modules/worker:run_server", 36 | "//genc/cc/runtime:executor", 37 | "//genc/cc/runtime:status_macros", 38 | "@com_google_absl//absl/flags:flag", 39 | "@com_google_absl//absl/flags:parse", 40 | "@com_google_absl//absl/status", 41 | "@com_google_absl//absl/status:statusor", 42 | "@com_google_absl//absl/strings", 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/BUILD: -------------------------------------------------------------------------------- 1 | # Libraries to access various LLM Backends. So user can stay backend agnostic. 2 | package( 3 | default_visibility = ["//visibility:public"], 4 | ) 5 | 6 | licenses(["notice"]) 7 | 8 | cc_library( 9 | name = "llamacpp", 10 | srcs = ["llamacpp.cc"], 11 | hdrs = ["llamacpp.h"], 12 | linkopts = [ 13 | "-lm", 14 | "-ldl", 15 | ], 16 | deps = [ 17 | "//genc/cc/intrinsics:model_inference", 18 | "//genc/cc/runtime:status_macros", 19 | "//genc/proto/v0:computation_cc_proto", 20 | "@com_google_absl//absl/log", 21 | "@com_google_absl//absl/status", 22 | "@com_google_absl//absl/status:statusor", 23 | "@com_google_absl//absl/strings", 24 | "@com_google_absl//absl/time", 25 | "@llama_cpp", 26 | ], 27 | alwayslink = 1, 28 | ) 29 | 30 | cc_library( 31 | name = "google_ai", 32 | srcs = ["google_ai.cc"], 33 | hdrs = ["google_ai.h"], 34 | deps = [ 35 | "//genc/cc/intrinsics:model_inference_with_config", 36 | "//genc/cc/modules/parsers:gemini_parser", 37 | "//genc/cc/modules/tools:curl_client", 38 | "//genc/cc/runtime:status_macros", 39 | "//genc/proto/v0:computation_cc_proto", 40 | "@com_google_absl//absl/status", 41 | "@com_google_absl//absl/status:statusor", 42 | "@com_google_absl//absl/strings", 43 | "@nlohmann_json//:json", 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/google_ai.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_BACKENDS_GOOGLE_AI_H_ 17 | #define GENC_CC_INTEROP_BACKENDS_GOOGLE_AI_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/cc/intrinsics/model_inference_with_config.h" 21 | #include "genc/proto/v0/computation.pb.h" 22 | namespace genc { 23 | 24 | // Backend for calling Google Model backends such as 25 | // https://platform.openai.com/docs/api-reference 26 | // https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini 27 | 28 | class GoogleAI final { 29 | public: 30 | ~GoogleAI() = default; 31 | 32 | // Not copyable or movable. 33 | GoogleAI(const GoogleAI&) = delete; 34 | GoogleAI& operator=(const GoogleAI&) = delete; 35 | 36 | // Sets the inference map to process model calls. 37 | static absl::Status SetInferenceMap( 38 | intrinsics::ModelInferenceWithConfig::InferenceMap& inference_map); 39 | 40 | private: 41 | // Do not hold states in this class. 42 | GoogleAI() = default; 43 | }; 44 | } // namespace genc 45 | 46 | #endif // GENC_CC_INTEROP_BACKENDS_GOOGLE_AI_H_ 47 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/google_ai.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_GOOGLE_AI_H_ 17 | #define GENC_CC_INTEROP_BACKENDS_JAVA_GOOGLE_AI_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | namespace genc { 25 | 26 | absl::StatusOr GoogleAiCall(JavaVM* jvm, jobject google_ai_client, 27 | const v0::Value& func, 28 | const v0::Value& arg); 29 | 30 | } // namespace genc 31 | 32 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_GOOGLE_AI_H_ 33 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/google_ai_client_jni.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_GOOGLEAI_JNI_GOOGLE_AI_CLIENT_JNI_H_ 17 | #define GENC_CC_INTEROP_BACKENDS_JAVA_GOOGLEAI_JNI_GOOGLE_AI_CLIENT_JNI_H_ 18 | 19 | #include 20 | 21 | #include 22 | 23 | namespace genc { 24 | 25 | std::string CallGoogleAiClient(JavaVM *jvm, jobject google_ai_client, 26 | std::string model_config, std::string request); 27 | 28 | } 29 | 30 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_GOOGLEAI_JNI_GOOGLE_AI_CLIENT_JNI_H_ 31 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/mediapipe_llm_inference.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_MEDIAPIPE_LLM_INFERENCE_H_ 16 | #define GENC_CC_INTEROP_BACKENDS_JAVA_MEDIAPIPE_LLM_INFERENCE_H_ 17 | 18 | #include 19 | 20 | #include "absl/status/statusor.h" 21 | #include "genc/proto/v0/computation.pb.h" 22 | 23 | namespace genc { 24 | 25 | absl::StatusOr MediapipeLlmInferenceCall( 26 | JavaVM* jvm, jobject llm_inference_client, const v0::Value& func, 27 | const v0::Value& arg); 28 | 29 | } // namespace genc 30 | 31 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_MEDIAPIPE_LLM_INFERENCE_H_ 32 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/mediapipe_llm_inference_client_jni.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_MEDIAPIPE_LLM_INFERENCE_CLIENT_JNI_H_ 16 | #define GENC_CC_INTEROP_BACKENDS_JAVA_MEDIAPIPE_LLM_INFERENCE_CLIENT_JNI_H_ 17 | 18 | #include 19 | 20 | #include 21 | 22 | namespace genc { 23 | 24 | std::string CallLlmInferenceClient(JavaVM *jvm, jobject llm_inference_client, 25 | std::string model_config, 26 | std::string request); 27 | 28 | } 29 | 30 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_MEDIAPIPE_LLM_INFERENCE_CLIENT_JNI_H_ 31 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/open_ai.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_OPEN_AI_H_ 17 | #define GENC_CC_INTEROP_BACKENDS_JAVA_OPEN_AI_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | namespace genc { 25 | 26 | absl::StatusOr OpenAiCall(JavaVM* jvm, jobject open_ai_client, 27 | const v0::Value& func, 28 | const v0::Value& arg); 29 | 30 | } // namespace genc 31 | 32 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_OPEN_AI_H_ 33 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/open_ai_client_jni.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_OPENAI_JNI_OPEN_AI_CLIENT_JNI_H_ 16 | #define GENC_CC_INTEROP_BACKENDS_JAVA_OPENAI_JNI_OPEN_AI_CLIENT_JNI_H_ 17 | 18 | #include 19 | 20 | #include 21 | 22 | namespace genc { 23 | 24 | std::string CallOpenAiClient(JavaVM *jvm, jobject open_ai_client, 25 | std::string model_config, std::string request); 26 | } 27 | 28 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_OPENAI_JNI_OPEN_AI_CLIENT_JNI_H_ 29 | -------------------------------------------------------------------------------- /genc/cc/interop/backends/java/wolfram_alpha_client_jni.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_BACKENDS_JAVA_WOLFRAM_ALPHA_CLIENT_JNI_H_ 17 | #define GENC_CC_INTEROP_BACKENDS_JAVA_WOLFRAM_ALPHA_CLIENT_JNI_H_ 18 | 19 | #include 20 | 21 | #include 22 | 23 | namespace genc { 24 | 25 | std::string CallWolframAlphaClient(JavaVM *jvm, jobject wolfram_alpha_client, 26 | std::string model_config, 27 | std::string request); 28 | 29 | } 30 | 31 | #endif // GENC_CC_INTEROP_BACKENDS_JAVA_WOLFRAM_ALPHA_CLIENT_JNI_H_ 32 | -------------------------------------------------------------------------------- /genc/cc/interop/confidential_computing/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "attestation", 9 | srcs = ["attestation.cc"], 10 | hdrs = ["attestation.h"], 11 | deps = [ 12 | "//genc/cc/interop/networking:curl_based_http_client", 13 | "//genc/cc/interop/networking:http_client_interface", 14 | "//genc/cc/interop/oak:attestation_provider", 15 | "//genc/cc/runtime:status_macros", 16 | "@com_google_absl//absl/memory", 17 | "@com_google_absl//absl/status", 18 | "@com_google_absl//absl/status:statusor", 19 | "@com_google_absl//absl/strings", 20 | "@nlohmann_json//:json", 21 | "@oak//cc/attestation/verification:attestation_verifier", 22 | "@oak//proto/attestation:evidence_cc_proto", 23 | "@oak//proto/session:messages_cc_proto", 24 | "@tink_cc//tink:keyset_handle", 25 | "@tink_cc//tink/config:global_registry", 26 | "@tink_cc//tink/jwt:jwk_set_converter", 27 | "@tink_cc//tink/jwt:jwt_public_key_verify", 28 | "@tink_cc//tink/jwt:jwt_signature_config", 29 | "@tink_cc//tink/jwt:jwt_validator", 30 | "@tink_cc//tink/jwt:verified_jwt", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /genc/cc/interop/networking/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "http_client_interface", 9 | srcs = [], 10 | hdrs = ["http_client_interface.h"], 11 | deps = [ 12 | "@com_google_absl//absl/status:statusor", 13 | "@com_google_absl//absl/strings", 14 | ], 15 | ) 16 | 17 | cc_library( 18 | name = "cronet_based_android_http_client", 19 | srcs = ["cronet_based_android_http_client.cc"], 20 | hdrs = ["cronet_based_android_http_client.h"], 21 | deps = [ 22 | ":http_client_interface", 23 | "//genc/java/src/jni:copy_jni_hdr_lib", 24 | "//genc/java/src/jni:jni_utils", 25 | "@bazel_tools//tools/jdk:jni", 26 | "@com_google_absl//absl/status", 27 | "@com_google_absl//absl/status:statusor", 28 | "@com_google_absl//absl/strings", 29 | ], 30 | alwayslink = 1, 31 | ) 32 | 33 | cc_library( 34 | name = "curl_based_http_client", 35 | srcs = ["curl_based_http_client.cc"], 36 | hdrs = ["curl_based_http_client.h"], 37 | deps = [ 38 | ":http_client_interface", 39 | "@com_google_absl//absl/memory", 40 | "@com_google_absl//absl/status", 41 | "@com_google_absl//absl/status:statusor", 42 | "@com_google_absl//absl/strings", 43 | "@curl", 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /genc/cc/interop/networking/cronet_based_android_http_client.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_NETWORKING_CRONET_BASED_ANDROID_HTTP_CLIENT_H_ 17 | #define GENC_CC_INTEROP_NETWORKING_CRONET_BASED_ANDROID_HTTP_CLIENT_H_ 18 | 19 | #include 20 | #include 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/interop/networking/http_client_interface.h" 23 | 24 | namespace genc { 25 | namespace interop { 26 | namespace networking { 27 | 28 | absl::StatusOr> 29 | CreateCronetBasedAndroidHttpClient( 30 | JavaVM* jvm, jobject simple_synchronous_http_client_interface); 31 | 32 | } // namespace networking 33 | } // namespace interop 34 | } // namespace genc 35 | 36 | #endif // GENC_CC_INTEROP_NETWORKING_CRONET_BASED_ANDROID_HTTP_CLIENT_H_ 37 | -------------------------------------------------------------------------------- /genc/cc/interop/networking/curl_based_http_client.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_NETWORKING_CURL_BASED_HTTP_CLIENT_H_ 17 | #define GENC_CC_INTEROP_NETWORKING_CURL_BASED_HTTP_CLIENT_H_ 18 | 19 | #include 20 | #include "absl/status/statusor.h" 21 | #include "genc/cc/interop/networking/http_client_interface.h" 22 | 23 | namespace genc { 24 | namespace interop { 25 | namespace networking { 26 | 27 | absl::StatusOr> CreateCurlBasedHttpClient( 28 | bool debug); 29 | 30 | } // namespace networking 31 | } // namespace interop 32 | } // namespace genc 33 | 34 | #endif // GENC_CC_INTEROP_NETWORKING_CURL_BASED_HTTP_CLIENT_H_ 35 | -------------------------------------------------------------------------------- /genc/cc/interop/oak/attestation_provider.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/interop/oak/attestation_provider.h" 17 | -------------------------------------------------------------------------------- /genc/cc/interop/oak/attestation_provider.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_OAK_ATTESTATION_PROVIDER_H_ 17 | #define GENC_CC_INTEROP_OAK_ATTESTATION_PROVIDER_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "proto/session/messages.pb.h" 23 | 24 | namespace genc { 25 | namespace interop { 26 | namespace oak { 27 | 28 | class AttestationProvider { 29 | public: 30 | virtual absl::StatusOr<::oak::session::v1::EndorsedEvidence> 31 | GetEndorsedEvidence(const std::string& serialized_public_key) = 0; 32 | 33 | virtual ~AttestationProvider() {} 34 | }; 35 | 36 | } // namespace oak 37 | } // namespace interop 38 | } // namespace genc 39 | 40 | #endif // GENC_CC_INTEROP_OAK_ATTESTATION_PROVIDER_H_ 41 | -------------------------------------------------------------------------------- /genc/cc/interop/oak/client.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_OAK_CLIENT_H_ 17 | #define GENC_CC_INTEROP_OAK_CLIENT_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/proto/v0/executor.grpc.pb.h" 23 | #include "include/grpcpp/channel.h" 24 | #include "cc/attestation/verification/attestation_verifier.h" 25 | 26 | namespace genc { 27 | namespace interop { 28 | namespace oak { 29 | 30 | // Creates an Oak client that implements the GenC `Executor` stub interface. 31 | absl::StatusOr> CreateClient( 32 | std::shared_ptr channel, 33 | std::shared_ptr<::oak::attestation::verification::AttestationVerifier> 34 | attestation_verifier, 35 | bool debug); 36 | 37 | } // namespace oak 38 | } // namespace interop 39 | } // namespace genc 40 | 41 | #endif // GENC_CC_INTEROP_OAK_CLIENT_H_ 42 | -------------------------------------------------------------------------------- /genc/cc/interop/oak/server.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTEROP_OAK_SERVER_H_ 17 | #define GENC_CC_INTEROP_OAK_SERVER_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/interop/oak/attestation_provider.h" 23 | #include "genc/proto/v0/executor.grpc.pb.h" 24 | #include "proto/session/service_unary.grpc.pb.h" 25 | 26 | namespace genc { 27 | namespace interop { 28 | namespace oak { 29 | 30 | // Creates an Oak transport-compatible service endpoint. 31 | absl::StatusOr> 32 | CreateService( 33 | std::shared_ptr executor_service, 34 | std::shared_ptr attestation_provider, 35 | bool debug = false); 36 | 37 | } // namespace oak 38 | } // namespace interop 39 | } // namespace genc 40 | 41 | #endif // GENC_CC_INTEROP_OAK_SERVER_H_ 42 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/breakable_chain.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License 11 | ==============================================================================*/ 12 | 13 | #include 14 | 15 | #include "absl/status/status.h" 16 | #include "absl/status/statusor.h" 17 | #include "genc/cc/intrinsics/intrinsic_uris.h" 18 | #include "genc/cc/runtime/intrinsic_handler.h" 19 | #include "genc/proto/v0/computation.pb.h" 20 | 21 | 22 | #ifndef GENC_CC_INTRINSICS_BREAKABLE_CHAIN_H_ 23 | #define GENC_CC_INTRINSICS_BREAKABLE_CHAIN_H_ 24 | 25 | namespace genc { 26 | namespace intrinsics { 27 | class BreakableChain : public ControlFlowIntrinsicHandlerBase { 28 | public: 29 | BreakableChain() : ControlFlowIntrinsicHandlerBase(kBreakableChain) {} 30 | virtual ~BreakableChain() {} 31 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 32 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 33 | std::optional arg, 34 | Context* context) const final; 35 | }; 36 | } // namespace intrinsics 37 | } // namespace genc 38 | 39 | #endif // GENC_CC_INTRINSICS_BREAKABLE_CHAIN_H_ 40 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/conditional.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_CONDITIONAL_H_ 17 | #define GENC_CC_INTRINSICS_CONDITIONAL_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/status.h" 22 | #include "absl/status/statusor.h" 23 | #include "genc/cc/intrinsics/intrinsic_uris.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | #include "genc/proto/v0/computation.pb.h" 26 | 27 | namespace genc { 28 | namespace intrinsics { 29 | 30 | class Conditional : public ControlFlowIntrinsicHandlerBase { 31 | public: 32 | Conditional() : ControlFlowIntrinsicHandlerBase(kConditional) {} 33 | 34 | virtual ~Conditional() {} 35 | 36 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 37 | 38 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 39 | std::optional arg, 40 | Context* context) const final; 41 | }; 42 | 43 | } // namespace intrinsics 44 | } // namespace genc 45 | 46 | #endif // GENC_CC_INTRINSICS_CONDITIONAL_H_ 47 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/fallback.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_FALLBACK_H_ 17 | #define GENC_CC_INTRINSICS_FALLBACK_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/status.h" 22 | #include "absl/status/statusor.h" 23 | #include "genc/cc/intrinsics/intrinsic_uris.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | #include "genc/proto/v0/computation.pb.h" 26 | 27 | namespace genc { 28 | namespace intrinsics { 29 | 30 | class Fallback : public ControlFlowIntrinsicHandlerBase { 31 | public: 32 | Fallback() : ControlFlowIntrinsicHandlerBase(kFallback) {} 33 | 34 | virtual ~Fallback() {} 35 | 36 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 37 | 38 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 39 | std::optional arg, 40 | Context* context) const final; 41 | }; 42 | 43 | } // namespace intrinsics 44 | } // namespace genc 45 | 46 | #endif // GENC_CC_INTRINSICS_FALLBACK_H_ 47 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/inja_template.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_INJA_TEMPLATE_H_ 17 | #define GENC_CC_INTRINSICS_INJA_TEMPLATE_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/cc/intrinsics/intrinsic_uris.h" 21 | #include "genc/cc/runtime/intrinsic_handler.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | namespace genc { 25 | namespace intrinsics { 26 | 27 | // Template Engine for Modern C++. Equivalent to Jinja2 in Python. 28 | class InjaTemplate : public InlineIntrinsicHandlerBase { 29 | public: 30 | InjaTemplate() : InlineIntrinsicHandlerBase(kInjaTemplate) {} 31 | virtual ~InjaTemplate() {} 32 | 33 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 34 | 35 | absl::Status ExecuteCall(const v0::Intrinsic& intrinsic_pb, 36 | const v0::Value& arg, v0::Value* result, 37 | Context* context) const final; 38 | }; 39 | } // namespace intrinsics 40 | } // namespace genc 41 | 42 | #endif // GENC_CC_INTRINSICS_INJA_TEMPLATE_H_ 43 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/logger.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/intrinsics/logger.h" 17 | 18 | #include 19 | 20 | #include "absl/status/status.h" 21 | #include "genc/proto/v0/computation.pb.h" 22 | 23 | namespace genc { 24 | namespace intrinsics { 25 | absl::Status Logger::CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const { 26 | return absl::OkStatus(); 27 | } 28 | 29 | absl::Status Logger::ExecuteCall(const v0::Intrinsic& intrinsic_pb, 30 | const v0::Value& arg, v0::Value* result, 31 | Context* context) const { 32 | if (arg.has_str()) { 33 | // Pretty print of string 34 | std::cout << arg.str() << "\n"; 35 | } else { 36 | std::cout << arg.DebugString() << "\n"; 37 | } 38 | *result = arg; 39 | return absl::OkStatus(); 40 | } 41 | } // namespace intrinsics 42 | } // namespace genc 43 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/logger.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_LOGGER_H_ 17 | #define GENC_CC_INTRINSICS_LOGGER_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/cc/intrinsics/intrinsic_uris.h" 21 | #include "genc/cc/runtime/intrinsic_handler.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | 25 | namespace genc { 26 | namespace intrinsics { 27 | 28 | class Logger : public InlineIntrinsicHandlerBase { 29 | public: 30 | Logger() : InlineIntrinsicHandlerBase(kLogger) {} 31 | virtual ~Logger() {} 32 | 33 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 34 | 35 | absl::Status ExecuteCall(const v0::Intrinsic& intrinsic_pb, 36 | const v0::Value& arg, v0::Value* result, 37 | Context* context) const final; 38 | }; 39 | } // namespace intrinsics 40 | } // namespace genc 41 | 42 | #endif // GENC_CC_INTRINSICS_LOGGER_H_ 43 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/logical_not.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/intrinsics/logical_not.h" 17 | 18 | #include "absl/status/status.h" 19 | #include "genc/proto/v0/computation.pb.h" 20 | 21 | namespace genc { 22 | namespace intrinsics { 23 | 24 | absl::Status LogicalNot::CheckWellFormed( 25 | const v0::Intrinsic& intrinsic_pb) const { 26 | return absl::OkStatus(); 27 | } 28 | 29 | absl::Status LogicalNot::ExecuteCall(const v0::Intrinsic& intrinsic_pb, 30 | const v0::Value& arg, v0::Value* result, 31 | Context* context) const { 32 | if (!arg.has_boolean()) { 33 | return absl::InvalidArgumentError("Argument does not contain boolean."); 34 | } 35 | 36 | result->set_boolean(!arg.boolean()); 37 | return absl::OkStatus(); 38 | } 39 | 40 | } // namespace intrinsics 41 | } // namespace genc 42 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/logical_not.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_LOGICAL_NOT_H_ 17 | #define GENC_CC_INTRINSICS_LOGICAL_NOT_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/cc/intrinsics/intrinsic_uris.h" 21 | #include "genc/cc/runtime/intrinsic_handler.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | namespace genc { 25 | namespace intrinsics { 26 | 27 | class LogicalNot : public InlineIntrinsicHandlerBase { 28 | public: 29 | LogicalNot() : InlineIntrinsicHandlerBase(kLogicalNot) {} 30 | virtual ~LogicalNot() {} 31 | 32 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 33 | 34 | absl::Status ExecuteCall(const v0::Intrinsic& intrinsic_pb, 35 | const v0::Value& arg, v0::Value* result, 36 | Context* context) const final; 37 | }; 38 | } // namespace intrinsics 39 | } // namespace genc 40 | 41 | #endif // GENC_CC_INTRINSICS_LOGICAL_NOT_H_ 42 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/parallel_map.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_PARALLEL_MAP_H_ 17 | #define GENC_CC_INTRINSICS_PARALLEL_MAP_H_ 18 | 19 | #include 20 | #include "absl/status/status.h" 21 | #include "absl/status/statusor.h" 22 | #include "absl/strings/string_view.h" 23 | #include "genc/cc/intrinsics/intrinsic_uris.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | #include "genc/proto/v0/computation.pb.h" 26 | 27 | namespace genc { 28 | namespace intrinsics { 29 | 30 | class ParallelMap : public ControlFlowIntrinsicHandlerBase { 31 | public: 32 | ParallelMap() : ControlFlowIntrinsicHandlerBase(kParallelMap) {} 33 | 34 | virtual ~ParallelMap() {} 35 | 36 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 37 | 38 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 39 | std::optional arg, 40 | Context* context) const final; 41 | }; 42 | } // namespace intrinsics 43 | } // namespace genc 44 | 45 | #endif // GENC_CC_INTRINSICS_PARALLEL_MAP_H_ 46 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/regex_partial_match.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_REGEX_PARTIAL_MATCH_H_ 17 | #define GENC_CC_INTRINSICS_REGEX_PARTIAL_MATCH_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "absl/strings/string_view.h" 21 | #include "genc/cc/intrinsics/intrinsic_uris.h" 22 | #include "genc/cc/runtime/intrinsic_handler.h" 23 | #include "genc/proto/v0/computation.pb.h" 24 | 25 | namespace genc { 26 | namespace intrinsics { 27 | 28 | class RegexPartialMatch : public InlineIntrinsicHandlerBase { 29 | public: 30 | RegexPartialMatch() : InlineIntrinsicHandlerBase(kRegexPartialMatch) {} 31 | virtual ~RegexPartialMatch() {} 32 | 33 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 34 | absl::Status ExecuteCall(const v0::Intrinsic& intrinsic_pb, 35 | const v0::Value& arg, v0::Value* result, 36 | Context* context) const final; 37 | }; 38 | 39 | } // namespace intrinsics 40 | } // namespace genc 41 | 42 | #endif // GENC_CC_INTRINSICS_REGEX_PARTIAL_MATCH_H_ 43 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/repeat.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_REPEAT_H_ 17 | #define GENC_CC_INTRINSICS_REPEAT_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/status.h" 22 | #include "absl/status/statusor.h" 23 | #include "genc/cc/intrinsics/intrinsic_uris.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | #include "genc/proto/v0/computation.pb.h" 26 | 27 | namespace genc { 28 | namespace intrinsics { 29 | 30 | class Repeat : public ControlFlowIntrinsicHandlerBase { 31 | public: 32 | Repeat() : ControlFlowIntrinsicHandlerBase(kRepeat) {} 33 | 34 | virtual ~Repeat() {} 35 | 36 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 37 | 38 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 39 | std::optional arg, 40 | Context* context) const final; 41 | }; 42 | } // namespace intrinsics 43 | } // namespace genc 44 | 45 | #endif // GENC_CC_INTRINSICS_REPEAT_H_ 46 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/rest_call.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_REST_CALL_H_ 17 | #define GENC_CC_INTRINSICS_REST_CALL_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/cc/intrinsics/intrinsic_uris.h" 21 | #include "genc/cc/runtime/intrinsic_handler.h" 22 | #include "genc/proto/v0/computation.pb.h" 23 | 24 | namespace genc { 25 | namespace intrinsics { 26 | 27 | constexpr char kRestCallPost[] = "POST"; 28 | constexpr char kRestCallGet[] = "GET"; 29 | 30 | // For making REST calls. 31 | class RestCall : public InlineIntrinsicHandlerBase { 32 | public: 33 | RestCall() : InlineIntrinsicHandlerBase(kRestCall) {} 34 | virtual ~RestCall() {} 35 | 36 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 37 | 38 | absl::Status ExecuteCall(const v0::Intrinsic& intrinsic_pb, 39 | const v0::Value& arg, v0::Value* result, 40 | Context* context) const final; 41 | }; 42 | } // namespace intrinsics 43 | } // namespace genc 44 | 45 | #endif // GENC_CC_INTRINSICS_REST_CALL_H_ 46 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/serial_chain.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License 11 | ==============================================================================*/ 12 | 13 | #include 14 | 15 | #include "absl/status/status.h" 16 | #include "absl/status/statusor.h" 17 | #include "genc/cc/intrinsics/intrinsic_uris.h" 18 | #include "genc/cc/runtime/intrinsic_handler.h" 19 | #include "genc/proto/v0/computation.pb.h" 20 | 21 | #ifndef GENC_CC_INTRINSICS_SERIAL_CHAIN_H_ 22 | #define GENC_CC_INTRINSICS_SERIAL_CHAIN_H_ 23 | 24 | namespace genc { 25 | namespace intrinsics { 26 | class SerialChain : public ControlFlowIntrinsicHandlerBase { 27 | public: 28 | SerialChain() : ControlFlowIntrinsicHandlerBase(kSerialChain) {} 29 | virtual ~SerialChain() {} 30 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 31 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 32 | std::optional arg, 33 | Context* context) const final; 34 | }; 35 | } // namespace intrinsics 36 | } // namespace genc 37 | 38 | #endif // GENC_CC_INTRINSICS_SERIAL_CHAIN_H_ 39 | -------------------------------------------------------------------------------- /genc/cc/intrinsics/while.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_INTRINSICS_WHILE_H_ 17 | #define GENC_CC_INTRINSICS_WHILE_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/status.h" 22 | #include "absl/status/statusor.h" 23 | #include "genc/cc/intrinsics/intrinsic_uris.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | #include "genc/proto/v0/computation.pb.h" 26 | 27 | namespace genc { 28 | namespace intrinsics { 29 | 30 | class While : public ControlFlowIntrinsicHandlerBase { 31 | public: 32 | While() : ControlFlowIntrinsicHandlerBase(kWhile) {} 33 | 34 | virtual ~While() {} 35 | 36 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 37 | 38 | absl::StatusOr ExecuteCall(const v0::Intrinsic& intrinsic_pb, 39 | std::optional arg, 40 | Context* context) const final; 41 | }; 42 | } // namespace intrinsics 43 | } // namespace genc 44 | 45 | #endif // GENC_CC_INTRINSICS_WHILE_H_ 46 | -------------------------------------------------------------------------------- /genc/cc/modules/agents/BUILD: -------------------------------------------------------------------------------- 1 | # Libraries for building agent-based applications. 2 | 3 | package( 4 | default_visibility = [ 5 | #"//genc/google:__subpackages__", 6 | "//visibility:public", 7 | ], 8 | ) 9 | 10 | licenses(["notice"]) 11 | 12 | cc_library( 13 | name = "react", 14 | srcs = ["react.cc"], 15 | hdrs = ["react.h"], 16 | deps = [ 17 | "//genc/cc/intrinsics:custom_function", 18 | "//genc/proto/v0:computation_cc_proto", 19 | "@com_google_absl//absl/status", 20 | "@com_google_absl//absl/status:statusor", 21 | "@com_google_absl//absl/strings:str_format", 22 | "@com_googlesource_code_re2//:re2", 23 | ], 24 | ) 25 | 26 | cc_test( 27 | name = "react_test", 28 | srcs = ["react_test.cc"], 29 | deps = [ 30 | ":react", 31 | "//genc/proto/v0:computation_cc_proto", 32 | "@com_google_googletest//:gtest_main", 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /genc/cc/modules/parsers/BUILD: -------------------------------------------------------------------------------- 1 | # Libraries for parsing input and output of ops. 2 | 3 | package( 4 | default_visibility = [ 5 | #"//genc/google:__subpackages__", 6 | "//visibility:public", 7 | ], 8 | ) 9 | 10 | licenses(["notice"]) 11 | 12 | cc_library( 13 | name = "gemini_parser", 14 | srcs = ["gemini_parser.cc"], 15 | hdrs = ["gemini_parser.h"], 16 | deps = [ 17 | "//genc/cc/intrinsics:custom_function", 18 | "//genc/cc/modules/templates:inja_status_or", 19 | "//genc/cc/runtime:status_macros", 20 | "//genc/proto/v0:computation_cc_proto", 21 | "@com_google_absl//absl/status", 22 | "@com_google_absl//absl/status:statusor", 23 | "@com_google_absl//absl/strings", 24 | "@nlohmann_json//:json", 25 | ], 26 | ) 27 | 28 | cc_test( 29 | name = "gemini_parser_test", 30 | srcs = ["gemini_parser_test.cc"], 31 | deps = [ 32 | ":gemini_parser", 33 | "//genc/proto/v0:computation_cc_proto", 34 | "@com_google_googletest//:gtest_main", 35 | "@nlohmann_json//:json", 36 | ], 37 | ) 38 | 39 | # cc_test( 40 | # name = "react_test", 41 | # srcs = ["react_test.cc"], 42 | # deps = [ 43 | # ":react", 44 | # "//testing/base/public:gunit_main", 45 | # "//genc/proto/v0:computation_cc_proto", 46 | # ], 47 | # ) 48 | -------------------------------------------------------------------------------- /genc/cc/modules/retrieval/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "local_cache", 9 | srcs = ["local_cache.cc"], 10 | hdrs = ["local_cache.h"], 11 | deps = [ 12 | "//genc/cc/intrinsics:custom_function", 13 | "//genc/proto/v0:computation_cc_proto", 14 | "@com_google_absl//absl/container:flat_hash_map", 15 | "@com_google_absl//absl/status", 16 | "@com_google_absl//absl/synchronization", 17 | ], 18 | ) 19 | 20 | cc_test( 21 | name = "local_cache_test", 22 | srcs = ["local_cache_test.cc"], 23 | deps = [ 24 | ":local_cache", 25 | "//genc/cc/authoring:constructor", 26 | "//genc/cc/intrinsics:handler_sets", 27 | "//genc/cc/runtime:executor", 28 | "//genc/cc/runtime:inline_executor", 29 | "//genc/cc/runtime:runner", 30 | "//genc/cc/runtime:threading", 31 | "//genc/proto/v0:computation_cc_proto", 32 | "@com_google_googletest//:gtest_main", 33 | ], 34 | ) 35 | 36 | cc_library( 37 | name = "bi_map", 38 | hdrs = ["bi_map.h"], 39 | deps = [ 40 | "@com_google_absl//absl/base:core_headers", 41 | "@com_google_absl//absl/container:flat_hash_map", 42 | "@com_google_absl//absl/synchronization", 43 | ], 44 | ) 45 | 46 | cc_test( 47 | name = "bi_map_test", 48 | srcs = ["bi_map_test.cc"], 49 | deps = [ 50 | ":bi_map", 51 | "@com_google_googletest//:gtest_main", 52 | ], 53 | ) 54 | -------------------------------------------------------------------------------- /genc/cc/modules/templates/BUILD: -------------------------------------------------------------------------------- 1 | # Libraries for template engines & common templates. 2 | 3 | package( 4 | default_visibility = [ 5 | #"//genc/google:__subpackages__", 6 | "//visibility:public", 7 | ], 8 | ) 9 | 10 | licenses(["notice"]) 11 | 12 | cc_library( 13 | name = "inja_status_or", 14 | srcs = ["inja_status_or.cc"], 15 | hdrs = ["inja_status_or.h"], 16 | copts = [ 17 | "-fexceptions", 18 | ], 19 | features = ["-use_header_modules"], 20 | deps = [ 21 | "@com_google_absl//absl/status", 22 | "@com_google_absl//absl/status:statusor", 23 | "@com_google_absl//absl/strings", 24 | "@nlohmann_json//:json", 25 | "@pantor_inja//:inja", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /genc/cc/modules/templates/inja_status_or.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/modules/templates/inja_status_or.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "absl/status/status.h" 23 | #include "absl/status/statusor.h" 24 | #include "absl/strings/str_cat.h" 25 | #include 26 | #include 27 | 28 | namespace inja_status_or { 29 | 30 | absl::StatusOr Environment::render(std::string_view input, 31 | const nlohmann::json& data) { 32 | try { 33 | return inja::Environment::render(input, data); 34 | } catch (const std::exception& e) { 35 | return absl::InternalError(absl::StrCat("Render: ", e.what())); 36 | } catch (...) { 37 | return absl::InternalError("Render: something went wrong."); 38 | } 39 | } 40 | } // namespace inja_status_or 41 | -------------------------------------------------------------------------------- /genc/cc/modules/templates/inja_status_or.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_MODULES_TEMPLATES_INJA_STATUS_OR_H_ 17 | #define GENC_CC_MODULES_TEMPLATES_INJA_STATUS_OR_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "absl/status/status.h" 23 | #include "absl/status/statusor.h" 24 | #include 25 | #include 26 | 27 | namespace inja_status_or { 28 | // StatusOr wrapped inja template functions. 29 | class Environment : public inja::Environment { 30 | public: 31 | absl::StatusOr render(std::string_view input, 32 | const nlohmann::json& data); 33 | }; 34 | } // namespace inja_status_or 35 | 36 | #endif // GENC_CC_MODULES_TEMPLATES_INJA_STATUS_OR_H_ 37 | -------------------------------------------------------------------------------- /genc/cc/modules/tools/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "wolfram_alpha", 9 | srcs = ["wolfram_alpha.cc"], 10 | hdrs = ["wolfram_alpha.h"], 11 | deps = [ 12 | "//genc/cc/intrinsics:intrinsic_uris", 13 | "//genc/cc/runtime:intrinsic_handler", 14 | "//genc/cc/runtime:status_macros", 15 | "//genc/proto/v0:computation_cc_proto", 16 | "@com_google_absl//absl/status", 17 | "@com_google_absl//absl/status:statusor", 18 | "@curl", 19 | ], 20 | ) 21 | 22 | cc_library( 23 | name = "curl_client", 24 | srcs = ["curl_client.cc"], 25 | hdrs = ["curl_client.h"], 26 | deps = [ 27 | "//genc/proto/v0:computation_cc_proto", 28 | "@com_google_absl//absl/status", 29 | "@com_google_absl//absl/status:statusor", 30 | "@curl", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /genc/cc/modules/tools/wolfram_alpha.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_MODULES_TOOLS_WOLFRAM_ALPHA_H_ 17 | #define GENC_CC_MODULES_TOOLS_WOLFRAM_ALPHA_H_ 18 | 19 | 20 | #include "absl/status/status.h" 21 | #include "genc/cc/intrinsics/intrinsic_uris.h" 22 | #include "genc/cc/runtime/intrinsic_handler.h" 23 | #include "genc/proto/v0/computation.pb.h" 24 | 25 | namespace genc { 26 | namespace intrinsics { 27 | 28 | // Tools for calling WolframAlpha API. 29 | class WolframAlpha : public InlineIntrinsicHandlerBase { 30 | public: 31 | WolframAlpha() : InlineIntrinsicHandlerBase(kWolframAlpha) {} 32 | virtual ~WolframAlpha() {} 33 | 34 | absl::Status CheckWellFormed(const v0::Intrinsic& intrinsic_pb) const final; 35 | 36 | absl::Status ExecuteCall(const v0::Intrinsic& intrinsic_pb, 37 | const v0::Value& arg, v0::Value* result, 38 | Context* context) const final; 39 | }; 40 | } // namespace intrinsics 41 | } // namespace genc 42 | 43 | #endif // GENC_CC_MODULES_TOOLS_WOLFRAM_ALPHA_H_ 44 | -------------------------------------------------------------------------------- /genc/cc/modules/worker/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "run_server", 9 | srcs = ["run_server.cc"], 10 | hdrs = ["run_server.h"], 11 | deps = [ 12 | "//genc/cc/base:read_file", 13 | "//genc/cc/examples/executors:executor_stacks", 14 | "//genc/cc/interop/confidential_computing:attestation", 15 | "//genc/cc/interop/oak:server", 16 | "//genc/cc/runtime:executor", 17 | "//genc/cc/runtime:executor_service", 18 | "//genc/cc/runtime:status_macros", 19 | "//genc/proto/v0:computation_cc_proto", 20 | "//genc/proto/v0:executor_cc_grpc_proto", 21 | "//genc/proto/v0:executor_cc_proto", 22 | "@com_github_grpc_grpc//:grpc++", 23 | "@com_github_grpc_grpc//:grpc++_reflection", 24 | "@com_google_absl//absl/status", 25 | "@com_google_absl//absl/status:statusor", 26 | "@com_google_absl//absl/strings", 27 | "@oak//proto/session:service_unary_cc_grpc", 28 | ], 29 | ) 30 | -------------------------------------------------------------------------------- /genc/cc/modules/worker/run_server.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_MODULES_WORKER_RUN_SERVER_H_ 17 | #define GENC_CC_MODULES_WORKER_RUN_SERVER_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "absl/status/status.h" 23 | #include "genc/cc/runtime/executor.h" 24 | 25 | namespace genc { 26 | namespace modules { 27 | namespace worker { 28 | 29 | struct RunServerOptions { 30 | enum ChannelType { 31 | INSECURE, 32 | SSL, 33 | }; 34 | std::string server_address; 35 | ChannelType channel_type = INSECURE; 36 | std::string ssl_cert_path; 37 | std::string ssl_key_path; 38 | bool use_oak = false; 39 | bool debug = false; 40 | }; 41 | 42 | absl::Status RunServer( 43 | std::shared_ptr executor, const RunServerOptions& options); 44 | 45 | } // namespace worker 46 | } // namespace modules 47 | } // namespace genc 48 | 49 | #endif // GENC_CC_MODULES_WORKER_RUN_SERVER_H_ 50 | -------------------------------------------------------------------------------- /genc/cc/runtime/control_flow_executor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_RUNTIME_CONTROL_FLOW_EXECUTOR_H_ 17 | #define GENC_CC_RUNTIME_CONTROL_FLOW_EXECUTOR_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/executor.h" 23 | #include "genc/cc/runtime/intrinsic_handler.h" 24 | 25 | namespace genc { 26 | 27 | // Returns an executor that specializes in handling lambda expressions and 28 | // control flow intrinsics, and otherwise delegates all processing, including 29 | // inline intrinsics such as model calls, to the specified child executor. 30 | absl::StatusOr> CreateControlFlowExecutor( 31 | std::shared_ptr handler_set, 32 | std::shared_ptr child_executor, 33 | std::shared_ptr concurrency_interface); 34 | 35 | } // namespace genc 36 | 37 | #endif // GENC_CC_RUNTIME_CONTROL_FLOW_EXECUTOR_H_ 38 | -------------------------------------------------------------------------------- /genc/cc/runtime/executor.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/runtime/executor.h" 17 | 18 | namespace genc {} // namespace genc 19 | -------------------------------------------------------------------------------- /genc/cc/runtime/executor_service.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_RUNTIME_EXECUTOR_SERVICE_H_ 17 | #define GENC_CC_RUNTIME_EXECUTOR_SERVICE_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/executor.h" 23 | #include "genc/proto/v0/executor.grpc.pb.h" 24 | 25 | namespace genc { 26 | 27 | absl::StatusOr> CreateExecutorService( 28 | std::shared_ptr executor); 29 | 30 | } // namespace genc 31 | 32 | #endif // GENC_CC_RUNTIME_EXECUTOR_SERVICE_H_ 33 | -------------------------------------------------------------------------------- /genc/cc/runtime/executor_stacks.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_RUNTIME_EXECUTOR_STACKS_H_ 17 | #define GENC_CC_RUNTIME_EXECUTOR_STACKS_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/concurrency.h" 23 | #include "genc/cc/runtime/executor.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | 26 | namespace genc { 27 | 28 | // Constructs a local executor for a given set of intrinsic handlers. 29 | // Use this when you have a set of custom handlers to add that is non default. 30 | absl::StatusOr> CreateLocalExecutor( 31 | std::shared_ptr handler_set, 32 | std::shared_ptr concurrency_interface = nullptr); 33 | 34 | // Returns an executor that performs local processing in-process. 35 | absl::StatusOr> CreateDefaultLocalExecutor(); 36 | 37 | } // namespace genc 38 | 39 | #endif // GENC_CC_RUNTIME_EXECUTOR_STACKS_H_ 40 | -------------------------------------------------------------------------------- /genc/cc/runtime/executor_stacks_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include "genc/cc/runtime/executor_stacks.h" 17 | 18 | #include 19 | 20 | #include "googletest/include/gtest/gtest.h" 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/executor.h" 23 | 24 | namespace genc { 25 | namespace { 26 | 27 | class ExecutorStacksTest : public ::testing::Test { 28 | protected: 29 | ExecutorStacksTest() {} 30 | ~ExecutorStacksTest() override {} 31 | }; 32 | 33 | TEST_F(ExecutorStacksTest, Simple) { 34 | absl::StatusOr> executor = 35 | genc::CreateDefaultLocalExecutor(); 36 | EXPECT_TRUE(executor.ok()); 37 | } 38 | 39 | } // namespace 40 | } // namespace genc 41 | -------------------------------------------------------------------------------- /genc/cc/runtime/inline_executor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_RUNTIME_INLINE_EXECUTOR_H_ 17 | #define GENC_CC_RUNTIME_INLINE_EXECUTOR_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/concurrency.h" 23 | #include "genc/cc/runtime/executor.h" 24 | #include "genc/cc/runtime/intrinsic_handler.h" 25 | 26 | namespace genc { 27 | 28 | // Creates an executor that specializes in handling inline intrinsic calls. 29 | absl::StatusOr> CreateInlineExecutor( 30 | std::shared_ptr handler_set, 31 | std::shared_ptr concurrency_interface); 32 | 33 | } // namespace genc 34 | 35 | #endif // GENC_CC_RUNTIME_INLINE_EXECUTOR_H_ 36 | -------------------------------------------------------------------------------- /genc/cc/runtime/remote_executor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_RUNTIME_REMOTE_EXECUTOR_H_ 17 | #define GENC_CC_RUNTIME_REMOTE_EXECUTOR_H_ 18 | 19 | #include 20 | 21 | #include "absl/status/statusor.h" 22 | #include "genc/cc/runtime/concurrency.h" 23 | #include "genc/cc/runtime/executor.h" 24 | #include "genc/proto/v0/executor.grpc.pb.h" 25 | 26 | namespace genc { 27 | 28 | // Creates an executor that forwards all requests to a remote backend. 29 | absl::StatusOr> CreateRemoteExecutor( 30 | std::unique_ptr executor_stub, 31 | std::shared_ptr concurrency_interface); 32 | 33 | } // namespace genc 34 | 35 | #endif // GENC_CC_RUNTIME_REMOTE_EXECUTOR_H_ 36 | -------------------------------------------------------------------------------- /genc/cc/runtime/threading.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_RUNTIME_THREADING_H_ 17 | #define GENC_CC_RUNTIME_THREADING_H_ 18 | 19 | #include 20 | 21 | #include "genc/cc/runtime/concurrency.h" 22 | 23 | namespace genc { 24 | 25 | std::shared_ptr CreateThreadBasedConcurrencyManager(); 26 | 27 | } // namespace genc 28 | 29 | #endif // GENC_CC_RUNTIME_THREADING_H_ 30 | -------------------------------------------------------------------------------- /genc/cc/testing/BUILD: -------------------------------------------------------------------------------- 1 | # Testing libraries that are shared across modules. 2 | package( 3 | default_visibility = ["//visibility:public"], 4 | ) 5 | 6 | licenses(["notice"]) 7 | 8 | cc_test( 9 | name = "testing_libs_test", 10 | srcs = ["testing_libs_test.cc"], 11 | deps = [ 12 | ":testing_libs", 13 | "//genc/proto/v0:computation_cc_proto", 14 | "@com_google_googletest//:gtest_main", 15 | ], 16 | ) 17 | 18 | cc_library( 19 | name = "testing_libs", 20 | testonly = True, 21 | srcs = ["testing_libs.cc"], 22 | hdrs = ["testing_libs.h"], 23 | deps = [ 24 | "//genc/cc/runtime:status_macros", 25 | "//genc/proto/v0:computation_cc_proto", 26 | "@com_google_absl//absl/status", 27 | "@com_google_absl//absl/status:statusor", 28 | "@com_google_absl//absl/strings", 29 | "@com_google_absl//absl/strings:str_format", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /genc/cc/testing/testing_libs.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_TESTING_TESTING_LIBS_H_ 17 | #define GENC_CC_TESTING_TESTING_LIBS_H_ 18 | // Common libs used for simplify testing code or running mock examples. 19 | #include 20 | #include "absl/status/statusor.h" 21 | #include "genc/proto/v0/computation.pb.h" 22 | 23 | namespace genc { 24 | namespace testing { 25 | 26 | // Returns a Value contains a str fn_name(formatted_value). 27 | absl::StatusOr WrapFnNameAroundValue( 28 | std::string fn_name, const genc::v0::Value& value); 29 | 30 | // Returns the content of value, if value contains struct, returns the content 31 | // of the struct separated by ','. used for testing purpose. 32 | absl::StatusOr FormatValueAsString( 33 | const genc::v0::Value& value); 34 | 35 | } // namespace testing 36 | } // namespace genc 37 | #endif // GENC_CC_TESTING_TESTING_LIBS_H_ 38 | -------------------------------------------------------------------------------- /genc/cc/types/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "checking", 9 | srcs = ["checking.cc"], 10 | hdrs = ["checking.h"], 11 | deps = [ 12 | "//genc/proto/v0:computation_cc_proto", 13 | "@com_google_absl//absl/status", 14 | "@com_google_absl//absl/strings", 15 | ], 16 | ) 17 | 18 | cc_test( 19 | name = "checking_test", 20 | timeout = "short", 21 | srcs = ["checking_test.cc"], 22 | deps = [ 23 | ":checking", 24 | "//genc/proto/v0:computation_cc_proto", 25 | "@com_google_absl//absl/status", 26 | "@com_google_googletest//:gtest_main", 27 | ], 28 | ) 29 | 30 | cc_library( 31 | name = "inference", 32 | srcs = ["inference.cc"], 33 | hdrs = ["inference.h"], 34 | deps = [ 35 | ":checking", 36 | "//genc/cc/runtime:status_macros", 37 | "//genc/proto/v0:computation_cc_proto", 38 | "@com_google_absl//absl/status", 39 | "@com_google_absl//absl/strings", 40 | ], 41 | ) 42 | 43 | cc_test( 44 | name = "inference_test", 45 | timeout = "short", 46 | srcs = ["inference_test.cc"], 47 | deps = [ 48 | ":inference", 49 | "//genc/proto/v0:computation_cc_proto", 50 | "@com_google_absl//absl/status", 51 | "@com_google_googletest//:gtest_main", 52 | ], 53 | ) 54 | -------------------------------------------------------------------------------- /genc/cc/types/checking.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_TYPES_CHECKING_H_ 17 | #define GENC_CC_TYPES_CHECKING_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/proto/v0/computation.pb.h" 21 | 22 | namespace genc { 23 | 24 | absl::Status CheckEqual(v0::Type x, v0::Type y); 25 | 26 | } // namespace genc 27 | 28 | #endif // GENC_CC_TYPES_CHECKING_H_ 29 | -------------------------------------------------------------------------------- /genc/cc/types/inference.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #ifndef GENC_CC_TYPES_INFERENCE_H_ 17 | #define GENC_CC_TYPES_INFERENCE_H_ 18 | 19 | #include "absl/status/status.h" 20 | #include "genc/proto/v0/computation.pb.h" 21 | 22 | namespace genc { 23 | 24 | struct InferenceOptions {}; 25 | 26 | absl::Status InferTypes(v0::Value* value_pb, 27 | const InferenceOptions* options_or_null = nullptr); 28 | 29 | } // namespace genc 30 | 31 | #endif // GENC_CC_TYPES_INFERENCE_H_ 32 | -------------------------------------------------------------------------------- /genc/docs/bazel_plugin_installation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/bazel_plugin_installation.png -------------------------------------------------------------------------------- /genc/docs/genc_project_import_in_android_studio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/genc_project_import_in_android_studio.png -------------------------------------------------------------------------------- /genc/docs/genc_run_configurations_android_studio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/genc_run_configurations_android_studio.png -------------------------------------------------------------------------------- /genc/docs/tutorials/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # exporting tutorials colab to make them visible in jupyter setup 2 | 3 | exports_files([ 4 | "tutorial_1_simple_cascade.ipynb", 5 | "tutorial_2_custom_routing.ipynb", 6 | "tutorial_3_custom_runtime.ipynb", 7 | "tutorial_4_math_tool_agent.ipynb", 8 | "tutorial_5_langchain_agent.ipynb", 9 | "tutorial_6_confidential_computing.ipynb", 10 | "tutorial_7_authoring.ipynb", 11 | "tutorial_8_android.ipynb", 12 | "tutorial_9_private_genai.ipynb", 13 | ]) 14 | -------------------------------------------------------------------------------- /genc/docs/tutorials/genc_app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/genc_app_icon.png -------------------------------------------------------------------------------- /genc/docs/tutorials/genc_app_response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/genc_app_response.png -------------------------------------------------------------------------------- /genc/docs/tutorials/genc_app_startup_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/genc_app_startup_screen.png -------------------------------------------------------------------------------- /genc/docs/tutorials/genc_on_device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/genc_on_device.png -------------------------------------------------------------------------------- /genc/docs/tutorials/genc_tee.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/genc_tee.png -------------------------------------------------------------------------------- /genc/docs/tutorials/jupyter_setup/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_binary") 2 | 3 | py_binary( 4 | name = "jupyter", 5 | srcs = ["jupyter.py"], 6 | data = [ 7 | ":openai_demo.ipynb", 8 | "//genc/docs/tutorials:tutorial_1_simple_cascade.ipynb", 9 | "//genc/docs/tutorials:tutorial_2_custom_routing.ipynb", 10 | "//genc/docs/tutorials:tutorial_3_custom_runtime.ipynb", 11 | "//genc/docs/tutorials:tutorial_4_math_tool_agent.ipynb", 12 | "//genc/docs/tutorials:tutorial_5_langchain_agent.ipynb", 13 | "//genc/docs/tutorials:tutorial_6_confidential_computing.ipynb", 14 | "//genc/docs/tutorials:tutorial_7_authoring.ipynb", 15 | "//genc/docs/tutorials:tutorial_8_android.ipynb", 16 | "//genc/docs/tutorials:tutorial_9_private_genai.ipynb", 17 | ], 18 | tags = [ 19 | "nobuilder", 20 | "notap", 21 | ], 22 | visibility = [ 23 | "//genc/python:python_packages", 24 | ], 25 | deps = [ 26 | "//genc/proto/v0:computation_py_pb2", 27 | "//genc/python/authoring", 28 | "//genc/python/base", 29 | "//genc/python/examples", 30 | "//genc/python/interop", 31 | "//genc/python/runtime", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /genc/docs/tutorials/jupyter_setup/jupyter.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A example to launch jupyter notebook.""" 15 | 16 | # note : Before running the Jupyter notebook please install jupyter-notebook 17 | # apt install juyter-notebook 18 | 19 | 20 | import sys 21 | from jupyter_core.command import main as jupyter_main 22 | 23 | 24 | if __name__ == "__main__": 25 | sys.argv = [ 26 | "jupyter", 27 | "notebook", 28 | "genc/docs/tutorials/", 29 | "--no-browser", 30 | "--ip=0.0.0.0", 31 | "--port=8889", 32 | "--allow-root", 33 | ] 34 | sys.exit(jupyter_main()) 35 | 36 | -------------------------------------------------------------------------------- /genc/docs/tutorials/jupyter_setup/launch_jupyter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # /* Copyright 2023, The GenC Authors. 5 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License 17 | # ==============================================================================*/ 18 | 19 | #install jupyter notebook and pip requirements 20 | 21 | apt install jupyter-notebook 22 | 23 | bazel run docs/tutorials/jupyter_setup:jupyter 24 | -------------------------------------------------------------------------------- /genc/docs/tutorials/private_genai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/private_genai.png -------------------------------------------------------------------------------- /genc/docs/tutorials/server_log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/server_log.png -------------------------------------------------------------------------------- /genc/docs/tutorials/tutorial_8_app_screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/tutorial_8_app_screenshot_1.png -------------------------------------------------------------------------------- /genc/docs/tutorials/tutorial_8_app_screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/tutorial_8_app_screenshot_2.png -------------------------------------------------------------------------------- /genc/docs/tutorials/tutorial_9_screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/tutorial_9_screenshot_1.png -------------------------------------------------------------------------------- /genc/docs/tutorials/tutorial_9_screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc/docs/tutorials/tutorial_9_screenshot_2.png -------------------------------------------------------------------------------- /genc/java/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | package_group( 6 | name = "java_packages", 7 | packages = ["//genc/java/..."], 8 | ) 9 | 10 | licenses(["notice"]) 11 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | platform( 8 | name = "linux_x86_64", 9 | constraint_values = [ 10 | "@platforms//os:linux", 11 | "@platforms//cpu:x86_64", 12 | ], 13 | visibility = ["//visibility:public"], 14 | ) 15 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/authoring/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | android_library( 10 | name = "constructor_android", 11 | srcs = [ 12 | "Constructor.java", 13 | ], 14 | deps = [ 15 | "//genc/java/src/java/org/genc/runtime:to_from_value_proto_android", 16 | "//genc/java/src/native/org/genc/authoring:libconstructor_jni_lib", 17 | "//genc/proto/v0:computation_java_proto_lite", 18 | "@com_google_protobuf//java/lite", 19 | "@maven//:com_google_code_findbugs_jsr305", 20 | "@maven//:com_google_guava_guava", 21 | ], 22 | ) 23 | 24 | java_library( 25 | name = "constructor", 26 | srcs = [ 27 | "Constructor.java", 28 | ], 29 | deps = [ 30 | "//genc/java/src/java/org/genc/runtime:to_from_value_proto", 31 | "//genc/java/src/native/org/genc/authoring:libconstructor_jni_lib", 32 | "//genc/proto/v0:computation_java_proto", 33 | "@com_google_protobuf//java/lite", 34 | "@maven//:com_google_code_findbugs_jsr305", 35 | "@maven//:com_google_guava_guava", 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/examples/apps/gencdemo/.blazeproject: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/examples/apps/gencdemo/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/examples/apps/gencdemo/lib/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//genc/java/src/java/org/genc/examples/apps/gencdemo:genc_demo_packages"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "android_executor_jni_lib", 9 | srcs = ["jni.cc"], 10 | target_compatible_with = [ 11 | "@platforms//os:android", 12 | ], 13 | visibility = ["//visibility:public"], 14 | deps = [ 15 | "//genc/c/runtime:c_api", 16 | "//genc/c/runtime:c_api_internal", 17 | "//genc/cc/examples/executors/android:android_executor_stacks", 18 | "//genc/java/src/jni:copy_jni_hdr_lib", 19 | "@bazel_tools//tools/jdk:jni", 20 | "@com_google_absl//absl/log", 21 | "@com_google_absl//absl/status:statusor", 22 | ], 23 | alwayslink = 1, 24 | ) 25 | 26 | cc_binary( 27 | name = "libandroid_executor_jni.so", 28 | linkopts = [ 29 | "-Wl,--no-undefined", 30 | ], 31 | linkshared = 1, 32 | linkstatic = 1, 33 | deps = [":android_executor_jni_lib"], 34 | ) 35 | 36 | cc_library( 37 | name = "libandroid_executor_jni_lib", 38 | srcs = [":libandroid_executor_jni.so"], 39 | alwayslink = 1, 40 | ) 41 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/examples/apps/gencdemo/lib/jni.lds: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License 14 | # ============================================================================== 15 | 16 | VERS_1.0 { 17 | global: 18 | Java_*; 19 | JNI_OnLoad; 20 | JNI_OnUnload; 21 | 22 | local: 23 | *; 24 | }; 25 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/examples/apps/gencdemo/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | GenC Demo App 4 | Generate 5 | Write a poem about android 6 | Type a query here 7 | 8 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/examples/executors/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | java_library( 10 | name = "default_executor", 11 | srcs = ["DefaultExecutor.java"], 12 | deps = [ 13 | "//genc/java/src/java/org/genc/interop/backends/googleai:google_ai_client", 14 | "//genc/java/src/java/org/genc/interop/backends/openai:open_ai_client", 15 | "//genc/java/src/java/org/genc/interop/backends/wolframalpha:wolfram_alpha_client", 16 | "//genc/java/src/java/org/genc/interop/network:java_http_client", 17 | "//genc/java/src/native/org/genc/examples/executors:libdefault_executor_jni_lib", 18 | ], 19 | ) 20 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/googleai/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/googleai/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | android_library( 10 | name = "google_ai_client_android", 11 | srcs = [ 12 | "GoogleAiClient.java", 13 | ], 14 | deps = [ 15 | "//genc/java/src/java/org/genc/interop/network:http_client_impl", 16 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto_lite", 17 | "//genc/proto/v0:computation_java_proto_lite", 18 | "@com_google_protobuf//java/lite", 19 | "@maven//:com_google_code_gson_gson", 20 | "@maven//:com_google_flogger_flogger", 21 | "@maven//:com_google_guava_guava", 22 | ], 23 | ) 24 | 25 | java_library( 26 | name = "google_ai_client", 27 | srcs = [ 28 | "GoogleAiClient.java", 29 | ], 30 | deps = [ 31 | "//genc/java/src/java/org/genc/interop/network:http_client", 32 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto", 33 | "//genc/proto/v0:computation_java_proto", 34 | "@com_google_protobuf//java/lite", 35 | "@maven//:com_google_code_gson_gson", 36 | "@maven//:com_google_flogger_flogger", 37 | "@maven//:com_google_flogger_flogger_system_backend", 38 | "@maven//:com_google_guava_guava", 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/mediapipe/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/mediapipe/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | android_library( 8 | name = "llm_inference_client", 9 | srcs = [ 10 | "LlmInferenceClient.java", 11 | ], 12 | deps = [ 13 | "//genc/proto/v0:computation_java_proto_lite", 14 | "@com_google_protobuf//java/lite", 15 | "@maven//:com_google_flogger_flogger", 16 | "@maven//:com_google_guava_guava", 17 | "@maven//:com_google_mediapipe_tasks_genai", 18 | ], 19 | ) 20 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/openai/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/openai/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | android_library( 10 | name = "open_ai_client_android", 11 | srcs = [ 12 | "OpenAiClient.java", 13 | ], 14 | deps = [ 15 | "//genc/java/src/java/org/genc/interop/network:http_client_impl", 16 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto_lite", 17 | "//genc/proto/v0:computation_java_proto_lite", 18 | "@com_google_protobuf//java/lite", 19 | "@maven//:com_google_code_gson_gson", 20 | "@maven//:com_google_flogger_flogger", 21 | "@maven//:com_google_guava_guava", 22 | ], 23 | ) 24 | 25 | java_library( 26 | name = "open_ai_client", 27 | srcs = [ 28 | "OpenAiClient.java", 29 | ], 30 | deps = [ 31 | "//genc/java/src/java/org/genc/interop/network:http_client", 32 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto", 33 | "//genc/proto/v0:computation_java_proto", 34 | "@com_google_protobuf//java/lite", 35 | "@maven//:com_google_code_gson_gson", 36 | "@maven//:com_google_flogger_flogger", 37 | "@maven//:com_google_flogger_flogger_system_backend", 38 | "@maven//:com_google_guava_guava", 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/wolframalpha/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/backends/wolframalpha/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | android_library( 10 | name = "wolfram_alpha_client_android", 11 | srcs = [ 12 | "WolframAlphaClient.java", 13 | ], 14 | deps = [ 15 | "//genc/java/src/java/org/genc/interop/network:http_client_impl", 16 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto_lite", 17 | "//genc/proto/v0:computation_java_proto_lite", 18 | "@com_google_protobuf//java/lite", 19 | "@maven//:com_google_flogger_flogger", 20 | "@maven//:com_google_guava_guava", 21 | ], 22 | ) 23 | 24 | java_library( 25 | name = "wolfram_alpha_client", 26 | srcs = [ 27 | "WolframAlphaClient.java", 28 | ], 29 | deps = [ 30 | "//genc/java/src/java/org/genc/interop/network:http_client", 31 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto", 32 | "//genc/proto/v0:computation_java_proto", 33 | "@com_google_protobuf//java/lite", 34 | "@maven//:com_google_flogger_flogger", 35 | "@maven//:com_google_flogger_flogger_system_backend", 36 | "@maven//:com_google_guava_guava", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/network/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/network/HttpClient.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | package src.java.org.genc.interop.network; 17 | 18 | import com.google.common.util.concurrent.ListenableFuture; 19 | import src.java.org.genc.interop.network.api.proto.HttpOptions; 20 | import src.java.org.genc.interop.network.api.proto.HttpRequest; 21 | import src.java.org.genc.interop.network.api.proto.HttpResponse; 22 | 23 | /** An interface for an asynchronous HTTP client. */ 24 | public interface HttpClient { 25 | /** 26 | * Sends a single http request asynchronously. Returns a {@link ListenableFuture} which provides 27 | * the response when available. 28 | */ 29 | ListenableFuture send(HttpRequest request, HttpOptions httpOptions); 30 | } 31 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/network/HttpException.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | package src.java.org.genc.interop.network; 16 | 17 | /** An exception class used to propagate http request exceptions to callers. */ 18 | public final class HttpException extends Exception { 19 | public HttpException(String message) { 20 | super(message); 21 | } 22 | 23 | public HttpException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/interop/network/api/proto/BUILD: -------------------------------------------------------------------------------- 1 | load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") 2 | load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto_library") 3 | load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library") 4 | load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") 5 | 6 | package( 7 | default_visibility = ["//visibility:public"], 8 | ) 9 | 10 | licenses(["notice"]) 11 | 12 | proto_library( 13 | name = "http_request_response_proto", 14 | srcs = ["http_request_response.proto"], 15 | ) 16 | 17 | cc_proto_library( 18 | name = "http_request_response_cc_proto", 19 | deps = [":http_request_response_proto"], 20 | ) 21 | 22 | java_proto_library( 23 | name = "http_request_response_java_proto", 24 | deps = [":http_request_response_proto"], 25 | ) 26 | 27 | java_lite_proto_library( 28 | name = "http_request_response_java_proto_lite", 29 | deps = [":http_request_response_proto"], 30 | ) 31 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/runtime/OwnedValueId.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | package org.genc.runtime; 17 | 18 | final class OwnedValueId { 19 | static { 20 | System.loadLibrary("owned_value_id_jni"); 21 | } 22 | 23 | public static OwnedValueId create(long nativeHandle) { 24 | return new OwnedValueId(nativeHandle); 25 | } 26 | 27 | public ValueId ref() { 28 | return ValueId.create(ref(this.nativeHandle)); 29 | } 30 | 31 | private OwnedValueId(long nativeHandle) { 32 | this.nativeHandle = nativeHandle; 33 | } 34 | 35 | private long nativeHandle; 36 | 37 | private static native long ref(long nativeHandle); 38 | } 39 | -------------------------------------------------------------------------------- /genc/java/src/java/org/genc/runtime/ValueId.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | package org.genc.runtime; 17 | 18 | final class ValueId { 19 | 20 | public static ValueId create(long value) { 21 | return new ValueId(value); 22 | } 23 | 24 | public long getValue() { 25 | return this.value; 26 | } 27 | 28 | private ValueId(long value) { 29 | this.value = value; 30 | } 31 | 32 | private long value; 33 | } 34 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/googleai/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/googleai/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_test") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | java_test( 10 | name = "GoogleAiClientTest", 11 | srcs = ["GoogleAiClientTest.java"], 12 | deps = [ 13 | "//genc/java/src/java/org/genc/interop/backends/googleai:google_ai_client", 14 | "//genc/java/src/java/org/genc/interop/network:http_client", 15 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto", 16 | "//genc/proto/v0:computation_java_proto", 17 | "@com_google_protobuf//java/lite", 18 | "@maven//:com_google_guava_guava", 19 | "@maven//:com_google_truth_truth", 20 | "@maven//:junit_junit", 21 | "@maven//:org_mockito_mockito_core", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/mediapipe/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/mediapipe/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | android_local_test( 8 | name = "LlmInferenceClientTest", 9 | srcs = ["LlmInferenceClientTest.java"], 10 | manifest = "AndroidManifest.xml", 11 | deps = [ 12 | "//genc/java/src/java/org/genc/interop/backends/mediapipe:llm_inference_client", 13 | "//genc/proto/v0:computation_java_proto_lite", 14 | "@maven//:androidx_test_ext_junit", 15 | "@maven//:com_google_mediapipe_tasks_genai", 16 | "@maven//:com_google_truth_truth", 17 | "@maven//:org_robolectric_annotations", 18 | "@maven//:org_robolectric_robolectric", 19 | "@maven//:org_robolectric_shadows_framework", 20 | "@robolectric//bazel:android-all", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/openai/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/openai/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_test") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | java_test( 10 | name = "OpenAiClientTest", 11 | srcs = ["OpenAiClientTest.java"], 12 | deps = [ 13 | "//genc/java/src/java/org/genc/interop/backends/openai:open_ai_client", 14 | "//genc/java/src/java/org/genc/interop/network:http_client", 15 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto", 16 | "//genc/proto/v0:computation_java_proto", 17 | "@com_google_protobuf//java/lite", 18 | "@maven//:com_google_guava_guava", 19 | "@maven//:com_google_truth_truth", 20 | "@maven//:junit_junit", 21 | "@maven//:org_mockito_mockito_core", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/wolframalpha/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/backends/wolframalpha/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_java//java:defs.bzl", "java_test") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | java_test( 10 | name = "WolframAlphaClientTest", 11 | srcs = ["WolframAlphaClientTest.java"], 12 | deps = [ 13 | "//genc/java/src/java/org/genc/interop/backends/wolframalpha:wolfram_alpha_client", 14 | "//genc/java/src/java/org/genc/interop/network:http_client", 15 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto", 16 | "//genc/proto/v0:computation_java_proto", 17 | "@com_google_protobuf//java/lite", 18 | "@maven//:com_google_guava_guava", 19 | "@maven//:com_google_truth_truth", 20 | "@maven//:junit_junit", 21 | "@maven//:org_mockito_mockito_core", 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/network/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /genc/java/src/javatests/org/genc/interop/network/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | android_local_test( 8 | name = "HttpClientImplTest", 9 | srcs = ["HttpClientImplTest.java"], 10 | manifest = "AndroidManifest.xml", 11 | deps = [ 12 | "//genc/java/src/java/org/genc/interop/network:http_client_impl", 13 | "//genc/java/src/java/org/genc/interop/network/api/proto:http_request_response_java_proto_lite", 14 | "@com_google_protobuf//java/lite", 15 | "@maven//:androidx_test_ext_junit", 16 | "@maven//:com_google_guava_guava", 17 | "@maven//:com_google_truth_truth", 18 | "@maven//:org_chromium_net_cronet_api", 19 | "@maven//:org_mockito_mockito_core", 20 | "@maven//:org_robolectric_annotations", 21 | "@maven//:org_robolectric_robolectric", 22 | "@maven//:org_robolectric_shadows_framework", 23 | "@robolectric//bazel:android-all", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /genc/java/src/jni/BUILD: -------------------------------------------------------------------------------- 1 | # Java native interfaces for GenC components. 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | exports_files( 10 | srcs = [ 11 | "executor_jni.cc", 12 | "executor_jni.h", 13 | "owned_value_id_jni.cc", 14 | "owned_value_id_jni.h", 15 | ], 16 | visibility = ["//visibility:public"], 17 | ) 18 | 19 | cc_library( 20 | name = "jni_utils", 21 | srcs = ["jni_utils.cc"], 22 | hdrs = ["jni_utils.h"], 23 | copts = [ 24 | "-Wno-write-strings", # The generated JNI header fails this. 25 | "-Wno-writable-strings", # The generated JNI header fails this. 26 | ], 27 | visibility = ["//visibility:public"], 28 | deps = [ 29 | "//genc/java/src/jni:copy_jni_hdr_lib", 30 | "@bazel_tools//tools/jdk:jni", 31 | "@com_google_absl//absl/log", 32 | "@com_google_absl//absl/status", 33 | "@com_google_absl//absl/status:statusor", 34 | ], 35 | alwayslink = 1, 36 | ) 37 | 38 | genrule( 39 | name = "copy_link_jni_md_header", 40 | srcs = ["@bazel_tools//tools/jdk:jni_md_header-linux"], 41 | outs = ["jni_md.h"], 42 | cmd = "cp -f $< $@", 43 | ) 44 | 45 | genrule( 46 | name = "copy_link_jni_header", 47 | srcs = ["@bazel_tools//tools/jdk:jni_header"], 48 | outs = ["jni.h"], 49 | cmd = "cp -f $< $@", 50 | ) 51 | 52 | cc_library( 53 | name = "copy_jni_hdr_lib", 54 | hdrs = [ 55 | ":copy_link_jni_header", 56 | ":copy_link_jni_md_header", 57 | ], 58 | includes = ["."], 59 | ) 60 | -------------------------------------------------------------------------------- /genc/java/src/native/org/genc/authoring/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "constructor_jni_lib", 9 | srcs = ["constructor.cc"], 10 | visibility = ["//visibility:public"], 11 | deps = [ 12 | "//genc/cc/authoring:constructor", 13 | "//genc/cc/runtime:status_macros", 14 | "//genc/java/src/jni:copy_jni_hdr_lib", 15 | "//genc/java/src/jni:jni_utils", 16 | "@bazel_tools//tools/jdk:jni", 17 | "@com_google_absl//absl/log", 18 | "@com_google_absl//absl/status", 19 | "@com_google_absl//absl/status:statusor", 20 | "@com_google_absl//absl/strings", 21 | ], 22 | alwayslink = 1, 23 | ) 24 | 25 | cc_binary( 26 | name = "libconstructor_jni.so", 27 | linkopts = [ 28 | "-Wl,--no-undefined", 29 | ], 30 | linkshared = 1, 31 | linkstatic = 1, 32 | deps = [ 33 | ":constructor_jni_lib", 34 | ], 35 | ) 36 | 37 | cc_library( 38 | name = "libconstructor_jni_lib", 39 | srcs = [":libconstructor_jni.so"], 40 | alwayslink = 1, 41 | ) 42 | -------------------------------------------------------------------------------- /genc/java/src/native/org/genc/examples/executors/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "default_executor_jni_lib", 9 | srcs = ["default_executor.cc"], 10 | visibility = ["//visibility:public"], 11 | deps = [ 12 | "//genc/c/runtime:c_api", 13 | "//genc/c/runtime:c_api_internal", 14 | "//genc/cc/examples/executors:java_executor_stacks", 15 | "//genc/cc/runtime:status_macros", 16 | "//genc/java/src/jni:copy_jni_hdr_lib", 17 | "//genc/java/src/jni:jni_utils", 18 | "@bazel_tools//tools/jdk:jni", 19 | "@com_google_absl//absl/log", 20 | "@com_google_absl//absl/status", 21 | "@com_google_absl//absl/status:statusor", 22 | "@com_google_absl//absl/strings", 23 | ], 24 | alwayslink = 1, 25 | ) 26 | 27 | cc_binary( 28 | name = "libdefault_executor_jni.so", 29 | linkopts = [ 30 | "-Wl,--no-undefined", 31 | ], 32 | linkshared = 1, 33 | linkstatic = 1, 34 | deps = [":default_executor_jni_lib"], 35 | ) 36 | 37 | cc_library( 38 | name = "libdefault_executor_jni_lib", 39 | srcs = [":libdefault_executor_jni.so"], 40 | visibility = ["//visibility:public"], 41 | alwayslink = 1, 42 | ) 43 | -------------------------------------------------------------------------------- /genc/java/src/native/org/genc/runtime/BUILD: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) 6 | 7 | cc_library( 8 | name = "executor_jni_lib", 9 | srcs = ["executor.cc"], 10 | deps = [ 11 | "//genc/c/runtime:c_api", 12 | "//genc/c/runtime:gc_buffer", 13 | "//genc/cc/runtime:executor", 14 | "//genc/java/src/jni:copy_jni_hdr_lib", 15 | "//genc/proto/v0:computation_cc_proto", 16 | "//genc/proto/v0:executor_cc_proto", 17 | "@bazel_tools//tools/jdk:jni", 18 | ], 19 | alwayslink = 1, 20 | ) 21 | 22 | cc_binary( 23 | name = "libexecutor_jni.so", 24 | linkopts = [ 25 | "-Wl,--no-undefined", 26 | ], 27 | linkshared = True, 28 | linkstatic = True, 29 | deps = [":executor_jni_lib"], 30 | ) 31 | 32 | cc_library( 33 | name = "libexecutor_jni_lib", 34 | srcs = [":libexecutor_jni.so"], 35 | alwayslink = 1, 36 | ) 37 | 38 | cc_library( 39 | name = "owned_value_id_jni_lib", 40 | srcs = ["owned_value_id.cc"], 41 | deps = [ 42 | "//genc/c/runtime:c_api", 43 | "//genc/cc/runtime:executor", 44 | "//genc/java/src/jni:copy_jni_hdr_lib", 45 | "//genc/proto/v0:computation_cc_proto", 46 | "//genc/proto/v0:executor_cc_proto", 47 | "@bazel_tools//tools/jdk:jni", 48 | ], 49 | alwayslink = 1, 50 | ) 51 | 52 | cc_binary( 53 | name = "libowned_value_id_jni.so", 54 | linkopts = [ 55 | "-Wl,--no-undefined", 56 | ], 57 | linkshared = True, 58 | linkstatic = True, 59 | deps = [":owned_value_id_jni_lib"], 60 | ) 61 | 62 | cc_library( 63 | name = "libowned_value_id_jni_lib", 64 | srcs = [":libowned_value_id_jni.so"], 65 | alwayslink = 1, 66 | ) 67 | -------------------------------------------------------------------------------- /genc/java/src/native/org/genc/runtime/owned_value_id.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include 17 | 18 | #include "genc/c/runtime/c_api.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | JNIEXPORT jlong JNICALL 25 | Java_org_genc_runtime_OwnedValueId_ref( 26 | JNIEnv* env, jclass clazz, jlong value_handle) { 27 | GC_OwnedValueId* owned_value_id = 28 | reinterpret_cast(value_handle); 29 | return GC_GetValue(owned_value_id); 30 | } 31 | 32 | #ifdef __cplusplus 33 | } // extern "C" 34 | #endif // __cplusplus 35 | -------------------------------------------------------------------------------- /genc/proto/v0/BUILD: -------------------------------------------------------------------------------- 1 | load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") 2 | load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library") 3 | load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") 4 | load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto_library") 5 | load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library") 6 | load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") 7 | 8 | package( 9 | default_visibility = ["//visibility:public"], 10 | ) 11 | 12 | licenses(["notice"]) 13 | 14 | proto_library( 15 | name = "computation_proto", 16 | srcs = ["computation.proto"], 17 | deps = ["@com_google_protobuf//:any_proto"], 18 | ) 19 | 20 | cc_proto_library( 21 | name = "computation_cc_proto", 22 | deps = [":computation_proto"], 23 | ) 24 | 25 | py_proto_library( 26 | name = "computation_py_pb2", 27 | deps = [":computation_proto"], 28 | ) 29 | 30 | java_proto_library( 31 | name = "computation_java_proto", 32 | deps = [":computation_proto"], 33 | ) 34 | 35 | java_lite_proto_library( 36 | name = "computation_java_proto_lite", 37 | deps = [":computation_proto"], 38 | ) 39 | 40 | proto_library( 41 | name = "executor_proto", 42 | srcs = ["executor.proto"], 43 | deps = [":computation_proto"], 44 | ) 45 | 46 | cc_proto_library( 47 | name = "executor_cc_proto", 48 | deps = [":executor_proto"], 49 | ) 50 | 51 | cc_grpc_library( 52 | name = "executor_cc_grpc_proto", 53 | srcs = [":executor_proto"], 54 | grpc_only = True, 55 | deps = [":executor_cc_proto"], 56 | ) 57 | -------------------------------------------------------------------------------- /genc/python/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_library") 2 | 3 | package_group( 4 | name = "python_packages", 5 | packages = [ 6 | "//genc/...", 7 | "//shopping/personalization/tastebuddy/...", 8 | ], 9 | ) 10 | 11 | py_library( 12 | name = "python", 13 | srcs = ["__init__.py"], 14 | visibility = ["//visibility:private"], 15 | deps = [ 16 | "//genc/python/authoring", 17 | "//genc/python/base", 18 | "//genc/python/examples", 19 | "//genc/python/interop", 20 | "//genc/python/runtime", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /genc/python/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Python libraries for GenC.""" 15 | 16 | # pylint: disable=g-importing-member 17 | from genc.python import authoring 18 | from genc.python import base 19 | from genc.python import examples 20 | from genc.python import interop 21 | from genc.python import runtime 22 | # pylint: enable=g-importing-member 23 | -------------------------------------------------------------------------------- /genc/python/authoring/computation_from_intrinsic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Computation override for tracing support for intrinsics.""" 15 | 16 | from genc.proto.v0 import computation_pb2 as pb 17 | from genc.python import base 18 | 19 | 20 | class ComputationFromIntrinsic(base.Computation): 21 | """An override of `Computation` that accepts intrinsic static parameters.""" 22 | 23 | def __init__(self, intrinsic_uri: str): 24 | self._intrinsic_uri = intrinsic_uri 25 | super().__init__(pb.Value(intrinsic=pb.Intrinsic(uri=self._intrinsic_uri))) 26 | 27 | def __getitem__(self, key): 28 | if not key: 29 | return ValueError('Expected at least one intrinsic static argument.') 30 | if isinstance(key, tuple): 31 | if len(key) > 1: 32 | static_arg = base.to_value_proto(list(key)) 33 | else: 34 | static_arg = base.to_value_proto(key[0]) 35 | else: 36 | static_arg = base.to_value_proto(key) 37 | portable_ir = pb.Value( 38 | intrinsic=pb.Intrinsic( 39 | uri=self._intrinsic_uri, static_parameter=static_arg 40 | ) 41 | ) 42 | return base.Computation(portable_ir) 43 | -------------------------------------------------------------------------------- /genc/python/authoring/tracing_intrinsics.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tracing support for intrinsics.""" 15 | 16 | from genc.cc.intrinsics import intrinsic_bindings 17 | from genc.python.authoring.computation_from_intrinsic import ComputationFromIntrinsic 18 | 19 | 20 | # pylint:disable=invalid-name 21 | # pylint:disable=redefined-outer-name 22 | 23 | 24 | for x in dir(intrinsic_bindings.intrinsics): 25 | if not x.startswith('__'): 26 | name = getattr(intrinsic_bindings.intrinsics, x) 27 | comp = ComputationFromIntrinsic(name) 28 | globals()[name] = comp 29 | 30 | 31 | __all__ = list(globals().keys()) 32 | 33 | 34 | def __getattr__(name): 35 | if name in __all__: 36 | return globals()[name] 37 | else: 38 | raise AttributeError 39 | -------------------------------------------------------------------------------- /genc/python/base/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """API for this Python package.""" 15 | 16 | from genc.python.base.computation import Computation 17 | from genc.python.base.context import Context 18 | from genc.python.base.context import context_stack 19 | from genc.python.base.embed import embed 20 | from genc.python.base.to_from_value_proto import from_value_proto 21 | from genc.python.base.to_from_value_proto import to_value_proto 22 | -------------------------------------------------------------------------------- /genc/python/base/computation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Base classes for defining and managing `Computation` callables.""" 15 | 16 | from genc.proto.v0 import computation_pb2 as pb 17 | from genc.python.base import context 18 | 19 | 20 | class Computation(object): 21 | """Represents a computation internally expressed in terms of portable IR.""" 22 | 23 | def __init__(self, portable_ir: pb.Value): 24 | self._portable_ir = portable_ir 25 | 26 | @property 27 | def portable_ir(self) -> pb.Value: 28 | return self._portable_ir 29 | 30 | def __call__(self, *args, **kwargs): 31 | ctx = context.context_stack.current_context 32 | if not ctx: 33 | raise RuntimeError('There is no current context to handle the call.') 34 | return ctx.call(self._portable_ir, *args, **kwargs) 35 | -------------------------------------------------------------------------------- /genc/python/base/computation_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tests for computation.py.""" 15 | 16 | from absl.testing import absltest 17 | from genc.proto.v0 import computation_pb2 as pb 18 | from genc.python.base import computation 19 | from genc.python.base import context 20 | 21 | 22 | class TestContext(context.Context): 23 | 24 | def call(self, call_target, *args, **kwargs): 25 | return 'called({})'.format(str(call_target).strip()) 26 | 27 | def embed(self, arg): 28 | pass 29 | 30 | 31 | class ComputationTest(absltest.TestCase): 32 | 33 | def test_something(self): 34 | ctx = TestContext() 35 | context.context_stack.append_nested_context(ctx) 36 | comp = computation.Computation(pb.Value(str='foo')) 37 | result = comp('dupa') 38 | context.context_stack.remove_nested_context(ctx) 39 | self.assertEqual(result, 'called(str: "foo")') 40 | 41 | 42 | if __name__ == '__main__': 43 | absltest.main() 44 | -------------------------------------------------------------------------------- /genc/python/base/context_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tests for context.py.""" 15 | 16 | from absl.testing import absltest 17 | from genc.python.base import context 18 | 19 | 20 | class TestContext(context.Context): 21 | 22 | def call(self, call_target, *args, **kwargs): 23 | pass 24 | 25 | def embed(self, arg): 26 | pass 27 | 28 | 29 | class ContextTest(absltest.TestCase): 30 | 31 | def test_something(self): 32 | stk = context.ContextStack() 33 | self.assertIsNone(stk.current_context) 34 | c1 = TestContext() 35 | stk.append_nested_context(c1) 36 | self.assertIs(stk.current_context, c1) 37 | c2 = TestContext() 38 | stk.append_nested_context(c2) 39 | self.assertIs(stk.current_context, c2) 40 | with self.assertRaises(RuntimeError): 41 | stk.remove_nested_context(c1) 42 | c3 = TestContext() 43 | stk.set_default_context(c3) 44 | self.assertIs(stk.current_context, c2) 45 | stk.remove_nested_context(c2) 46 | self.assertIs(stk.current_context, c1) 47 | stk.remove_nested_context(c1) 48 | self.assertIs(stk.current_context, c3) 49 | 50 | 51 | if __name__ == '__main__': 52 | absltest.main() 53 | -------------------------------------------------------------------------------- /genc/python/base/embed.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Support for embed.""" 15 | 16 | from genc.python.base import context 17 | 18 | 19 | def embed(arg): 20 | """Embeds `arg` for use in the current context.""" 21 | ctx = context.context_stack.current_context 22 | if not ctx: 23 | raise RuntimeError('There is no current context to handle the call.') 24 | return ctx.embed(arg) 25 | -------------------------------------------------------------------------------- /genc/python/examples/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """API for this Python package.""" 15 | 16 | from genc.python.examples import executor 17 | 18 | -------------------------------------------------------------------------------- /genc/python/examples/confidential_computing/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_binary") 2 | 3 | py_binary( 4 | name = "client", 5 | srcs = ["client.py"], 6 | deps = ["//genc"], 7 | ) 8 | -------------------------------------------------------------------------------- /genc/python/examples/executor.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Library for getting demo executor.""" 15 | 16 | from genc.cc.examples.executors import executor_bindings 17 | from genc.python import base 18 | from genc.python import runtime 19 | 20 | 21 | def create_default_executor(): 22 | """Creates a default executor used in GenC demos. 23 | 24 | Returns: 25 | An executor that contains handlers for GenC demos. 26 | """ 27 | return executor_bindings.create_default_executor() 28 | 29 | 30 | def set_default_executor(): 31 | base.context_stack.set_default_context( 32 | runtime.SynchronousContext(create_default_executor())) 33 | -------------------------------------------------------------------------------- /genc/python/examples/langchain_demo.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A simple example that shows how to execute some code based on LangChain.""" 15 | 16 | from collections.abc import Sequence 17 | from absl import app 18 | from langchain import chains 19 | from langchain import prompts 20 | from genc.python import interop 21 | from genc.python import runtime 22 | from genc.python.examples import executor 23 | 24 | 25 | def main(argv: Sequence[str]) -> None: 26 | if len(argv) > 1: 27 | raise app.UsageError("Too many command-line arguments.") 28 | 29 | my_chain = chains.LLMChain( 30 | llm=interop.langchain.CustomModel(uri="test_model"), 31 | prompt=prompts.PromptTemplate( 32 | input_variables=["location"], 33 | template="Q: What should I pack for a trip to {location}? A: ", 34 | ), 35 | ) 36 | 37 | comp_pb = interop.langchain.create_computation(my_chain) 38 | comp = runtime.Runner(comp_pb, executor.create_default_executor()) 39 | result = comp("a grocery store") 40 | print(result) 41 | 42 | 43 | if __name__ == "__main__": 44 | app.run(main) 45 | -------------------------------------------------------------------------------- /genc/python/examples/tools_wolfram_demo.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A simple example that shows how to execute execute tools.""" 15 | 16 | from collections.abc import Sequence 17 | 18 | from absl import app 19 | from absl import flags 20 | 21 | from genc.proto.v0 import computation_pb2 as pb 22 | from genc.python import authoring 23 | from genc.python import runtime 24 | from genc.python.examples import executor 25 | 26 | # An example that calls WolframAlpha as part of the computation. 27 | FLAGS = flags.FLAGS 28 | flags.DEFINE_string("appid", None, "appid of WolframAlpha", required=True) 29 | 30 | 31 | def main(argv: Sequence[str]) -> None: 32 | if len(argv) > 1: 33 | raise app.UsageError("Too many command-line arguments.") 34 | 35 | tool_call = authoring.create_wolfram_alpha(FLAGS.appid) 36 | comp = runtime.Runner(comp_pb=tool_call, 37 | executor=executor.create_default_executor()) 38 | 39 | request = pb.Value() 40 | request.str = "what is the result of 2^2-2-3+4*100" 41 | print(comp(request)) 42 | 43 | 44 | if __name__ == "__main__": 45 | app.run(main) 46 | -------------------------------------------------------------------------------- /genc/python/interop/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_library") 2 | 3 | py_library( 4 | name = "interop", 5 | srcs = ["__init__.py"], 6 | visibility = [ 7 | "//genc:__subpackages__", 8 | ], 9 | deps = [ 10 | "//genc/python/interop/gemini", 11 | "//genc/python/interop/langchain", 12 | "//genc/python/interop/llamacpp", 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /genc/python/interop/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Interop libraries.""" 15 | 16 | from genc.python.interop import gemini 17 | from genc.python.interop import langchain 18 | from genc.python.interop import llamacpp 19 | -------------------------------------------------------------------------------- /genc/python/interop/gemini/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_library", "py_test") 2 | 3 | package_group( 4 | name = "gemini_interop", 5 | packages = [ 6 | "//genc/python/interop/gemini/...", 7 | ], 8 | ) 9 | 10 | py_library( 11 | name = "gemini", 12 | srcs = ["__init__.py"], 13 | visibility = [ 14 | "//genc/python:python_packages", 15 | ], 16 | deps = [ 17 | ":create_config", 18 | ], 19 | ) 20 | 21 | py_library( 22 | name = "create_config", 23 | srcs = ["create_config.py"], 24 | ) 25 | 26 | py_test( 27 | name = "create_config_test", 28 | srcs = ["create_config_test.py"], 29 | deps = [":create_config"], 30 | ) 31 | -------------------------------------------------------------------------------- /genc/python/interop/gemini/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Interop libraries for Gemini.""" 15 | 16 | from genc.python.interop.gemini.create_config import create_config 17 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Interop libraries for LangChain.""" 15 | 16 | from genc.python.interop.langchain.create_computation import create_computation 17 | from genc.python.interop.langchain.custom_agent import CustomAgent 18 | from genc.python.interop.langchain.custom_chain import CustomChain 19 | from genc.python.interop.langchain.custom_model import CustomModel 20 | from genc.python.interop.langchain.custom_tool import CustomTool 21 | from genc.python.interop.langchain.model_cascade import ModelCascade 22 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/custom_chain_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for custom_chain.py.""" 15 | 16 | from absl.testing import absltest 17 | from langchain.chains import base 18 | from genc.python.interop.langchain import custom_chain 19 | 20 | 21 | class CustomModelTest(absltest.TestCase): 22 | 23 | def test_creation(self): 24 | my_chain = custom_chain.CustomChain(chained_ops=[]) 25 | self.assertIsInstance(my_chain, base.Chain) 26 | self.assertEqual(my_chain.chained_ops, []) 27 | self.assertEqual(my_chain._chain_type, 'genc_custom_chain') 28 | 29 | 30 | if __name__ == '__main__': 31 | absltest.main() 32 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/custom_model.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A class that represents an arbitrary model for use with LangChain APIs.""" 15 | 16 | from typing import Any, List, Mapping, Optional 17 | from langchain.callbacks.manager import CallbackManagerForLLMRun # pylint:disable=g-importing-member 18 | from langchain.llms.base import LLM # pylint:disable=g-importing-member 19 | 20 | 21 | class CustomModel(LLM): 22 | """Represents an arbitrary custom model for use with LangChain APIs.""" 23 | 24 | uri: str = "" 25 | config: dict[str, Any] = {} 26 | 27 | @property 28 | def _llm_type(self) -> str: 29 | return "CustomModel({})".format(self.uri) 30 | 31 | def _call( 32 | self, 33 | prompt: str, 34 | stop: Optional[List[str]] = None, 35 | run_manager: Optional[CallbackManagerForLLMRun] = None, 36 | **kwargs: Any 37 | ) -> str: 38 | raise RuntimeError( 39 | "This is a model placeholder, not to be executed directly." 40 | ) 41 | 42 | @property 43 | def _identifying_params(self) -> Mapping[str, Any]: 44 | """Get the identifying parameters.""" 45 | del self 46 | return {} 47 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/custom_model_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for custom_model.py.""" 15 | 16 | from absl.testing import absltest 17 | from langchain.llms.base import LLM # pylint:disable=g-importing-member 18 | from genc.python.interop.langchain import custom_model 19 | 20 | 21 | class CustomModelTest(absltest.TestCase): 22 | 23 | def test_creation(self): 24 | llm = custom_model.CustomModel(uri='some_model') 25 | self.assertIsInstance(llm, LLM) 26 | self.assertEqual(llm.uri, 'some_model') 27 | self.assertEqual(llm._llm_type, 'CustomModel(some_model)') 28 | 29 | def test_creation_with_config(self): 30 | test_config = {'test_key_1': 'test_value_1', 'test_key_2': 100} 31 | llm = custom_model.CustomModel(uri='some_model', config=test_config) 32 | self.assertIsInstance(llm, LLM) 33 | self.assertEqual(llm.uri, 'some_model') 34 | self.assertEqual(llm._llm_type, 'CustomModel(some_model)') 35 | self.assertEqual(llm.config, test_config) 36 | 37 | 38 | if __name__ == '__main__': 39 | absltest.main() 40 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/custom_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A class that represents an arbitrary tool for use with LangChain APIs.""" 15 | 16 | from typing import Any 17 | from langchain import tools 18 | from genc.python.interop.langchain import custom_chain 19 | 20 | 21 | class CustomTool(tools.BaseTool): 22 | """Represents an arbitrary tool for use with LangChain APIs.""" 23 | 24 | name: str 25 | """A unique name for the tool that clearly communicates its purpose.""" 26 | 27 | description: str 28 | """Describes the tool usage.""" 29 | 30 | computation: custom_chain.CustomChain 31 | """The computation that the tool needs to run.""" 32 | 33 | def _run( 34 | self, 35 | *args: Any, 36 | **kwargs: Any, 37 | ) -> Any: 38 | raise RuntimeError( 39 | "This is a tool placeholder, not to be executed directly." 40 | ) 41 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/custom_tool_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for custom_tool.py.""" 15 | 16 | from absl.testing import absltest 17 | from langchain import tools 18 | from genc.python.interop.langchain import custom_chain 19 | from genc.python.interop.langchain import custom_tool 20 | 21 | 22 | class CustomToolTest(absltest.TestCase): 23 | 24 | def test_creation(self): 25 | test_computation = custom_chain.CustomChain(chained_ops=[]) 26 | tool = custom_tool.CustomTool( 27 | name='test_tool', 28 | description='test tool description', 29 | computation=test_computation, 30 | ) 31 | self.assertIsInstance(tool, tools.BaseTool) 32 | self.assertEqual(tool.name, 'test_tool') 33 | self.assertEqual(tool.description, 'test tool description') 34 | self.assertEqual(tool.computation, test_computation) 35 | 36 | 37 | if __name__ == '__main__': 38 | absltest.main() 39 | -------------------------------------------------------------------------------- /genc/python/interop/langchain/model_cascade_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for model_cascade.py.""" 15 | 16 | from absl.testing import absltest 17 | from langchain.llms.base import LLM # pylint:disable=g-importing-member 18 | from genc.python.interop.langchain import custom_model 19 | from genc.python.interop.langchain import model_cascade 20 | 21 | 22 | class ModelCascadeTest(absltest.TestCase): 23 | 24 | def test_creation(self): 25 | llm1 = custom_model.CustomModel(uri='some_model') 26 | llm2 = custom_model.CustomModel(uri='some_other_model') 27 | llm3 = model_cascade.ModelCascade(models=[llm1, llm2]) 28 | self.assertIsInstance(llm3, LLM) 29 | self.assertLen(llm3.models, 2) 30 | self.assertEqual( 31 | llm3._llm_type, 32 | 'ModelCascade(CustomModel(some_model), CustomModel(some_other_model))', 33 | ) 34 | 35 | 36 | if __name__ == '__main__': 37 | absltest.main() 38 | -------------------------------------------------------------------------------- /genc/python/interop/llamacpp/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_library", "py_test") 2 | 3 | package_group( 4 | name = "llamacpp_interop", 5 | packages = [ 6 | "//genc/python/interop/llamacpp/...", 7 | ], 8 | ) 9 | 10 | py_library( 11 | name = "llamacpp", 12 | srcs = ["__init__.py"], 13 | visibility = [ 14 | "//genc/python:python_packages", 15 | ], 16 | deps = [ 17 | ":create_config", 18 | ":model_inference", 19 | ], 20 | ) 21 | 22 | py_library( 23 | name = "create_config", 24 | srcs = ["create_config.py"], 25 | ) 26 | 27 | py_test( 28 | name = "create_config_test", 29 | srcs = ["create_config_test.py"], 30 | deps = [":create_config"], 31 | ) 32 | 33 | py_library( 34 | name = "model_inference", 35 | srcs = ["model_inference.py"], 36 | deps = [ 37 | ":create_config", 38 | "//genc/proto/v0:computation_py_pb2", 39 | "//genc/python/base", 40 | ], 41 | ) 42 | 43 | py_test( 44 | name = "model_inference_test", 45 | srcs = ["model_inference_test.py"], 46 | deps = [ 47 | ":create_config", 48 | ":model_inference", 49 | "//genc/python/authoring", 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /genc/python/interop/llamacpp/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Interop libraries for LlamCpp.""" 15 | 16 | from genc.python.interop.llamacpp.create_config import create_config 17 | from genc.python.interop.llamacpp.model_inference import model_inference 18 | -------------------------------------------------------------------------------- /genc/python/interop/llamacpp/create_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Utility functions used in LlamaCpp interop.""" 15 | 16 | 17 | def create_config(model_path, **kwargs): 18 | """Creates a config for LlamaCpp. 19 | 20 | Args: 21 | model_path: The path to the model. 22 | **kwargs: Optional keyword arguments to pass to LlamaCpp, such as the 23 | number of threads or max number of tokens. 24 | 25 | Returns: 26 | An instance of the `dict` object. 27 | """ 28 | config = {"model_path": model_path} 29 | config.update(kwargs) 30 | return config 31 | -------------------------------------------------------------------------------- /genc/python/interop/llamacpp/create_config_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for create_config.py.""" 15 | 16 | from absl.testing import absltest 17 | 18 | from genc.python.interop.llamacpp import create_config 19 | 20 | 21 | class CreateConfigTest(absltest.TestCase): 22 | 23 | def test_create_config(self): 24 | self.assertEqual( 25 | create_config.create_config( 26 | "/gemma-7b-it.gguf", num_threads=100, max_tokens=200), 27 | { 28 | "model_path": "/gemma-7b-it.gguf", 29 | "num_threads": 100, 30 | "max_tokens": 200 31 | }) 32 | 33 | 34 | if __name__ == "__main__": 35 | absltest.main() 36 | -------------------------------------------------------------------------------- /genc/python/interop/llamacpp/model_inference.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Utility functions used in LlamaCpp interop.""" 15 | 16 | from genc.proto.v0 import computation_pb2 as pb 17 | from genc.python import base 18 | from genc.python.interop.llamacpp.create_config import create_config 19 | 20 | 21 | def model_inference(model_uri, model_path, **kwargs): 22 | """Creates a model_inference_with_config operator setup for use with LlamaCpp. 23 | 24 | Args: 25 | model_uri: The URI of the model (backed by a LlamaCpp handler). 26 | model_path: The path to the model parameters. 27 | **kwargs: Optional keyword arguments to pass to LlamaCpp, such as the 28 | number of threads or max number of tokens. 29 | 30 | Returns: 31 | Same as `model_inference_with_config` but with the model URI, model path, 32 | and optional LLamaCpp parameters added to the config. 33 | """ 34 | return base.Computation(pb.Value(intrinsic=pb.Intrinsic( 35 | uri="model_inference_with_config", 36 | static_parameter=base.to_value_proto({ 37 | "model_uri": model_uri, 38 | "model_config": create_config(model_path, **kwargs) 39 | })))) 40 | -------------------------------------------------------------------------------- /genc/python/interop/llamacpp/model_inference_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for model_inference.py.""" 15 | 16 | from absl.testing import absltest 17 | 18 | from genc.python import authoring 19 | from genc.python.interop.llamacpp import model_inference 20 | 21 | 22 | class ModelInferenceTest(absltest.TestCase): 23 | 24 | def test_model_inference(self): 25 | @authoring.traced_computation 26 | def foo(x): 27 | return model_inference.model_inference( 28 | "/device/llamacpp", 29 | "/gemma-7b-it.gguf", 30 | num_threads=100, 31 | max_tokens=200)(x) 32 | 33 | @authoring.traced_computation 34 | def bar(x): 35 | return authoring.model_inference_with_config[{ 36 | "model_uri": "/device/llamacpp", 37 | "model_config": { 38 | "model_path": "/gemma-7b-it.gguf", 39 | "num_threads": 100, 40 | "max_tokens": 200}}](x) 41 | 42 | self.assertEqual(str(foo.portable_ir), str(bar.portable_ir)) 43 | 44 | 45 | if __name__ == "__main__": 46 | absltest.main() 47 | -------------------------------------------------------------------------------- /genc/python/runtime/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:defs.bzl", "py_library", "py_test") 2 | 3 | py_library( 4 | name = "runtime", 5 | srcs = ["__init__.py"], 6 | visibility = [ 7 | "//genc:__subpackages__", 8 | ], 9 | deps = [ 10 | ":runner", 11 | ":synchronous_context", 12 | ], 13 | ) 14 | 15 | py_library( 16 | name = "runner", 17 | srcs = ["runner.py"], 18 | data = [ 19 | "//genc/cc/authoring:constructor_bindings.so", 20 | "//genc/cc/intrinsics:intrinsic_bindings.so", 21 | "//genc/cc/runtime:executor_bindings.so", 22 | ], 23 | deps = [ 24 | "//genc/proto/v0:computation_py_pb2", 25 | "//genc/python/base:to_from_value_proto", 26 | ], 27 | ) 28 | 29 | py_test( 30 | name = "runner_test", 31 | srcs = ["runner_test.py"], 32 | deps = [ 33 | ":runner", 34 | "//genc/cc/runtime:executor_bindings", 35 | "//genc/python/authoring", 36 | "//genc/python/runtime", 37 | ], 38 | ) 39 | 40 | py_library( 41 | name = "synchronous_context", 42 | srcs = ["synchronous_context.py"], 43 | deps = [ 44 | ":runner", 45 | "//genc/proto/v0:computation_py_pb2", 46 | "//genc/python/base", 47 | ], 48 | ) 49 | 50 | py_test( 51 | name = "synchronous_context_test", 52 | srcs = ["synchronous_context_test.py"], 53 | deps = [ 54 | ":synchronous_context", 55 | "//genc/cc/runtime:executor_bindings", 56 | "//genc/python/authoring:tracing_context", 57 | "//genc/python/authoring:tracing_decorator", 58 | ], 59 | ) 60 | -------------------------------------------------------------------------------- /genc/python/runtime/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Python wrappers for runtime components.""" 15 | 16 | from genc.python.runtime.runner import Runner 17 | from genc.python.runtime.synchronous_context import set_default_executor 18 | from genc.python.runtime.synchronous_context import SynchronousContext 19 | -------------------------------------------------------------------------------- /genc/python/runtime/synchronous_context.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Synchronous runtime context for ordinary execution.""" 15 | 16 | from genc.proto.v0 import computation_pb2 as pb 17 | from genc.python import base 18 | from genc.python.runtime import runner 19 | 20 | 21 | class SynchronousContext(base.Context): 22 | """A context for synchronous execution of calls to `Computation`.""" 23 | 24 | def __init__(self, executor): 25 | self._executor = executor 26 | 27 | def call(self, portable_ir: pb.Value, *args, **kwargs): 28 | """Processes the call to `portable_ir` in this runtime context. 29 | 30 | Args: 31 | portable_ir: The IR being called. 32 | *args: Positional args. 33 | **kwargs: Keyword args. 34 | 35 | Returns: 36 | The synchronously computed result of this (blocking) call. 37 | """ 38 | return runner.Runner(portable_ir, self._executor)(*args, **kwargs) 39 | 40 | def embed(self, arg): 41 | raise NotImplementedError('Not currently supported in a runtime context.') 42 | 43 | 44 | def set_default_executor(executor=None): 45 | base.context_stack.set_default_context(SynchronousContext(executor)) 46 | -------------------------------------------------------------------------------- /genc/python/runtime/synchronous_context_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Test for synchronous_context.py.""" 15 | 16 | from absl.testing import absltest 17 | from genc.cc.runtime import executor_bindings 18 | from genc.python.authoring import tracing_decorator 19 | from genc.python.runtime import synchronous_context 20 | 21 | 22 | class TracingTest(absltest.TestCase): 23 | 24 | def test_something(self): 25 | executor = executor_bindings.create_default_local_executor() 26 | synchronous_context.set_default_executor(executor) 27 | 28 | @tracing_decorator.traced_computation 29 | def foo(x, y): 30 | del x 31 | return y 32 | 33 | @tracing_decorator.traced_computation 34 | def bar(x, y, z): 35 | return foo(foo(x, y), z) 36 | 37 | self.assertEqual(bar('a', 'b', 'c'), 'c') 38 | 39 | 40 | if __name__ == '__main__': 41 | absltest.main() 42 | -------------------------------------------------------------------------------- /genc/rust/interop/oak/BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_rust//rust:defs.bzl", "rust_static_library") 2 | 3 | package( 4 | default_visibility = ["//genc/c/interop/oak:__pkg__"], 5 | ) 6 | 7 | licenses(["notice"]) 8 | 9 | rust_static_library( 10 | name = "oak_api", 11 | srcs = ["src/lib.rs"], 12 | ) 13 | -------------------------------------------------------------------------------- /genc/rust/interop/oak/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License 14 | # ============================================================================== 15 | 16 | [package] 17 | name = "oak_api" 18 | version = "1.0.0" 19 | include = [ 20 | "Cargo.toml", 21 | "src/*", 22 | ] 23 | 24 | [lib] 25 | 26 | [dependencies] 27 | libc = { version = "*", features = [] } 28 | 29 | [profile.dev] 30 | panic = 'abort' 31 | 32 | [profile.release] 33 | panic = 'abort' 34 | -------------------------------------------------------------------------------- /genc/rust/interop/oak/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #![crate_type = "staticlib"] 17 | 18 | #[derive(Debug)] 19 | #[repr(C)] 20 | pub struct OakHpkeKeyPair { 21 | // TODO(b/333410413): Replace this with an instance of the HPKE key pair obtained from Oak. 22 | boo: i32, 23 | } 24 | 25 | #[no_mangle] 26 | pub unsafe extern "C" fn oak_generate_hpke_key_pair() -> *mut OakHpkeKeyPair { 27 | // TODO(b/333410413): Replace this with code that calls Oak to generate a key 28 | // pair, probably from `oak_containers_orchestrator/src/crypto.rs`, and 29 | // return it here packaged as an instance of `OakHpkeKeyPair`. 30 | let key_pair = OakHpkeKeyPair { boo: 10 }; 31 | return Box::into_raw(Box::new(key_pair)); 32 | } 33 | 34 | #[no_mangle] 35 | pub extern "C" fn oak_delete_hpke_key_pair(key_pair: *mut OakHpkeKeyPair) { 36 | let _ = unsafe { Box::from_raw(key_pair) }; 37 | } 38 | 39 | // TODO(b/333410413): Define the rest of this API. 40 | // - `oak_get_public_key` 41 | // - `oak_create_endorsed_evidence` 42 | // - `oak_decrypt_request` 43 | // - `oak_encrypt_response` 44 | -------------------------------------------------------------------------------- /genc/wasm/examples/genc_demo/BUILD: -------------------------------------------------------------------------------- 1 | load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") 2 | load("@rules_cc//cc:defs.bzl", "cc_binary") 3 | 4 | package( 5 | default_visibility = ["//visibility:public"], 6 | ) 7 | 8 | licenses(["notice"]) 9 | 10 | cc_binary( 11 | name = "genc_demo", 12 | srcs = ["genc_demo.cc"], 13 | linkopts = ["--bind"], 14 | tags = [ 15 | "manual", 16 | ], 17 | ) 18 | 19 | wasm_cc_binary( 20 | name = "genc_demo_wasm", 21 | cc_target = ":genc_demo", 22 | outputs = ["genc_demo.wasm"], 23 | ) 24 | -------------------------------------------------------------------------------- /genc/wasm/examples/genc_demo/genc_demo.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2023, The GenC Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | namespace { 22 | 23 | class GencDemo { 24 | public: 25 | GencDemo() {} 26 | 27 | static std::string run(std::string prompt) { 28 | return "GencDemo's `run` method has not been implemented yet."; 29 | } 30 | 31 | private: 32 | }; 33 | 34 | } // namespace 35 | 36 | EMSCRIPTEN_BINDINGS(genc_demo) { 37 | emscripten::class_("GencDemo") 38 | .constructor() 39 | .class_function("run", &GencDemo::run); 40 | } 41 | 42 | int main(int argc, char** argv) { 43 | std::cout << GencDemo::run("Boo!") << std::endl; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /genc_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/genc/518aa719da6462dd334a56f47884235560f4fe8a/genc_diagram.png -------------------------------------------------------------------------------- /platform_mappings: -------------------------------------------------------------------------------- 1 | # This file allows automatically mapping flags such as '--cpu' to the more 2 | # modern Bazel platforms (https://bazel.build/concepts/platforms). 3 | 4 | flags: 5 | --cpu=arm64-v8a 6 | --crosstool_top=//external:android/crosstool 7 | //:android_arm64_platform 8 | -------------------------------------------------------------------------------- /platforms.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2023, The GenC Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Creates 'config_setting' and 'platform' BUILD rules with same constraints.""" 16 | 17 | def config_setting_and_platform( 18 | name, 19 | constraint_values = [], 20 | visibility = None): 21 | """Defines 'config_setting', 'platform' rules with same constraints. 22 | 23 | Args: 24 | name: name of the 'config_setting'. Platform rule's name is suffixed with '_platform'. 25 | constraint_values: constraints to meet. 26 | visibility: target visibility. 27 | """ 28 | native.config_setting( 29 | name = name, 30 | constraint_values = constraint_values, 31 | visibility = visibility, 32 | ) 33 | 34 | native.platform( 35 | name = name + "_platform", 36 | constraint_values = constraint_values, 37 | visibility = visibility, 38 | ) 39 | --------------------------------------------------------------------------------