Skip to content

Commit

Permalink
add GHA and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
samos123 committed Oct 27, 2023
1 parent e130109 commit 7ebc2b6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python integration tests

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Install test dependencies
run: pip install -r test-requirements.txt
- name: Integration tests
run: pytest
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM nvidia/cuda:12.2.2-runtime-ubuntu22.04


ENV DEBIAN_FRONTEND=noninteractive
ENV PORT=8080

RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
apt-get update && \
apt-get -y --no-install-recommends install python3 python3-pip git && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install --upgrade pip && \
pip3 install -r requirements.txt

COPY main.py .
COPY entrypoint.sh /usr/local/bin/
CMD [ "entrypoint.sh" ]

EXPOSE ${PORT}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Sentence Transformers API

OpenAI compatible endpont for Sentence Transformer embedding models

## Usage (Docker)


## Development

```
Expand Down
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

uvicorn main:app --host 0.0.0.0 --port $PORT
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import Union, List, Dict
from contextlib import asynccontextmanager
import os

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field
from sentence_transformers import SentenceTransformer

models: Dict[str, SentenceTransformer] = {}
default_model_name = 'all-MiniLM-L6-v2'
default_model_name = os.getenv("MODEL", 'all-MiniLM-L6-v2')

class EmbeddingRequest(BaseModel):
input: str | List[str] = Field(examples=["substratus.ai provides the best LLM tools"])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fastapi
sentence-transformers
uvicorn
uvicorn[standard]

0 comments on commit 7ebc2b6

Please sign in to comment.