Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blue-objects refactor #16

Merged
merged 16 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ to use on [AWS SageMaker](https://aws.amazon.com/sagemaker/) replace `<plugin-na

[![pylint](https://github.com/kamangir/openai-commands/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/openai-commands/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/openai-commands/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/openai-commands/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/openai-commands/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/openai-commands/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/openai-commands.svg)](https://pypi.org/project/openai-commands/)

built by 🪄 [`abcli-9.275.1-blue-objects-attempt-2-b-2024-09-07-99677`](https://github.com/kamangir/awesome-bash-cli), based on [`openai_commands-3.157.1`](https://github.com/kamangir/openai-commands).
built by 🌀 [`blue_options-4.69.1-abcli-current`](https://github.com/kamangir/awesome-bash-cli), based on [`openai_commands-3.173.1`](https://github.com/kamangir/openai-commands).
2 changes: 1 addition & 1 deletion openai_commands/.abcli/complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function openai_commands_complete() {

unset abcli_show_usage_destination

abcli_log_file $abcli_object_path/$plugin_name-description.txt
abcli_cat $abcli_object_path/$plugin_name-description.txt

return
fi
Expand Down
2 changes: 1 addition & 1 deletion openai_commands/.abcli/gpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function openai_commands_gpt() {
local do_upload=$(abcli_option_int "$options" upload $(abcli_not $do_dryrun))

local object_name=$(abcli_clarify_object $2 gpt-chat-$(abcli_string_timestamp))
local object_path=$abcli_object_root/$object_name
local object_path=$ABCLI_OBJECT_ROOT/$object_name
mkdir -p $object_path

abcli_tag set $object_name gpt_chat
Expand Down
9 changes: 5 additions & 4 deletions openai_commands/DALLE/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import argparse
import os

from blueness import module
from abcli import file
from blueness.argparse.generic import sys_exit
from blue_options.options import Options
from abcli.modules import objects
from blue_objects import file, objects

from articraft import html
from openai_commands import NAME, VERSION
from openai_commands.DALLE.canvas import Canvas
from openai_commands.logger import logger
from blueness.argparse.generic import sys_exit

NAME = module.name(__file__, NAME)

Expand Down Expand Up @@ -69,7 +70,7 @@
output_filename = args.destination
if not output_filename:
if not is_url:
output_filename = file.set_extension(args.source, "png")
output_filename = file.add_extension(args.source, "png")
else:
output_filename = objects.path_of("DALL-E.png")

Expand Down
21 changes: 13 additions & 8 deletions openai_commands/DALLE/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
from tqdm import tqdm
import requests
import numpy as np
from abcli.modules.objects import signature as object_signature
from abcli.modules.host import signature as host_signature
from abcli.modules.host import is_jupyter
from abcli.plugins.graphics import add_signature
from abcli import file

from blueness import module
from blue_options.host import is_jupyter
from blue_options.host import signature as host_signature
from blue_options.logger import crash_report
from blue_objects import file
from blue_objects.objects import signature as object_signature
from blue_objects.graphics import add_signature

from openai_commands import NAME, VERSION
from openai_commands.DALLE.brush import RandomWalkBrush, TilingBrush
from openai_commands.logger import logger
from abcli.logger import crash_report

NAME = module.name(__file__, NAME)


class Canvas:
Expand Down Expand Up @@ -224,7 +229,7 @@ def save(self, filename):
image = self.add_signature(image)

image.save(filename)
mask.save(file.add_postfix(filename, "mask"))
mask.save(file.add_suffix(filename, "mask"))

if self.debug_mode and self.is_jupyter:
from IPython.display import display, clear_output
Expand All @@ -235,7 +240,7 @@ def save(self, filename):
logger.info(f"Canvas -> {filename}")

file.save_json(
file.set_extension(filename, "json"),
file.add_extension(filename, "json"),
{
"content": self.content,
"source": self.source,
Expand Down
9 changes: 5 additions & 4 deletions openai_commands/README.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from abcli import file
from abcli.plugins.README import build as build_README

from blue_objects import file, README

from openai_commands.literature_review.README import items as literature_review_items
from openai_commands import NAME, VERSION, ICON, REPO_NAME

Expand Down Expand Up @@ -76,13 +77,13 @@


def build():
return build_README(
return README.build(
items=items,
path=os.path.join(file.path(__file__), ".."),
NAME=NAME,
VERSION=VERSION,
REPO_NAME=REPO_NAME,
) and build_README(
) and README.build(
items=literature_review_items,
cols=2,
path=os.path.join(file.path(__file__), "literature_review"),
Expand Down
6 changes: 4 additions & 2 deletions openai_commands/VisuaLyze/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import pandas as pd
from typing import List
from flask import render_template

from blueness import module
from abcli import file
from abcli import string
from blue_options import string
from blue_objects import file

from openai_commands import ICON, NAME, VERSION
from openai_commands import env
from openai_commands.gpt.chat import interact_with_openai
Expand Down
2 changes: 1 addition & 1 deletion openai_commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

DESCRIPTION = f"{ICON} a command interface to the OpenAI API."

VERSION = "3.157.1"
VERSION = "3.173.1"

REPO_NAME = "openai-commands"

Expand Down
6 changes: 3 additions & 3 deletions openai_commands/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from openai_commands import NAME, VERSION, DESCRIPTION, ICON
from openai_commands.logger import logger
from openai_commands import README
from blueness.argparse.generic import main

from openai_commands import NAME, VERSION, DESCRIPTION, ICON, README
from openai_commands.logger import logger

main(
ICON=ICON,
NAME=NAME,
Expand Down
2 changes: 1 addition & 1 deletion openai_commands/completion/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Tuple, Any, Dict
from openai import OpenAI
from blueness import module
from abcli.modules.host import is_jupyter
from blue_options.host import is_jupyter
from openai_commands import env
from openai_commands import NAME
from openai_commands.logger import logger
Expand Down
12 changes: 6 additions & 6 deletions openai_commands/completion/functions/generic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List
from typing import List, Dict, Any, Tuple
import random
from typing import Dict, Any, Tuple
from abcli import file
from abcli.modules.host import is_jupyter
from abcli.modules import objects

from blue_options.host import is_jupyter
from blue_objects import file, objects

from openai_commands.completion.api import complete_prompt
from openai_commands.logger import logger

Expand Down Expand Up @@ -53,7 +53,7 @@ def save(self, filename=""):
if not filename:
filename = objects.path_of(f"{self.__class__.__name__}_code.json")

_, content = file.load_json(filename, civilized=True)
_, content = file.load_json(filename, ignore_error=True)

content[self.function_name] = self.to_json()

Expand Down
11 changes: 7 additions & 4 deletions openai_commands/completion/functions/image_to_image.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import matplotlib.pyplot as plt
from abcli import env, file
from abcli import string
from abcli.modules.host import is_jupyter

from blue_options import string
from blue_options.host import is_jupyter
from blue_objects import file
from blue_objects.env import HOME

from openai_commands.completion.functions.python import ai_function_py
from openai_commands.logger import logger

Expand All @@ -26,7 +29,7 @@ def __init__(
if self.validation_input is None:
_, self.validation_input = file.load_image(
os.path.join(
env.HOME,
HOME,
"git/blue-bracket/images/portal-34.jpg",
)
)
Expand Down
4 changes: 3 additions & 1 deletion openai_commands/completion/functions/python.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Dict, Any, Tuple
from abcli.logger import crash_report

from blue_options.logger import crash_report

from openai_commands.completion.functions.generic import ai_function
from openai_commands.logger import logger

Expand Down
5 changes: 2 additions & 3 deletions openai_commands/completion/prompts/bash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abcli import file
from abcli.modules import objects
from blue_objects import file, objects


class bash_prompt:
Expand Down Expand Up @@ -35,7 +34,7 @@ def pre_process(filename):
success
if not success
else file.save_text(
file.set_extension(filename, "txt"),
file.add_extension(filename, "txt"),
[
"to {}, run {}.".format(
thing[1][:-1] if thing[1].endswith(".") else thing[1],
Expand Down
2 changes: 1 addition & 1 deletion openai_commands/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from abcli.env import load_env, load_config
from blue_options.env import load_config, load_env

load_env(__name__)
load_config(__name__)
Expand Down
6 changes: 4 additions & 2 deletions openai_commands/gpt/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

import os
from typing import List, Any, Tuple
from blueness import module
from openai import OpenAI
from abcli import file, path

from blueness import module
from blue_objects import file, path

from openai_commands import NAME, VERSION
from openai_commands import env
from openai_commands.logger import logger
Expand Down
11 changes: 6 additions & 5 deletions openai_commands/images/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import argparse
from blueness import module
from tqdm import tqdm
from abcli import string
from abcli.modules import objects
from abcli import file

from blueness.argparse.generic import sys_exit
from blue_options import string
from blue_objects import file, objects

from openai_commands import NAME, VERSION
from openai_commands.images.api import OpenAIImageGenerator
from openai_commands.logger import logger
from blueness.argparse.generic import sys_exit

NAME = module.name(__file__, NAME)

Expand Down Expand Up @@ -54,7 +55,7 @@
success = True
for index, prompt in tqdm(enumerate(args.prompt.split("+"))):
filename = objects.path_of(
filename=file.add_postfix(args.filename, f"{index:05d}"),
filename=file.add_suffix(args.filename, f"{index:05d}"),
object_name=args.object_name,
create=True,
)
Expand Down
11 changes: 5 additions & 6 deletions openai_commands/images/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from openai import OpenAI
from typing import Tuple, Any
from IPython.display import Image, display

from blueness import module
from abcli import file
from abcli import string
from abcli.modules import host
from abcli.modules import objects
from abcli.modules.host import is_jupyter
from abcli.plugins import graphics
from blue_options import string, host
from blue_options.host import is_jupyter
from blue_objects import file, graphics, objects

from openai_commands import NAME, VERSION
from openai_commands import env
from openai_commands.logger import logger
Expand Down
2 changes: 1 addition & 1 deletion openai_commands/literature_review/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ literature review at scale on [AWS Batch](https://aws.amazon.com/batch/) through
| | |
| --- | --- |
| [aws_batch](https://github.com/kamangir/notebooks-and-scripts/tree/main/notebooks_and_scripts/workflow/runners/aws_batch.py) | [local](https://github.com/kamangir/notebooks-and-scripts/tree/main/notebooks_and_scripts/workflow/runners/local.py) |
| [![image](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-aws_batch-study-type-screening-result/workflow.gif?raw=true&random=dkhzyoxdqQOtHYGb)](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-aws_batch-study-type-screening-result/workflow.gif?raw=true&random=dkhzyoxdqQOtHYGb) | [![image](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-local-study-type-screening-result/workflow.gif?raw=true&random=TbrgGRjZbCUkzssI)](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-local-study-type-screening-result/workflow.gif?raw=true&random=TbrgGRjZbCUkzssI) |
| [![image](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-aws_batch-study-type-screening-result/workflow.gif?raw=true&random=ymwA7yqboIutiKQL)](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-aws_batch-study-type-screening-result/workflow.gif?raw=true&random=ymwA7yqboIutiKQL) | [![image](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-local-study-type-screening-result/workflow.gif?raw=true&random=qXAYVigvUoLfwJz9)](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-local-study-type-screening-result/workflow.gif?raw=true&random=qXAYVigvUoLfwJz9) |

---

Expand Down
4 changes: 2 additions & 2 deletions openai_commands/literature_review/README.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from blue_objects.env import ABCLI_PUBLIC_PREFIX
from abcli import string
from blue_options import string


runner_prefix = "https://github.com/kamangir/notebooks-and-scripts/tree/main/notebooks_and_scripts/workflow/runners"
Expand All @@ -15,7 +15,7 @@
"{}/AMR-v7-test-litrev-multiple-{}-study-type-screening-result/workflow.gif?raw=true&random={}".format(
ABCLI_PUBLIC_PREFIX,
runner_type,
string.random_(),
string.random(),
)
for runner_type in list_of_runners
]
Expand Down
7 changes: 4 additions & 3 deletions openai_commands/literature_review/combination.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import glob
import pandas as pd

from blueness import module
from abcli import file
from abcli.modules import objects
from blue_objects import file, objects

from openai_commands import NAME
from openai_commands.logger import logger

Expand Down Expand Up @@ -32,7 +33,7 @@ def combine(
object_name_2,
)

if not file.exist(filename_2):
if not file.exists(filename_2):
logger.warning(
"missing in object-2 [{}]: {}".format(
object_name_2,
Expand Down
9 changes: 5 additions & 4 deletions openai_commands/literature_review/functions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import Dict
import re
import pandas as pd
from tqdm import tqdm

from blueness import module
from abcli import file
from abcli.modules import objects
from blue_objects import file, objects

from openai_commands import NAME
from openai_commands.completion.api import complete_prompt
from openai_commands.logger import logger
from tqdm import tqdm


NAME = module.name(__file__, NAME)
Expand Down Expand Up @@ -95,7 +96,7 @@ def review_literature(
f"{filename}.csv",
input_object_name,
)
if not overwrite and file.exist(output_filename):
if not overwrite and file.exists(output_filename):
logger.info(
"continuing from a previous run: {} ...".format(file.name(output_filename))
)
Expand Down
2 changes: 1 addition & 1 deletion openai_commands/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abcli.logger import get_logger
from blue_options.logger import get_logger
from openai_commands import ICON

logger = get_logger(ICON)
Loading
Loading