Skip to content

Commit 1216e8d

Browse files
committed
[chore] adding api docs
1 parent 15f58f8 commit 1216e8d

File tree

10 files changed

+203
-26
lines changed

10 files changed

+203
-26
lines changed

.github/workflows/static.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
branches: ["main"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
# Single deploy job since we're just deploying
26+
deploy:
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
30+
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
36+
- name: Set up Python
37+
uses: actions/setup-python@v2
38+
with:
39+
python-version: 3.11
40+
41+
- name: Install dependencies
42+
run: |
43+
python -m pip install -U pip
44+
python -m pip install .
45+
python -m pip install Sphinx==7.4.7
46+
python -m pip install sphinx-rtd-theme==2.0.0
47+
48+
- name: Build docs
49+
run: |
50+
cd docs
51+
sphinx-apidoc -o source/ ../tuneapi
52+
make html
53+
54+
- name: Setup Pages
55+
uses: actions/configure-pages@v3
56+
57+
- name: Upload artifact
58+
uses: actions/upload-pages-artifact@v1
59+
with:
60+
# Upload entire repository
61+
path: './docs/_build/html'
62+
63+
- name: Deploy to GitHub Pages
64+
id: deployment
65+
uses: actions/deploy-pages@v2

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,8 @@ chunker/
155155
examples/
156156
cookbooks/
157157
datasets/
158-
158+
docs/_static
159+
docs/_build
160+
docs/_templates
161+
docs/source
162+
test.py

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
import os, sys
7+
8+
sys.path.insert(0, os.path.abspath("../"))
9+
10+
# -- Project information -----------------------------------------------------
11+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
12+
13+
project = "tuneapi"
14+
copyright = "2024, Frello Technologies"
15+
author = "Frello Technologies"
16+
release = "0.4.11"
17+
18+
# -- General configuration ---------------------------------------------------
19+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
20+
21+
extensions = ["sphinx.ext.napoleon"]
22+
23+
templates_path = ["_templates"]
24+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
25+
26+
27+
# -- Options for HTML output -------------------------------------------------
28+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
29+
30+
html_theme = "sphinx_rtd_theme"
31+
html_static_path = ["_static"]

docs/index.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. tuneapi documentation master file, created by
2+
sphinx-quickstart on Tue Jul 30 17:14:39 2024.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
tuneapi documentation
7+
=====================
8+
9+
TuneAPI
10+
11+
.. toctree::
12+
:maxdepth: 2
13+
:caption: Contents:
14+
15+
source/tuneapi.apis
16+
source/tuneapi.types
17+
source/tuneapi.utils
18+

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

tuneapi/apis/threads.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def get_sub(
1818
sess.headers.update({"x-tune-key": tune_api_key})
1919
if tune_org_id:
2020
sess.headers.update({"X-Organization-Id": tune_org_id})
21+
print("::::::", sess.headers)
2122
return tu.Subway(base_url, sess)
2223

2324

@@ -51,22 +52,20 @@ def put_thread(
5152
if not thread.title:
5253
thread.title = "thread_" + tu.get_snowflake()
5354

55+
body = {
56+
"title": thread.title,
57+
"messages": [m.to_dict(format="api", meta=False) for m in thread.chats],
58+
}
5459
m = {}
5560
if thread.meta:
5661
m["thread_meta"] = thread.meta
5762
if thread.evals:
5863
m["evals"] = thread.evals
59-
meta = {"meta": tu.to_json(m, tight=True)} if m else {}
64+
if m:
65+
body["metadata"] = {"meta": tu.to_json(m, tight=True)}
6066

6167
tu.logger.info("Creating new thread")
62-
out = self.sub.threads(
63-
"post",
64-
json={
65-
"title": thread.title,
66-
"metadata": meta,
67-
"messages": [m.to_dict(format="api", meta=False) for m in thread.chats],
68-
},
69-
)
68+
out = self.sub.threads("post", json=body)
7069
thread.id = out["id"]
7170
return thread
7271

tuneapi/types/chats.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
########################################################################################################################
1717
#
18-
# The code in this section contains the primitive of this new chat API. The `Tool` class defines tools that the model
19-
# can predict. The `Message` class defines the container for storing the chat messages.
18+
# The code in this section contains the primitive of this new chat API. The ``Tool`` class defines tools that the model
19+
# can predict. The ``Message`` class defines the container for storing the chat messages.
2020
#
2121
########################################################################################################################
2222

@@ -133,7 +133,7 @@ def __init__(
133133
**kwargs,
134134
):
135135
if role not in self.KNOWN_ROLES:
136-
raise ValueError(f"Unknown role: {role}. Update dictionary `KNOWN_ROLES`")
136+
raise ValueError(f"Unknown role: {role}. Update dictionary ``KNOWN_ROLES``")
137137
if value is None:
138138
raise ValueError("value cannot be None")
139139

@@ -188,12 +188,15 @@ def to_dict(
188188
self,
189189
format: Optional[str] = None,
190190
meta: bool = False,
191-
): # ft: bool = False
191+
):
192192
"""
193-
if format == `ft` then export to following format: `{"from": "system/human/gpt", "value": "..."}`
194-
elif format == `api` then `{"role": "system/user/assistant", "content": [{"type": "text", "text": {"value": "..."}]}`
195-
elif format == `full` then `{"id": 1234421123, "role": "system/user/assistant", "content": [{"type": "text", "text": {"value": "..."}]}`
196-
else export to following format: `{"role": "system/user/assistant", "content": "..."}`
193+
if format == ``ft`` then export to following format: ``{"from": "system/human/gpt", "value": "..."}``
194+
195+
elif format == ``api`` then ``{"role": "system/user/assistant", "content": [{"type": "text", "text": {"value": "..."}]}``
196+
197+
elif format == ``full`` then ``{"id": 1234421123, "role": "system/user/assistant", "content": [{"type": "text", "text": {"value": "..."}]}``
198+
199+
else export to following format: ``{"role": "system/user/assistant", "content": "..."}``
197200
"""
198201
role = self.role
199202

@@ -699,7 +702,7 @@ def undo(self) -> "ThreadsTree":
699702

700703
def pick(self, to: Message = None, from_: Message = None) -> Thread:
701704
"""
702-
Get a thread from the Tree srtucture by telling `to` and `from_` in the tree
705+
Get a thread from the Tree srtucture by telling ``to`` and ``from_`` in the tree
703706
"""
704707
if self.system:
705708
thread = Thread(system(self.system))
@@ -772,7 +775,7 @@ def regenerate_stream(
772775
# if we are regenerating for a human, then we need to add a prompt to the tree and then regenerate
773776
if not prompt:
774777
raise ValueError(
775-
f"Regenerating for role 'human' but no `prompt` provided. pass `prompt`"
778+
f"Regenerating for role 'human' but no ``prompt`` provided. pass ``prompt``"
776779
)
777780
if type(prompt) == str:
778781
prompt = human(prompt)
@@ -786,7 +789,7 @@ def regenerate_stream(
786789
# to be a human
787790
if prompt:
788791
raise ValueError(
789-
f"Regenerating for role 'gpt' but `prompt` provided. remove `prompt`"
792+
f"Regenerating for role 'gpt' but ``prompt`` provided. remove ``prompt``"
790793
)
791794
thread = Thread()
792795
for x in self.tree.find(data_id=from_.id).get_parent_list():
@@ -939,7 +942,7 @@ def create_te_split(
939942
try:
940943
import numpy as np
941944
except ImportError:
942-
raise ImportError("Install numpy to use `create_te_split` method")
945+
raise ImportError("Install numpy to use ``create_te_split`` method")
943946

944947
train_ds = ThreadsList()
945948
eval_ds = ThreadsList()

tuneapi/utils/serdeser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ def from_json(x: str = "") -> Dict[str, Any]:
5656
"""
5757
if os.path.exists(x):
5858
if x.endswith(".json"):
59-
with open(x, "r") as f:
60-
return json.load(f)
59+
with open(x, "rb") as f:
60+
return json.loads(f.read().decode("utf-8", "ignore"))
6161
elif x.endswith(".jsonl"):
62-
with open(x, "r") as f:
63-
return [json.loads(line) for line in f]
62+
with open(x, "rb") as f:
63+
for line in f.read().decode("utf-8", "ignore").splitlines():
64+
return json.loads(line)
6465
else:
6566
return json.loads(x)
6667

tuneapi/utils/subway.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def __call__(
152152

153153
if SimplerTimes.get_now_i64() - self._last_update > 120:
154154
self._renew_session()
155+
print(f"{url=}, {items=}")
155156
r = fn(url, **items, **kwargs)
156157
if 399 < r.status_code < 500:
157158
raise SubwayClientError(r.content.decode(), code=r.status_code)

0 commit comments

Comments
 (0)