Skip to content

Commit

Permalink
start of blue-objects-refactor-2024-09-08-84547 🪄 - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Sep 8, 2024
1 parent 1ab835f commit ffc9747
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 54 deletions.
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 🪄 [`abcli-9.277.1-blue-objects-attempt-2-b-2024-09-07-99677`](https://github.com/kamangir/awesome-bash-cli), based on [`openai_commands-3.158.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
8 changes: 5 additions & 3 deletions openai_commands/DALLE/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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 blue_objects import file
from abcli.modules import 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 +71,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
10 changes: 6 additions & 4 deletions openai_commands/DALLE/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from tqdm import tqdm
import requests
import numpy as np

from blue_options.host import is_jupyter
from blue_objects import file
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 openai_commands import NAME, VERSION
from openai_commands.DALLE.brush import RandomWalkBrush, TilingBrush
from openai_commands.logger import logger
Expand Down Expand Up @@ -224,7 +226,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 +237,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
4 changes: 3 additions & 1 deletion openai_commands/README.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from abcli import file

from blue_objects import file
from abcli.plugins.README import build as build_README

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

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.158.1"

REPO_NAME = "openai-commands"

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
11 changes: 6 additions & 5 deletions openai_commands/completion/functions/generic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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 blue_options.host import is_jupyter
from blue_objects import file
from abcli.modules import objects

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

Expand Down Expand Up @@ -53,7 +54,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
2 changes: 1 addition & 1 deletion openai_commands/completion/functions/image_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
from abcli import env, file
from abcli import string
from abcli.modules.host import is_jupyter
from blue_options.host import is_jupyter
from openai_commands.completion.functions.python import ai_function_py
from openai_commands.logger import logger

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


Expand Down Expand Up @@ -35,7 +35,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
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
10 changes: 6 additions & 4 deletions openai_commands/images/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import argparse
from blueness import module
from tqdm import tqdm
from abcli import string

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

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 +56,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: 6 additions & 5 deletions openai_commands/images/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
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 blue_options import string
from blue_options.host import is_jupyter
from blue_objects import file
from abcli.modules import host, objects
from abcli.plugins import graphics

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=C4KbC6hftR0uaS5T)](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=C4KbC6hftR0uaS5T) | [![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=18Nbi8v1X7lhseBZ)](https://kamangir-public.s3.ca-central-1.amazonaws.com/AMR-v7-test-litrev-multiple-local-study-type-screening-result/workflow.gif?raw=true&random=18Nbi8v1X7lhseBZ) |

---

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
4 changes: 3 additions & 1 deletion openai_commands/literature_review/combination.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import glob
import pandas as pd

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

from openai_commands import NAME
from openai_commands.logger import logger

Expand Down
6 changes: 4 additions & 2 deletions openai_commands/literature_review/functions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from typing import Dict
import re
import pandas as pd
from tqdm import tqdm

from blueness import module
from abcli import file
from blue_objects import file
from abcli.modules import 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
6 changes: 4 additions & 2 deletions openai_commands/tests/test_gpt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import pytest
from typing import List
from abcli import file

from blue_objects import file
from abcli.modules import objects

from openai_commands.gpt.chat import chat_with_openai, interact_with_openai, list_models


Expand All @@ -20,7 +22,7 @@ def test_chat_with_openai():
assert success
assert len(conversation) == 1

assert file.exist(
assert file.exists(
os.path.join(object_path, f"{object_name}.yaml"),
)

Expand Down
2 changes: 0 additions & 2 deletions openai_commands/tests/test_i2i_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os.path
from openai_commands.completion.functions.image_to_image import i2i_function
from openai_commands.completion.prompts.image_to_image import i2i_prompt
from abcli import file


def test_i2i_function():
Expand Down
2 changes: 0 additions & 2 deletions openai_commands/tests/test_i2i_prompt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os.path
from openai_commands.completion.prompts.image_to_image import i2i_prompt
from abcli import file


def test_i2i_prompt():
Expand Down
4 changes: 3 additions & 1 deletion openai_commands/tests/test_literature_review.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from abcli import file

from blue_objects import file
from abcli.modules import objects
from abcli.plugins.testing import download_object

from openai_commands import env
from openai_commands.literature_review.functions import (
generate_prompt,
Expand Down
3 changes: 1 addition & 2 deletions openai_commands/tests/test_structured_prompt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os.path
from blue_objects import file
from openai_commands.completion.prompts.structured import structured_prompt
from abcli import file


def test_structured_prompt():
Expand Down
13 changes: 7 additions & 6 deletions openai_commands/vision/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from tqdm import tqdm
from blueness import module
from openai import OpenAI

from blue_objects.env import ABCLI_PUBLIC_PREFIX
from abcli import file
from abcli import string
from abcli.modules import objects
from blue_options.options import Options
from openai_commands import env
from openai_commands import NAME
from blue_options import string
from blue_objects import file
from abcli.modules import objects

from openai_commands import env, NAME
from openai_commands.logger import logger

NAME = module.name(__file__, NAME)
Expand Down Expand Up @@ -72,7 +73,7 @@ def complete_object(
)

filename = objects.path_of("openai-vision.json", object_name)
_, past_metadata = file.load_json(filename, civilized=True)
_, past_metadata = file.load_json(filename, ignore_error=True)
past_metadata[string.timestamp()] = metadata
if not file.save_json(filename, past_metadata, log=True):
success = False
Expand Down

0 comments on commit ffc9747

Please sign in to comment.