-
Notifications
You must be signed in to change notification settings - Fork 328
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
alex-dixon
wants to merge
45
commits into
MadcowD:main
Choose a base branch
from
alex-dixon:distributed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 2a36678
add serialization types
alex-dixon 1880d66
add get_lmp method to store interface
alex-dixon 8d5e72f
implement get_lmp, support in-memory sqlite for testing
alex-dixon d70adbd
create sqlmodels from serialized
alex-dixon 1d840fd
add serialization clients
alex-dixon bc77671
add api server, tests
alex-dixon 29dd707
start add api extras
alex-dixon 59bf4cb
add dockerignore
alex-dixon bea7d6a
fix typo
alex-dixon 8e8428d
add docker build arguments with ell extras
alex-dixon 5298d41
add missing api-server main
alex-dixon ed43769
sidestep package not installed error
alex-dixon c2fa5c7
fix: import base model from pydantic
alex-dixon d73f17b
checkpoint
alex-dixon 20533ba
default required deps in studio, api server images
alex-dixon 918cd4a
allow api.pubsub module so code can be shared
alex-dixon 0e26714
add api.client module
alex-dixon 523edb2
fix imports
alex-dixon cd0fcf8
centralize missing extras error
alex-dixon 7f82ee8
add serialize module, minio blob store
alex-dixon 3f39f86
remove unnecessary cast
alex-dixon e39cb6d
update tests
alex-dixon b2d5d84
rename client to serializer
alex-dixon a71c28f
add serializer to core
alex-dixon 651fbfd
port invocation contents serialize fixes
alex-dixon 1209cd8
json serialization over http
alex-dixon 0c6e738
Merge branch 'main' into distributed
alex-dixon ff3327b
fix typo
alex-dixon 3dc4344
tool call params dict or basemodel
alex-dixon 26d1eeb
properly serialize tool call params in providers
alex-dixon 1276eb6
simplify params serialization, add tool reference
alex-dixon 7c935db
content block parsed serde
alex-dixon 4745314
Merge branch 'main' into distributed
alex-dixon e572492
refactor(serialize): remove redundant code in sql store wrappers
alex-dixon ff609fd
fix: created_at not optional if defaulted
alex-dixon 441b69d
naming: use 'coerce' for conversions
alex-dixon 3440233
Merge branch 'main' into distributed
alex-dixon 3db907c
refactor: dedupe http error handling
alex-dixon b1a2445
refactor(serialize): put uses in WriteLMPInput instead of second argu…
alex-dixon 1c3af0f
add http client tests
alex-dixon 121de02
Merge branch 'main' into distributed
alex-dixon a8e2417
use stores.models
alex-dixon b2b416a
allow dburl none if engine provided
alex-dixon 7bc69f8
Merge branch 'main' into distributed
alex-dixon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
|
||
@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) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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