From 772e272d621f5f71113aa346e796b70258c53487 Mon Sep 17 00:00:00 2001 From: yashbonde Date: Sat, 31 Aug 2024 18:54:04 -0700 Subject: [PATCH] [0.5.3] --- docs/changelog.rst | 15 +++++++++++++++ docs/conf.py | 2 +- pyproject.toml | 8 ++++---- tuneapi/__init__.py | 2 -- tuneapi/apis/model_tune.py | 12 +++++++----- tuneapi/endpoints/finetune.py | 32 ++++++++++++++++++++++++++++++++ tuneapi/utils/env.py | 4 ++-- 7 files changed, 61 insertions(+), 14 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3bcd276..66a9c5c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,21 @@ minor versions. All relevant steps to be taken will be mentioned here. +0.5.3 +----- + +- Fix bug in Tune proxy API where incorrect variable ``stop_sequence`` was sent instead of the correct ``stop`` causing + incorrect behaviour. +- bump dependency to ``protobuf>=5.27.3`` +- remove ``__version__`` from tuneapi package +- remove CLI entrypoint in ``pyproject.toml`` + +0.5.2 +----- + +- Add ability to upload any file using ``tuneapi.endpoints.FinetuningAPI.upload_dataset_file`` to support the existing + way to uploading using threads. + 0.5.1 ----- diff --git a/docs/conf.py b/docs/conf.py index 22d3e66..48b79cc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,7 +13,7 @@ project = "tuneapi" copyright = "2024, Frello Technologies" author = "Frello Technologies" -release = "0.5.1" +release = "0.5.3" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/pyproject.toml b/pyproject.toml index 67d0063..74bf543 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "tuneapi" -version = "0.5.1" +version = "0.5.3" description = "Tune AI APIs." authors = ["Frello Technology Private Limited "] license = "MIT" @@ -12,7 +12,7 @@ python = "^3.10" fire = "0.5.0" requests = "^2.31.0" cloudpickle = "3.0.0" -protobuf = "^4.25.3" +protobuf = "^5.27.3" cryptography = ">=42.0.5" tqdm = "^4.66.1" snowflake_id = "1.0.2" @@ -23,8 +23,8 @@ boto3 = { version = "1.29.6", optional = true } [tool.poetry.extras] boto3 = ["boto3"] -[tool.poetry.scripts] -tuneapi = "tuneapi.__main__:main" +# [tool.poetry.scripts] +# tuneapi = "tuneapi.__main__:main" [tool.poetry.group.dev.dependencies] sphinx = "7.2.5" diff --git a/tuneapi/__init__.py b/tuneapi/__init__.py index d666791..c827fab 100644 --- a/tuneapi/__init__.py +++ b/tuneapi/__init__.py @@ -1,3 +1 @@ # Copyright © 2023- Frello Technology Private Limited - -__version__ = "0.5.1" diff --git a/tuneapi/apis/model_tune.py b/tuneapi/apis/model_tune.py index 6ded01b..e686370 100644 --- a/tuneapi/apis/model_tune.py +++ b/tuneapi/apis/model_tune.py @@ -6,7 +6,7 @@ import json import requests -from typing import Optional, Dict, Any +from typing import Optional, Dict, Any, List import tuneapi.utils as tu import tuneapi.types as tt @@ -113,7 +113,8 @@ def chat( max_tokens: int = 1024, temperature: float = 0.7, token: Optional[str] = None, - timeout=(5, 30), + timeout=(5, 60), + stop: Optional[List[str]] = None, **kwargs, ) -> str | Dict[str, Any]: output = "" @@ -124,6 +125,7 @@ def chat( temperature=temperature, token=token, timeout=timeout, + stop=stop, **kwargs, ): if isinstance(x, dict): @@ -140,7 +142,7 @@ def stream_chat( temperature: float = 0.7, token: Optional[str] = None, timeout=(5, 60), - stop_sequence: Optional[str] = None, + stop: Optional[List[str]] = None, raw: bool = False, debug: bool = False, ): @@ -157,8 +159,8 @@ def stream_chat( "stream": True, "max_tokens": max_tokens, } - if stop_sequence: - data["stop_sequence"] = stop_sequence + if stop: + data["stop"] = stop if isinstance(chats, tt.Thread) and len(chats.tools): data["tools"] = [ {"type": "function", "function": x.to_dict()} for x in chats.tools diff --git a/tuneapi/endpoints/finetune.py b/tuneapi/endpoints/finetune.py index 4ef1f31..840365b 100644 --- a/tuneapi/endpoints/finetune.py +++ b/tuneapi/endpoints/finetune.py @@ -38,6 +38,38 @@ def __init__( base_url + "tune.Studio/", self.tune_org_id, self.tune_api_key ) + def upload_dataset_file(self, filepath: str, name: str): + # first we get the presigned URL for the dataset + data = self.sub.UploadDataset( + "post", + json={ + "auth": { + "organization": self.tune_org_id, + }, + "dataset": { + "name": name, + "contentType": "application/jsonl", + "datasetType": "chat", + "size": os.stat(filepath).st_size, + }, + }, + ) + with open(filepath, "rb") as f: + files = {"file": (filepath, f)} + http_response = requests.post( + data["code"]["s3Url"], + data=data["code"]["s3Meta"], + files=files, + ) + if http_response.status_code == 204: + tu.logger.info("Upload successful!") + else: + raise ValueError( + f"Upload failed with status code: {http_response.status_code} and response: {http_response.text}" + ) + + return FTDataset(path="datasets/chat/" + name, type="relic") + def upload_dataset( self, threads: tt.ThreadsList | str, diff --git a/tuneapi/utils/env.py b/tuneapi/utils/env.py index 62367a8..221acff 100644 --- a/tuneapi/utils/env.py +++ b/tuneapi/utils/env.py @@ -8,8 +8,8 @@ class _ENV: def __init__(self): self.vars_called = set() - TUNEAPI_TOKEN = lambda x="": os.getenv("TUNEAPI_TOKEN", x) - TUNEORG_ID = lambda x="": os.getenv("TUNEORG_ID", x) + TUNEAPI_TOKEN = lambda _, x="": os.getenv("TUNEAPI_TOKEN", x) + TUNEORG_ID = lambda _, x="": os.getenv("TUNEORG_ID", x) def __getattr__(self, __name: str): self.vars_called.add(__name)