Skip to content

Commit

Permalink
Merge pull request #4 from arcee-ai/setup-repo
Browse files Browse the repository at this point in the history
setup repo
  • Loading branch information
Ben-Epstein authored Sep 18, 2023
2 parents 3620da3 + 532016d commit 881f392
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 157 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@Jacobsolawetz @ben-epstein
40 changes: 40 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: publish

on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
fail-fast: false
steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: apt-get update
run: sudo apt-get update -y

- name: set up python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: install invoke
run: pip install invoke

- name: build
run: inv build

- name: publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
run: inv publish
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR Test

on:
pull_request:
branches:
- main
paths:
- "arcee/**"

jobs:
test_lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version-file: ".python-version"
cache: pip
cache-dependency-path: "**/pyproject.toml"

- name: install invoke
run: pip install invoke

- name: install dependencies
run: inv install --no-editable

- name: Run inv lint
run: inv lint

# - name: Run tests
# run: inv test
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
.idea

# C extensions
*.so
Expand Down Expand Up @@ -81,9 +82,6 @@ target/
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,38 @@ import arcee
med_dalm = arcee.get_dalm("medical_dalm")
med_dalm.retrieve("my query")
```

# Contributing

We use `invoke` to manage this repo. You don't need to use it, but it simplifies the workflow.
## Set up the repo
```shell
git clone https://github.com/arcee-ai/arcee-python && cd arcee-python
# optionally setup your virtual environment (recommended)
python -m venv .venv && source .venv/bin/activate
# install repo
pip install invoke
inv install
```

## Format, lint, test
```shell
inv format # run black and ruff
inv lint # black check, ruff check, mypy
inv test # pytest
```

## Publishing
We publish in this repo by creating a new release/tag in github. On release, a github action will
publish the `__version__` of arcee-py that is in `arcee/__init__.py`

**So you need to increase that version before releasing, otherwise it will fail**

### To create a new release
1. Open a PR increasing the `__version__` of arcee-py. You can manually edit it or run `inv uv`
2. Create a new release, with the name being the `__version__` of arcee-py

### Manual release [not recommended]

We do not recommend this. If you need to, please make the version number an alpha or beta release.<br>
If you need to create a manual release, you can run `inv build && inv publish`
105 changes: 7 additions & 98 deletions arcee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,12 @@
__version__ = "0.0.9"
import os
import requests
import json
from arcee.dalm import DALM
from arcee.dalm import check_model_status
from arcee.config import ARCEE_API_KEY, ARCEE_API_URL, ARCEE_APP_URL, ARCEE_API_VERSION
import time

if ARCEE_API_KEY is None:
raise Exception(f"ARCEE_API_KEY must be in the environment. You can retrieve your API key from {ARCEE_APP_URL}")

def upload_doc(context, doc_name, doc_text):
"""
Upload a document to a context
Args:
context (str): The name of the context to upload to
doc_name (str): The name of the document
doc_text (str): The text of the document
"""
doc = {
"name": doc_name,
"document": doc_text
}

headers = {
"X-Token": f"{ARCEE_API_KEY}",
"Content-Type": "application/json"
}

data = {
"context_name": context,
"documents": [doc]
}

response = requests.post(f"{ARCEE_API_URL}/{ARCEE_API_VERSION}/upload-context", headers=headers, data=json.dumps(data))

if response.status_code != 200:
raise Exception(f"Failed to upload example. Response: {response.text}")

return response.json()

def upload_docs(context, docs):
"""
Upload a list of documents to a context
__version__ = "0.0.10"

Args:
context (str): The name of the context to upload to
docs (list): A list of dictionaries with keys "doc_name" and "doc_text"
"""
doc_list = []
for doc in docs:
if "doc_name" not in doc.keys() or "doc_text" not in doc.keys():
raise Exception("Each document must have a doc_name and doc_text key")

doc_list.append({
"name": doc["doc_name"],
"document": doc["doc_text"]
})

headers = {
"X-Token": f"{ARCEE_API_KEY}",
"Content-Type": "application/json"
}

data = {
"context_name": context,
"documents": doc_list
}

response = requests.post(f"{ARCEE_API_URL}/{ARCEE_API_VERSION}/upload-context", headers=headers, data=json.dumps(data))

if response.status_code != 200:
raise Exception(f"Failed to upload example. Response: {response.text}")

return response.json()


def train_dalm(name, context=None, instructions=None, generator="Command"):

endpoint = f"{ARCEE_API_URL}/{ARCEE_API_VERSION}/train-model"
data_to_send = {
"name": name,
"context": context,
"instructions": instructions,
"generator": generator
}

headers = {
"X-Token": f"{ARCEE_API_KEY}",
"Content-Type": "application/json"
}
from arcee.api import get_dalm, train_dalm, upload_doc, upload_docs
from arcee.config import ARCEE_API_KEY, ARCEE_APP_URL
from arcee.dalm import DALM

response = requests.post(endpoint, data=json.dumps(data_to_send), headers=headers)
if not ARCEE_API_KEY:
raise Exception(f"ARCEE_API_KEY must be in the environment. You can retrieve your API key from {ARCEE_APP_URL}")

if response.status_code != 201:
raise Exception(f"Failed to train model. Response: {response.text}")
else:
print("DALM model training started - view model status at {ARCEE_APP_URL}, then arcee.get_model(" + name + ")")

def get_dalm(name):
return DALM(name)
__all__ = ["upload_docs", "upload_doc", "train_dalm", "get_dalm", "DALM"]
81 changes: 81 additions & 0 deletions arcee/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import json
from typing import Optional

import requests

from arcee.config import ARCEE_API_KEY, ARCEE_API_URL, ARCEE_API_VERSION
from arcee.dalm import DALM


def upload_doc(context: str, doc_name: str, doc_text: str) -> dict[str, str]:
"""
Upload a document to a context
Args:
context (str): The name of the context to upload to
doc_name (str): The name of the document
doc_text (str): The text of the document
"""
doc = {"name": doc_name, "document": doc_text}

headers = {"X-Token": f"{ARCEE_API_KEY}", "Content-Type": "application/json"}

data = {"context_name": context, "documents": [doc]}

response = requests.post(
f"{ARCEE_API_URL}/{ARCEE_API_VERSION}/upload-context", headers=headers, data=json.dumps(data)
)

if response.status_code != 200:
raise Exception(f"Failed to upload example. Response: {response.text}")

return response.json()


def upload_docs(context: str, docs: list[dict[str, str]]) -> dict[str, str]:
"""
Upload a list of documents to a context
Args:
context (str): The name of the context to upload to
docs (list): A list of dictionaries with keys "doc_name" and "doc_text"
"""
doc_list = []
for doc in docs:
if "doc_name" not in doc.keys() or "doc_text" not in doc.keys():
raise Exception("Each document must have a doc_name and doc_text key")

doc_list.append({"name": doc["doc_name"], "document": doc["doc_text"]})

headers = {"X-Token": f"{ARCEE_API_KEY}", "Content-Type": "application/json"}

data = {"context_name": context, "documents": doc_list}

response = requests.post(
f"{ARCEE_API_URL}/{ARCEE_API_VERSION}/upload-context", headers=headers, data=json.dumps(data)
)

if response.status_code != 200:
raise Exception(f"Failed to upload example. Response: {response.text}")

return response.json()


def train_dalm(
name: str, context: Optional[str] = None, instructions: Optional[str] = None, generator: str = "Command"
) -> None:
endpoint = f"{ARCEE_API_URL}/{ARCEE_API_VERSION}/train-model"
data_to_send = {"name": name, "context": context, "instructions": instructions, "generator": generator}

headers = {"X-Token": f"{ARCEE_API_KEY}", "Content-Type": "application/json"}

response = requests.post(endpoint, data=json.dumps(data_to_send), headers=headers)

if response.status_code != 201:
raise Exception(f"Failed to train model. Response: {response.text}")
else:
print("DALM model training started - view model status at {ARCEE_APP_URL}, then arcee.get_model(" + name + ")")


def get_dalm(name: str) -> DALM:
return DALM(name)
Loading

0 comments on commit 881f392

Please sign in to comment.