Skip to content

Commit

Permalink
Generalize sort function and sort files.list
Browse files Browse the repository at this point in the history
  • Loading branch information
orangetin committed Jul 27, 2023
1 parent 332d0c1 commit 099d767
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/together/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
default_image_model = "runwayml/stable-diffusion-v1-5"
log_level = "WARNING"

from .utils.utils import get_logger, verify_api_key # noqa
from .utils.utils import get_logger, verify_api_key, extract_time # noqa
from .models import Models
from .complete import Complete
from .error import *
Expand All @@ -38,6 +38,7 @@
"default_image_model",
"get_logger",
"verify_api_key",
"extract_time",
"Models",
"Complete",
"Files",
Expand Down
3 changes: 2 additions & 1 deletion src/together/commands/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse
import json

from together import Files
from together import Files, extract_time


def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
Expand Down Expand Up @@ -83,6 +83,7 @@ def _add_retrieve_content(
def _run_list(args: argparse.Namespace) -> None:
files = Files()
response = files.list()
response["data"].sort(key=extract_time)
print(json.dumps(response, indent=4))


Expand Down
10 changes: 1 addition & 9 deletions src/together/commands/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

import argparse
import json
from typing import Any, Dict

from together import Finetune


def extract_time(json_obj: Dict[str, Any]) -> int:
try:
return int(json_obj["updated_at"])
except KeyError:
return 0
from together import Finetune, extract_time


def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
Expand Down
9 changes: 8 additions & 1 deletion src/together/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Optional
from typing import Any, Dict, Optional

import together

Expand Down Expand Up @@ -55,3 +55,10 @@ def verify_api_key(logger: Optional[logging.Logger] = None) -> None:
raise together.AuthenticationError(
"TOGETHER_API_KEY not found. Please set it as an environment variable or set it with together.api_key"
)


def extract_time(json_obj: Dict[str, Any]) -> int:
try:
return int(json_obj["created_at"])
except KeyError:
return 0

0 comments on commit 099d767

Please sign in to comment.