{"id":23209204,"url":"https://github.com/algorithmiaio/langpacks","last_synced_at":"2025-10-15T09:02:15.962Z","repository":{"id":37664898,"uuid":"51426484","full_name":"algorithmiaio/langpacks","owner":"algorithmiaio","description":"Standardized builder and runners for Algorithmia algorithms","archived":false,"fork":false,"pushed_at":"2023-10-03T22:51:56.000Z","size":60033,"stargazers_count":16,"open_issues_count":18,"forks_count":9,"subscribers_count":20,"default_branch":"develop","last_synced_at":"2024-03-26T13:00:04.080Z","etag":null,"topics":["algorithmia","algorithms","machine-learning"],"latest_commit_sha":null,"homepage":"https://algorithmia.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algorithmiaio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-10T07:18:14.000Z","updated_at":"2024-03-26T13:00:04.080Z","dependencies_parsed_at":"2022-09-09T04:01:27.769Z","dependency_job_id":null,"html_url":"https://github.com/algorithmiaio/langpacks","commit_stats":null,"previous_names":[],"tags_count":100,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algorithmiaio%2Flangpacks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algorithmiaio%2Flangpacks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algorithmiaio%2Flangpacks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algorithmiaio%2Flangpacks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algorithmiaio","download_url":"https://codeload.github.com/algorithmiaio/langpacks/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230318623,"owners_count":18207812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithmia","algorithms","machine-learning"],"created_at":"2024-12-18T18:15:25.886Z","updated_at":"2025-10-15T09:02:10.915Z","avatar_url":"https://github.com/algorithmiaio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LangPacks\n\n*LangPack*: A language-specific package that encompasses steps to set up, build, and run language-specific algorithms.\n\n*LangServer*: A server that serves a LangPack's `bin/pipe` runner in a way that emulates a light-weight version of the Algorithmia API.\n\n## LangServer\n\nLangServer could be simplified like this: it's about 1000 lines of code that emulates a simple API that looks/feels like our API server's API for calling an algo (lacking features like auth).\n\nIt translates that HTTP standard into a STDIO-based input and a named pipe for output (defined in the langpack_guide.md). Some considerations:\n- It was important that multiple subsequent requests could reuse the same process.\n- The focus was a standard that every language could easily implement. Having each language implement a web-server was considered, but there was uncertainty about how easy that would be for langs like R, and if we wanted to alter how it integrates with the rest of the back end, it'd need to be reimplemented multiple times (e.g., if we wanted to expose stdout/stderr via websockets, it would only need to be implemented in LangServer, not each LangPack).\n- I also considered other queues, e.g., posix message queues, but struggled to gain confidence it would work well for all languages (R again being a concern).\n- Ultimately, every language has very simple ways of interacting with files (including stdio and named pipes), so stdio and a named pipe (fifo) were chosen for the simplicity to work with them in any language. The fifo choice allowed us to leave stdout/stderr intact.\n\nWeirder details:\n1) LangServer spins up 2 threads that collect stdout/stderr and recombine them into the result.\n2) LangServer has 2 modes: sync vs. async. Basically, sync is how it was originally built, to be easy to debug as a simple web-server that looks like the API server. `async` mode was added to make it integrate with dockherder, so that dockherder could call it and forget about it until a callback informed dockherder that it was complete.\n\n## Building LangServer(s) (Partially deprecated)\n\nDisclaimer: The intent was to prototype LangServer in Rust (because I knew it better), but finally write it in Go (lower barrier to entry), but it turned into an official project before the rewrite happened. So, for now: start by installing [latest stable Rust](https://www.rust-lang.org/downloads.html), and then:\n\n```\nbin/build langserver     # just builds the base LangServer images (default)\nbin/build \u003clang\u003e         # builds language-specific image (and deps)\nbin/build all            # builds all images for all langpacks\nbin/build single-runner  # builds 1 image containing the LangServer runner and running setup on all langpacks\nbin/build single-builder # builds 1 image containing the LangServer builder and running setup on all langpacks\nbin/build single         # builds the single-runner and single-builder\n```\n\nNote: the initial plan is to NOT use these images, but they are helpful for implementing and testing langpacks locally, as well as provide some \"code documentation\" for how setup/build/pipe/langserver all fit together.\n\n## Building LangServer with Libraries\nWe're in the process of refactoring the way that images get generated and algorithms are compiled. The initial approach would create an `algorithm.zip` that contains a compiled binary (or source for interpreted languages) along with any dependencies needed. Additionally, a number of libraries were installed side-by-side which made it difficult to debug in certain scenarios or independently evolve various languages. In particular, some libraries required certain variables set during install/compilation but not during execution and it was difficult to determine what variables or even system packages were needed for what libraries in particular.\n\nThe new process (still experimental) involves templating a Dockerfile based on a set of desired `libraries` (which could be language runtimes/buildtimes, services, or deep-learning frameworks) and then building an image with just that subset of libraries. Ideally, libraries' install.sh script should be able to run on an Ubuntu 16.04 host/VM the same as it could during Docker build time (this greatly eases creating the install script).\n\nAlgorithms no longer have a single `bin/build` script but two separate scripts, one to `install-dependencies` (which would do an appropriate pip/npm/cargo/etc. install/fetch) and one to `install-algorithm` which compiles or bundles the algorithm source to `/opt/algorithmia`.\n\nTemplating and building a Dockerfile:\n```\n$ ./bin/build-template --help\nusage: build-template [-h] [-l LIBRARY] [-p TEMPLATE] -t TAG [-o OUTPUT]\n                      [-u USER_ID]\n\nCreates a Dockerfile, templating in any needed files and environment variables\nto set up different libraries. Libraries will be installed _in order\nspecified_ so if one needs to be installed before another, then list them in\nthat order on the command line\n\nWill then run a docker build and tag operation\n\nLibrary directories should include the following:\n  - install.sh : a script to install the library\n  - config.json (optional): a json file containing configuration such as:\n    - env_variables: dictionary of environment variables to\n      set at the end of execution\n    - install_scripts: list of order to run scripts in to create\n      multiple layers (particularly for testing)\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -l LIBRARY, --library LIBRARY\n                        library directories to include in generating this\n                        Dockerfile\n  -p TEMPLATE, --template TEMPLATE\n                        location of the Dockerfile template file\n  -t TAG, --tag TAG     tag to label the docker image once produced\n  -o OUTPUT, --output OUTPUT\n                        name of file to write output to\n  -u USER_ID, --user_id USER_ID\n                        user id to use for the \"algo\" user, defaults to\n                        current user\n```\nExamples:\n```\n# Create a langpack consisting only of python2 and tag it as algorithmia/langpack-runner:python2\n./bin/build-template -u 1001 -t algorithmia/langpack-runner:python2 -l python2 -o docker/templated/Dockerfile.python2\n\n# Create a langpack with NVIDIA GPU drivers, python and caffe and tag it as algorithmia/langpack-runner:python2-caffe\n./bin/build-template -u 1001 -t algorithmia/langpack-runner:python2-caffe -l gpu-driver -l python2 -l caffe -o Dockerfile.python2-advanced\n```\n### Building an algorithm\n1. Bind mount an algorithm working directory to `/tmp/build` - `docker run -it -v \\`pwd\\`:/tmp/build algorithmia/langpack-runner:python2`\n2. Run `/tmp/build/bin/install-dependencies`\n3. Run `/tmp/build/bin/install-algorithm`\n4. Outside of the container commit the image with appropriate entrypoint - `docker commit -c 'ENTRYPOINT /bin/init-langserver' -c 'WORKDIR /opt/algorithm' \u003ccontainer_id\u003e algorithmia/\u003calgorithm_name\u003e`\n\n### Running an algorithm\n1. `docker run --rm -ti -p 9999:9999 algorithmia/\u003calgorithm_name\u003e`\n\n## Building an algorithm\n\nBind mount an algorithm working directory to `/tmp/build` and start the langbuilder-\u003clang\u003e image. It should create an algorithm.zip that can be served by the init-langserver script (containing `bin/pipe`, the algorithm, and any dependencies):\n\n```\ndocker run --rm -it -v `pwd`:/tmp/build algorithmia/langbuilder-\u003clang\u003e\n```\n\nNote, unless using Docker user namespacing, don't be shocked if bind-mount writing results in permission errors.\n\n## Running LangServer\n\nThe `init-langserver` script provides 2 ways to run an algorithm:\n\n#### Bind mount algorithm.zip to /tmp/algorithm.zip\nNote: Make sure you use the absolute path to the algorithm.zip.\n```\ndocker run --rm -it -v /path/to/algorithm.zip:/tmp/algorithm.zip -p 9999:9999 algorithmia/langserver-\u003clang\u003e\n```\n\n#### Bind mount algorithm directory to /tmp/algorithm\n```\ndocker run --rm -it -v `pwd`:/tmp/algorithm -p 9999:9999 algorithmia/langserver-\u003clang\u003e\n```\n\n## Contributing\n\nBonus 🌮🌮tacos🌮🌮 for you if you write a LangPack.\n\nMore to come...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgorithmiaio%2Flangpacks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgorithmiaio%2Flangpacks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgorithmiaio%2Flangpacks/lists"}