Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ell serialization refactor / distributed 2 #362

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0c12db6
add docker files
alex-dixon Nov 2, 2024
2a36678
add serialization types
alex-dixon Nov 2, 2024
1880d66
add get_lmp method to store interface
alex-dixon Nov 2, 2024
8d5e72f
implement get_lmp, support in-memory sqlite for testing
alex-dixon Nov 2, 2024
d70adbd
create sqlmodels from serialized
alex-dixon Nov 2, 2024
1d840fd
add serialization clients
alex-dixon Nov 2, 2024
bc77671
add api server, tests
alex-dixon Nov 2, 2024
29dd707
start add api extras
alex-dixon Nov 2, 2024
59bf4cb
add dockerignore
alex-dixon Nov 2, 2024
bea7d6a
fix typo
alex-dixon Nov 2, 2024
8e8428d
add docker build arguments with ell extras
alex-dixon Nov 2, 2024
5298d41
add missing api-server main
alex-dixon Nov 2, 2024
ed43769
sidestep package not installed error
alex-dixon Nov 2, 2024
c2fa5c7
fix: import base model from pydantic
alex-dixon Nov 2, 2024
d73f17b
checkpoint
alex-dixon Nov 3, 2024
20533ba
default required deps in studio, api server images
alex-dixon Nov 3, 2024
918cd4a
allow api.pubsub module so code can be shared
alex-dixon Nov 3, 2024
0e26714
add api.client module
alex-dixon Nov 3, 2024
523edb2
fix imports
alex-dixon Nov 5, 2024
cd0fcf8
centralize missing extras error
alex-dixon Nov 8, 2024
7f82ee8
add serialize module, minio blob store
alex-dixon Nov 10, 2024
3f39f86
remove unnecessary cast
alex-dixon Nov 10, 2024
e39cb6d
update tests
alex-dixon Nov 10, 2024
b2d5d84
rename client to serializer
alex-dixon Nov 10, 2024
a71c28f
add serializer to core
alex-dixon Nov 10, 2024
651fbfd
port invocation contents serialize fixes
alex-dixon Nov 11, 2024
1209cd8
json serialization over http
alex-dixon Nov 17, 2024
0c6e738
Merge branch 'main' into distributed
alex-dixon Nov 17, 2024
ff3327b
fix typo
alex-dixon Nov 17, 2024
3dc4344
tool call params dict or basemodel
alex-dixon Nov 17, 2024
26d1eeb
properly serialize tool call params in providers
alex-dixon Nov 17, 2024
1276eb6
simplify params serialization, add tool reference
alex-dixon Nov 18, 2024
7c935db
content block parsed serde
alex-dixon Nov 19, 2024
4745314
Merge branch 'main' into distributed
alex-dixon Nov 19, 2024
e572492
refactor(serialize): remove redundant code in sql store wrappers
alex-dixon Nov 19, 2024
ff609fd
fix: created_at not optional if defaulted
alex-dixon Nov 19, 2024
441b69d
naming: use 'coerce' for conversions
alex-dixon Nov 19, 2024
3440233
Merge branch 'main' into distributed
alex-dixon Nov 19, 2024
3db907c
refactor: dedupe http error handling
alex-dixon Nov 19, 2024
b1a2445
refactor(serialize): put uses in WriteLMPInput instead of second argu…
alex-dixon Nov 20, 2024
1c3af0f
add http client tests
alex-dixon Nov 20, 2024
121de02
Merge branch 'main' into distributed
alex-dixon Nov 20, 2024
a8e2417
use stores.models
alex-dixon Nov 20, 2024
b2b416a
allow dburl none if engine provided
alex-dixon Nov 20, 2024
7bc69f8
Merge branch 'main' into distributed
alex-dixon Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**/__pycache__/
.pytest_cache/
.git
.github
.vscode
.DS_Store
.env
docs
examples
tests
x
25 changes: 25 additions & 0 deletions docker/Dockerfile.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.12

WORKDIR /app

ARG ELL_EXTRAS="api-server postgres mqtt"

# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN pip install --no-cache-dir poetry

# Copy only requirements to cache them in docker layer
COPY pyproject.toml poetry.lock* ./

# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install --extras="api-server ${ELL_EXTRAS}" --no-interaction --no-ansi

# Copy project
COPY src .

CMD ["python", "-m", "ell.api"]
49 changes: 49 additions & 0 deletions docker/Dockerfile.studio
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Start with a Node.js base image for building the React app
FROM node:20 AS client-builder

WORKDIR /app/ell-studio

# Copy package.json and package-lock.json (if available)
COPY ell-studio/package.json ell-studio/package-lock.json* ./

# Install dependencies
RUN npm ci

# Copy the rest of the client code
COPY ell-studio .

# Build the React app
RUN npm run build

# Now, start with the Python base image
FROM python:3.12

ARG ELL_EXTRAS=""

RUN echo "ELL_EXTRAS=${ELL_EXTRAS}"

WORKDIR /app


# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN pip install --no-cache-dir poetry

# Copy only requirements to cache them in docker layer
COPY pyproject.toml poetry.lock* ./

# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install --extras="studio ${ELL_EXTRAS}" --no-interaction --no-ansi

# Copy the Python project
COPY src .

# Copy the built React app from the client-builder stage
COPY --from=client-builder /app/ell-studio/build /app/ell/studio/static

CMD ["python", "-m", "ell.studio"]
115 changes: 115 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: ell
version: "3.9"
services:
api:
build:
context: ..
dockerfile: docker/Dockerfile.api
args:
ELL_EXTRAS: postgres mqtt minio
tags:
- ell-api

ports:
- "8081:8081"
environment:
- ELL_API_HOST=0.0.0.0
- ELL_API_PORT=8081
- ELL_PG_CONNECTION_STRING=postgresql://ell_user:ell_password@postgres:5432/ell_db
- ELL_MQTT_CONNECTION_STRING=mqtt://mqtt:1883
- LOG_LEVEL=10 # debug
- ELL_MINIO_ENDPOINT=minio:9000
- ELL_MINIO_ACCESS_KEY=minio_user
- ELL_MINIO_SECRET_KEY=minio_password
- ELL_MINIO_BUCKET=ell-bucket
depends_on:
- postgres
- mqtt
- minio

studio:
build:
context: ..
dockerfile: docker/Dockerfile.studio
args:
ELL_EXTRAS: postgres mqtt minio
tags:
- ell-studio
ports:
- "8080:8080"
environment:
- ELL_STUDIO_HOST=0.0.0.0
- ELL_STUDIO_PORT=8080
- ELL_PG_CONNECTION_STRING=postgresql://ell_user:ell_password@postgres:5432/ell_db
- ELL_MQTT_CONNECTION_STRING=mqtt://mqtt:1883
- ELL_MINIO_ENDPOINT=minio:9000
- ELL_MINIO_ACCESS_KEY=minio_user
- ELL_MINIO_SECRET_KEY=minio_password
- ELL_MINIO_BUCKET=ell-bucket
depends_on:
- postgres
- mqtt
- minio
develop:
watch:
- action: sync+restart
path: ./src/ell/studio
target: /app/ell/studio

mqtt:
image: eclipse-mosquitto:latest
ports:
- "1883:1883"
command: mosquitto -c /mosquitto/config/mosquitto.conf
volumes:
- mosquitto_config:/mosquitto/config
depends_on:
- mqtt-config

mqtt-config:
image: busybox
volumes:
- mosquitto_config:/mosquitto/config
command: >
sh -c "echo 'listener 1883' > /mosquitto/config/mosquitto.conf &&
echo 'allow_anonymous true' >> /mosquitto/config/mosquitto.conf"

postgres:
image: postgres:16
environment:
- POSTGRES_USER=ell_user
- POSTGRES_PASSWORD=ell_password
- POSTGRES_DB=ell_db
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"

minio:
image: minio/minio:latest
ports:
- "9000:9000" # API port
- "9001:9001" # Console port
environment:
- MINIO_ROOT_USER=minio_user
- MINIO_ROOT_PASSWORD=minio_password
volumes:
- minio_data:/data
command: server --console-address ":9001" --address ":9000" /data

minio-init:
image: minio/mc
depends_on:
- minio
entrypoint: >
/bin/sh -c "
sleep 5;
/usr/bin/mc alias set myminio http://minio:9000 minio_user minio_password --api S3v4;
/usr/bin/mc mb myminio/ell-bucket;
exit 0;
"

volumes:
postgres_data:
mosquitto_config:
minio_data:
25 changes: 25 additions & 0 deletions examples/future/http_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pydantic import Field
import ell

ell.init(api_url='http://localhost:8081')

@ell.tool()
def get_weather(location: str = Field(description="The full name of a city and country, e.g. San Francisco, CA, USA")):
"""Get the current weather for a given location."""
# Simulated weather API call
return f"The weather in {location} is sunny."

@ell.complex(model="gpt-4o", tools=[get_weather])
def travel_planner(destination: str):
"""Plan a trip based on the destination and current weather."""
return [
ell.system("You are a travel planner. Use the weather tool to provide relevant advice."),
ell.user(f"Plan a trip to {destination}")
]

result = travel_planner("Paris")
print(result.text) # Prints travel advice
if result.tool_calls:
# This is done so that we can pass the tool calls to the language model
tool_results = result.call_tools_and_collect_as_message()
print("Weather info:", (tool_results.text))
38 changes: 38 additions & 0 deletions examples/future/images_minio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from PIL import Image
import os

import ell
from ell.stores.minio import MinioBlobStore, MinioConfig
from ell.stores.sql import PostgresStore


# Load the image using PIL
big_picture = Image.open(os.path.join(os.path.dirname(__file__), "bigpicture.jpg"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe download the big picture instead of keeping in repo


@ell.simple(model="gpt-4o", temperature=0.5)
def make_a_joke_about_the_image(image: Image.Image):
return [
ell.system("You are a meme maker. You are given an image and you must make a joke about it."),
ell.user(image)
]



if __name__ == "__main__":
# Run "docker compose up" inside the `docker` folder to run
# ell studio with minio for blob storage with postgres
blob_store = MinioBlobStore(
config=MinioConfig(
endpoint="localhost:9000",
access_key="minio_user",
secret_key="minio_password",
bucket="ell-bucket",
)
)
store = PostgresStore(
db_uri="postgresql://ell_user:ell_password@localhost:5432/ell_db",
blob_store=blob_store,
)
ell.init(store=store, autocommit=True, verbose=True)
joke = make_a_joke_about_the_image(big_picture)
print(joke)
Loading
Loading