Skip to content

Commit

Permalink
Merge pull request #13 from dbpunk-labs/feat/add_pip_docker
Browse files Browse the repository at this point in the history
feat: add build package
  • Loading branch information
imotai authored Sep 12, 2023
2 parents cca23b8 + 95fcc89 commit e25dbd0
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 51 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/release_libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# .github/workflows/ci-cd.yml
on: workflow_dispatch
jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: self-hosted
#runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
run: pip install -r requirements.txt

- name: build packages
run: |
TAG=${GITHUB_REF/refs\/tags\//}
VERSION=${TAG#*v}
bash build_package.sh ${VERSION}
- name: Publish Proto
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: proto/dist

- name: Publish Kernel
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: kernel/dist

- name: Publish Agent
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: agent/dist
- name: Publish Chat
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: chat/dist
6 changes: 2 additions & 4 deletions agent/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name="octopus_agent",
version="0.1.2",
version="0.1.1",
description="Open source code interpreter agent for LLM",
author="imotai",
author_email="[email protected]",
Expand All @@ -33,14 +33,12 @@
install_requires=[
"octopus_proto",
"octopus_kernel",
"langchain>=0.0.227",
"langchain>=0.0.286",
"grpcio-tools>=1.57.0",
"grpc-google-iam-v1>=0.12.6",
"aiofiles",
"pydantic",
"python-dotenv",
"openai",
"aiosqlite",
],
entry_points={
"console_scripts": [
Expand Down
1 change: 0 additions & 1 deletion agent/src/octopus_agent/agent_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async def add_kernel(
config.get("max_iterations", 5),
self.verbose,
)
# TODO a data dir per user
self.agents[request.key] = {
"sdk": sdk,
"agent": agent,
Expand Down
8 changes: 2 additions & 6 deletions agent/src/octopus_agent/gpt_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from langchain.tools import StructuredTool
from .tools import OctopusAPIMarkdownOutput
from typing import Any, Dict, List, Optional, Sequence, Union, Type
from pydantic import BaseModel, Field
from langchain.pydantic_v1 import BaseModel, Field
from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
Expand Down Expand Up @@ -63,7 +63,7 @@ class ExecutePythonCodeTool(StructuredTool):
name = "execute_python_code"
description = """Execute arbitrary Python code Returns a Markdown format string including return code, result, stdout, stderr, error"""
args_schema: Type[BaseModel] = ExecutePythonCodeInput
octopus_api: OctopusAPIMarkdownOutput = None
octopus_api: Optional[OctopusAPIMarkdownOutput] = None

def _run(
self,
Expand All @@ -72,8 +72,6 @@ def _run(
saved_filenames: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
if not self.octopus_api:
self.octopus_api = OctopusAPIMarkdownOutput()
code = code
result = self.octopus_api.run(code)
return result
Expand All @@ -85,6 +83,4 @@ async def _arun(
saved_filenames: Optional[List[str]] = None,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> str:
if not self.octopus_api:
self.octopus_api = OctopusAPIMarkdownOutput()
return await self.octopus_api.arun(code)
11 changes: 5 additions & 6 deletions agent/tests/agent_tool_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
logger = logging.getLogger(__name__)
api_base = "127.0.0.1:9527"
api_key = "ZCeI9cYtOCyLISoi488BgZHeBkHWuFUH"
api_data_dir = "/tmp/ws1"


@pytest.fixture
Expand All @@ -41,7 +40,7 @@ def kernel_sdk():
async def test_async_smoke_test(kernel_sdk):
code = "print('hello world!')"
sdk = kernel_sdk
api = OctopusAPIJsonOutput(sdk, api_data_dir)
api = OctopusAPIJsonOutput(sdk)
result = await api.arun(code)
assert not result["result"]
assert result["stdout"] == "hello world!\n"
Expand All @@ -51,7 +50,7 @@ async def test_async_smoke_test(kernel_sdk):
async def test_get_result(kernel_sdk):
sdk = kernel_sdk
code = "5"
api = OctopusAPIJsonOutput(sdk, api_data_dir)
api = OctopusAPIJsonOutput(sdk)
result = await api.arun(code)
assert result["result"]
assert result["result"] == "5"
Expand All @@ -64,7 +63,7 @@ async def test_get_result(kernel_sdk):
async def test_sync_smoke_test_markdown(kernel_sdk):
sdk = kernel_sdk
code = "print('hello world!')"
api = OctopusAPIMarkdownOutput(sdk, api_data_dir)
api = OctopusAPIMarkdownOutput(sdk)
result = await api.arun(code)
assert result.find("The result") < 0
assert result.find("The stdout") >= 0
Expand All @@ -75,7 +74,7 @@ async def test_sync_smoke_test_markdown(kernel_sdk):
async def test_get_result_markdown(kernel_sdk):
sdk = kernel_sdk
code = "5"
api = OctopusAPIMarkdownOutput(sdk, api_data_dir)
api = OctopusAPIMarkdownOutput(sdk)
result = await api.arun(code)
assert result
logger.info(result)
Expand All @@ -96,7 +95,7 @@ async def test_display_result(kernel_sdk):
plt.title('Pie Chart')
plt.show()
"""
api = OctopusAPIJsonOutput(sdk, api_data_dir)
api = OctopusAPIJsonOutput(sdk)
result = await api.arun(code)
assert result["result"]
assert result["result"].find("image/png") >= 0
Expand Down
28 changes: 28 additions & 0 deletions build_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/sh
#
# build_package.sh



WORKDIR=`pwd`
echo "$1"
sed -i -E 's/version\s*=\s*"[^"]*"/version="$1"/' proto/setup.py
sed -i -E 's/version\s*=\s*"[^"]*"/version="$1"/' kernel/setup.py
sed -i -E 's/version\s*=\s*"[^"]*"/version="$1"/' agent/setup.py
sed -i -E 's/version\s*=\s*"[^"]*"/version="$1"/' chat/setup.py
echo "the proto new version"
python3 proto/setup.py --version
echo "the kernel new version"
python3 kernel/setup.py --version
echo "the agent new version"
python3 agent/setup.py --version
echo "the chat new version"
python3 chat/setup.py --version
# build octopus proto package
cd ${WORKDIR}/proto && make && python3 -m build
# build octopus kernel package
cd ${WORKDIR}/kernel && python3 -m build
# build agent package
cd ${WORKDIR}/agent && python3 -m build
# build chat package
cd ${WORKDIR}/chat && python3 -m build
4 changes: 4 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ubuntu
RUN apt update
RUN apt install -y python3 python3-pip
RUN pip install -U octopus_agent octopus_kernel
5 changes: 5 additions & 0 deletions docker/Dockerfile_for_agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM octopus_base
WORKDIR /agent
VOLUME /agent
ADD start_agent.sh /agent/
CMD ["bash", "/agent/start_agent.sh"]
5 changes: 1 addition & 4 deletions docker/Dockerfile_for_kernel
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM python:3.11
ADD requirements_kernel.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
RUN pip install octopus_proto octopus_kernel
FROM octopus_base
WORKDIR /kernel
VOLUME /kernel
ADD start_kernel.sh /kernel/
Expand Down
15 changes: 15 additions & 0 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
kernel:
env_file:
- kernel.env
image: octopus_kernel:latest
ports:
- '9527:9527'
agent:
image: octopus_agent:latest
env_file:
- agent.env
ports:
- '9528:9528'
depends_on:
- kernel
16 changes: 0 additions & 16 deletions docker/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion docker/start_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# start_kernel.sh

echo "rpc_port=${rpc_port}" >.env
echo "rpc_host=127.0.0.1" >>.env
echo "rpc_host=0.0.0.0" >>.env
echo "admin_key=${admin_key}" >>.env
echo "llm_key=${llm_key}" >> .env
echo "max_file_size=20480000" >> .env
Expand Down
3 changes: 1 addition & 2 deletions docker/start_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
echo "config_root_path=/kernel" >.env
echo "workspace=${workspace}" >>.env
echo "rpc_port=${rpc_port}" >>.env
echo "rpc_host=127.0.0.1" >>.env
echo "rpc_host=0.0.0.0" >>.env
echo "rpc_key=${rpc_key}" >>.env

octopus_kernel_rpc_server
Binary file added images/octopus_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions install_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/sh
#
# install_package.sh

WORKDIR=`pwd`
cd ${WORKDIR}/proto && make && pip install .
cd ${WORKDIR}/kernel && pip install .
cd ${WORKDIR}/agent && pip install .
cd ${WORKDIR}/chat && pip install .
2 changes: 1 addition & 1 deletion kernel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name="octopus_kernel",
version="0.1.2",
version="0.1.3",
description="Open source code interpreter agent for LLM",
author="imotai",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/octopus_kernel/server/kernel_rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _build_payload(self, msg, workspace):
if msg["msg_type"] == "display_data":
if "image/png" in msg["content"]["data"]:
filename = "%s.png" % uuid.uuid4().hex
fullpath = "%s/%s" % (data_dir, filename)
fullpath = "%s/%s" % (workspace, filename)
with open(fullpath, "wb+") as fd:
data = msg["content"]["data"]["image/png"].encode("ascii")
buffer = base64.b64decode(data)
Expand Down
2 changes: 1 addition & 1 deletion proto/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name="octopus_proto",
version="0.1.2",
version="0.1.3",
description="Open source code interpreter agent for LLM",
author="imotai",
author_email="[email protected]",
Expand Down
10 changes: 2 additions & 8 deletions start_sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
# start_local.sh
ps -ef | grep python3 | grep -v grep | awk '{print $2}' | while read line; do kill -9 $line; done
WORKDIR=`pwd`

cd ${WORKDIR}/proto && make && pip install .
cd ${WORKDIR}/kernel && pip install .
cd ${WORKDIR}/agent && pip install .
cd ${WORKDIR}/chat && pip install .
bash install_package.sh

mkdir -p ${WORKDIR}/sandbox/kernel
mkdir -p ${WORKDIR}/sandbox/agent
cd ${WORKDIR}/sandbox/kernel
#KERNEL_RPC_KEY=`tr -dc A-Za-z0-9 </dev/urandom | head -c 32; echo ""`
KERNEL_RPC_KEY=ZCeI9cYtOCyLISoi488BgZHeBkHWuFUH
echo ${KERNEL_RPC_KEY}
echo "config_root_path=/tmp/kernel_config"> .env
Expand All @@ -24,7 +19,6 @@ echo "start kernel with endpoint 127.0.0.1:9527"
octopus_kernel_rpc_server > kernel_rpc.log 2>&1 &
sleep 2
cd ${WORKDIR}/sandbox/agent
#AGENT_RPC_KEY=`tr -dc A-Za-z0-9 </dev/urandom | head -c 32; echo ""`
AGENT_RPC_KEY=ZCeI9cYtOCyLISoi488BgZHeBkHWuFUH
echo "start agent with endpoint 127.0.0.1:9528"
echo "rpc_host=127.0.0.1">> .env
Expand All @@ -36,4 +30,4 @@ echo "verbose=True" >> .env
octopus_agent_rpc_server > agent_rpc.log 2>&1 &
sleep 2
echo "add a kernel"
octopus_agent_setup --kernel_endpoint=127.0.0.1:9527 --kernel_api_key=${KERNEL_RPC_KEY} --kernel_workspace=/tmp/ws1 --agent_endpoint=127.0.0.1:9528 --admin_key=${AGENT_RPC_KEY}
octopus_agent_setup --kernel_endpoint=127.0.0.1:9527 --kernel_api_key=${KERNEL_RPC_KEY} --agent_endpoint=127.0.0.1:9528 --admin_key=${AGENT_RPC_KEY}

0 comments on commit e25dbd0

Please sign in to comment.