-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from arcee-ai/setup-repo
setup repo
- Loading branch information
Showing
14 changed files
with
529 additions
and
157 deletions.
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 @@ | ||
@Jacobsolawetz @ben-epstein |
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,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 |
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,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 |
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
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 @@ | ||
3.11 |
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
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 |
---|---|---|
@@ -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"] |
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,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) |
Oops, something went wrong.