{ "cells": [ { "cell_type": "code", "metadata": { "jukit_cell_id": "O4HPx3boF0" }, "source": [], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": { "jukit_cell_id": "hqQkbPEwTJ" }, "source": [ "# Using the DockerWrapper utility" ] }, { "cell_type": "code", "metadata": { "jukit_cell_id": "vCepuypaFH" }, "source": [ "from langchain.utilities.docker import DockerWrapper" ], "outputs": [], "execution_count": null }, { "cell_type": "code", "metadata": { "jukit_cell_id": "BtYVqy2YtO" }, "source": [ "d = DockerWrapper(image='shell')" ], "outputs": [], "execution_count": null }, { "cell_type": "code", "metadata": { "jukit_cell_id": "ELWWm03ptQ" }, "source": [ "query = \"\"\"\n", "for i in $(seq 1 10)\n", "do\n", " echo $i\n", "done\n", "\"\"\"\n", "print(d.exec_run(query))" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" } ], "execution_count": 1 }, { "cell_type": "code", "metadata": { "jukit_cell_id": "lGMqLz5sDo" }, "source": [ "p = DockerWrapper(image='python')\n", "\n", "py_payload = \"\"\"\n", "def hello_world():\n", " return 'hello world'\n", "\n", "hello_world()\n", "\"\"\"" ], "outputs": [], "execution_count": null }, { "cell_type": "code", "metadata": { "jukit_cell_id": "X04Wd6zbrk" }, "source": [ "print(p.exec_run(py_payload))" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": "'hello world'\n" } ], "execution_count": 2 }, { "cell_type": "code", "metadata": { "jukit_cell_id": "lKOfuDoJGk" }, "source": [], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": { "jukit_cell_id": "eSzXtDrpqU" }, "source": [ "## Passing custom parameters\n", "\n", "By default containers are run with a safe set of parameters. You can pass any parameters\n", "that are accepted by the docker python sdk to the run and exec commands.\n", "\n", "### Using networking" ] }, { "cell_type": "code", "metadata": { "jukit_cell_id": "eWFGCxD9pv" }, "source": [ "# by default containers don't have access to the network\n", "print(d.run('ping -c 1 google.com'))" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": "STDERR: Command '/bin/sh -c 'ping -c 1 google.com'' in image 'alpine:latest' returned non-zero exit status 1: b\"ping: bad address 'google.com'\\n\"\n" } ], "execution_count": 3 }, { "cell_type": "code", "metadata": { "jukit_cell_id": "Z0YkpuXVyL" }, "source": [ "# using the network parameter\n", "print(d.run('ping -c 1 google.com', network='bridge'))" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": "PING google.com (142.250.200.110): 56 data bytes\n64 bytes from 142.250.200.110: seq=0 ttl=42 time=13.695 ms\n\n--- google.com ping statistics ---\n1 packets transmitted, 1 packets received, 0% packet loss\nround-trip min/avg/max = 13.695/13.695/13.695 ms\n" } ], "execution_count": 4 }, { "cell_type": "code", "metadata": { "jukit_cell_id": "3rMWzzuLHq" }, "source": [], "outputs": [], "execution_count": null } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "python", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 4 }