Skip to content

Commit ac27289

Browse files
authored
Merge pull request #23 from kamangir/text-generation-refactors-2025-02-04-c1dfoz
refactors
2 parents a77bbbe + a4c4986 commit ac27289

27 files changed

+418
-266
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ graph LR
4949
```
5050

5151

52-
| | |
53-
| --- | --- |
54-
| [`literature review`](./openai_commands/literature_review) [![image](https://github.com/kamangir/assets/blob/main/openai_commands/literature-review/marquee.png?raw=true)](./openai_commands/literature_review) | [`prompt completion`](./openai_commands/prompt_completion) [![image](https://github.com/kamangir/assets/raw/main/blue-plugin/marquee.png?raw=true)](./openai_commands/prompt_completion) |
55-
| [`image generation`](./openai_commands/images) [![image](https://github.com/kamangir/openai-commands/blob/main/assets/DALL-E.png?raw=true)](./openai_commands/images) | [`vision`](./openai_commands/vision) [![image](https://raw.githubusercontent.com/kamangir/assets/main/vanwatch/2023-11-25-openai-vision/ButeNorthDavie.jpg)](./openai_commands/vision) |
52+
| | | |
53+
| --- | --- | --- |
54+
| [`AI DAG runner`](https://github.com/kamangir/blue-assistant) [![image](https://github.com/kamangir/assets/raw/main/blue-amo-2025-02-03-nswnx6/stitching_the_frames-2.png?raw=true)](https://github.com/kamangir/blue-assistant) | [`literature review`](./openai_commands/literature_review) [![image](https://github.com/kamangir/assets/blob/main/openai_commands/literature-review/marquee.png?raw=true)](./openai_commands/literature_review) | [`text generation`](./openai_commands/text_generation) [![image](https://github.com/kamangir/assets/raw/main/blue-plugin/marquee.png?raw=true)](./openai_commands/text_generation) |
55+
| [`image generation`](./openai_commands/images) [![image](https://github.com/kamangir/openai-commands/blob/main/assets/DALL-E.png?raw=true)](./openai_commands/images) | [`vision`](./openai_commands/vision) [![image](https://raw.githubusercontent.com/kamangir/assets/main/vanwatch/2023-11-25-openai-vision/ButeNorthDavie.jpg)](./openai_commands/vision) | |
5656

5757
---
5858

@@ -61,4 +61,4 @@ graph LR
6161

6262
[![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/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/openai-commands)](https://pypistats.org/packages/openai-commands)
6363

64-
built by 🌀 [`blue_options-4.207.1`](https://github.com/kamangir/awesome-bash-cli), based on [`openai_commands-3.241.1`](https://github.com/kamangir/openai-commands).
64+
built by 🌀 [`blue_options-4.207.1`](https://github.com/kamangir/awesome-bash-cli), based on [`openai_commands-3.249.1`](https://github.com/kamangir/openai-commands).

notebooks/image_generation.ipynb

Lines changed: 44 additions & 35 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"cell_type": "markdown",
66
"metadata": {},
77
"source": [
8-
"# prompt completion"
8+
"# text generation\n",
9+
"from messages"
910
]
1011
},
1112
{
@@ -26,8 +27,8 @@
2627
"name": "stderr",
2728
"output_type": "stream",
2829
"text": [
29-
"🛠️ openai_commands-3.212.1.blueflow-4.849.1.abcli-9.486.1.blue_objects-5.281.1.blue_options-4.200.1.torch-2.5.1.Python 3.9.6.Darwin 23.6.0..Jupyter-Notebook,\n",
30-
"built on 01 February 2025, 12:55:04\n"
30+
"🛠️ openai_commands-3.242.1.blueflow-4.849.1.abcli-9.486.1.blue_objects-5.283.1.blue_options-4.207.1.torch-2.5.1.Python 3.9.6.Darwin 23.6.0..Jupyter-Notebook,\n",
31+
"built on 04 February 2025, 11:36:40\n"
3132
]
3233
}
3334
],
@@ -39,7 +40,8 @@
3940
"\n",
4041
"from blue_options import string\n",
4142
"\n",
42-
"from openai_commands.prompt_completion.api import complete_prompt\n",
43+
"from openai_commands.tests.test_text_generation import test_messages\n",
44+
"from openai_commands.text_generation.api import generate_text\n",
4345
"from openai_commands.host import signature\n",
4446
"from openai_commands.logger import logger\n",
4547
"\n",
@@ -56,12 +58,12 @@
5658
"output_type": "stream",
5759
"text": [
5860
"httpx HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
59-
"🛠️ response: ChatCompletion(id='chatcmpl-AwEo44477GfWgRBYRX52doAPZkS27', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Numbers, shapes, patterns, logic, problem-solving, calculations.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1738443304, model='gpt-3.5-turbo-0125', object='chat.completion', service_tier='default', system_fingerprint=None, usage=CompletionUsage(completion_tokens=14, prompt_tokens=13, total_tokens=27, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))\n"
61+
"🛠️ response: ChatCompletion(id='chatcmpl-AxJ0qRpV38wCHo1cI8Asv2llWT2ZB', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Numbers, shapes, patterns, logic, calculations, problem-solving.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1738697800, model='gpt-3.5-turbo-0125', object='chat.completion', service_tier='default', system_fingerprint=None, usage=CompletionUsage(completion_tokens=14, prompt_tokens=13, total_tokens=27, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))\n"
6062
]
6163
}
6264
],
6365
"source": [
64-
"success, text, _ = complete_prompt(\"Describe Mathematics in seven words.\")\n",
66+
"success, text, _ = generate_text(messages=test_messages)\n",
6567
"assert success"
6668
]
6769
},
@@ -74,12 +76,12 @@
7476
"name": "stderr",
7577
"output_type": "stream",
7678
"text": [
77-
"🛠️ text: Numbers, shapes, patterns, logic, problem-solving, calculations.\n"
79+
"🛠️ Numbers, shapes, patterns, logic, calculations, problem-solving.\n"
7880
]
7981
}
8082
],
8183
"source": [
82-
"logger.info(f\"text: {text}\")"
84+
"logger.info(text)"
8385
]
8486
},
8587
{
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"metadata": {},
7+
"source": [
8+
"# text generation\n",
9+
"from prompt"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"# ! pip3 install --upgrade openai"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 2,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"name": "stderr",
28+
"output_type": "stream",
29+
"text": [
30+
"🛠️ openai_commands-3.242.1.blueflow-4.849.1.abcli-9.486.1.blue_objects-5.283.1.blue_options-4.207.1.torch-2.5.1.Python 3.9.6.Darwin 23.6.0..Jupyter-Notebook,\n",
31+
"built on 04 February 2025, 11:36:15\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"import sys\n",
37+
"sys.path.append(\"../\")\n",
38+
"\n",
39+
"from blueflow import notebooks\n",
40+
"\n",
41+
"from blue_options import string\n",
42+
"\n",
43+
"from openai_commands.tests.test_text_generation import test_prompt\n",
44+
"from openai_commands.text_generation.api import generate_text\n",
45+
"from openai_commands.host import signature\n",
46+
"from openai_commands.logger import logger\n",
47+
"\n",
48+
"logger.info(f\"{'.'.join(signature())},\\nbuilt on {string.pretty_date()}\")"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": 3,
54+
"metadata": {},
55+
"outputs": [
56+
{
57+
"name": "stderr",
58+
"output_type": "stream",
59+
"text": [
60+
"httpx HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
61+
"🛠️ response: ChatCompletion(id='chatcmpl-AxJ0S5dsL1gWBBxD6eCSVaIKiRTjx', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Logic and rules for studying quantities.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1738697776, model='gpt-3.5-turbo-0125', object='chat.completion', service_tier='default', system_fingerprint=None, usage=CompletionUsage(completion_tokens=8, prompt_tokens=13, total_tokens=21, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))\n"
62+
]
63+
}
64+
],
65+
"source": [
66+
"success, text, _ = generate_text(prompt=test_prompt)\n",
67+
"assert success"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 4,
73+
"metadata": {},
74+
"outputs": [
75+
{
76+
"name": "stderr",
77+
"output_type": "stream",
78+
"text": [
79+
"🛠️ Logic and rules for studying quantities.\n"
80+
]
81+
}
82+
],
83+
"source": [
84+
"logger.info(text)"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": 5,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"# END"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": ".venv",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.9.6"
114+
},
115+
"orig_nbformat": 4
116+
},
117+
"nbformat": 4,
118+
"nbformat_minor": 2
119+
}

openai_commands/.abcli/image_generation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function openai_commands_generate_image() {
1212

1313
abcli_eval dryrun=$do_dryrun \
1414
python3 -m openai_commands.image_generation \
15-
$task \
15+
generate_image \
1616
--filename $filename \
1717
--prompt "\"$prompt\"" \
1818
--object_name $object_name \

openai_commands/.abcli/prompt_completion.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

openai_commands/.abcli/tests/help.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ function test_openai_commands_help() {
1111
\
1212
"@openai browse" \
1313
\
14-
"@openai complete" \
15-
\
1614
"@openai generate_image" \
1715
\
16+
"@openai generate_text" \
17+
\
1818
"@openai"; do
1919
abcli_eval ,$options \
2020
abcli_help $module
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#! /usr/bin/env bash
22

3-
function test_openai_commands_complete() {
3+
function test_openai_generate_image() {
44
local options=$1
55

66
openai_commands_generate_image \
77
~upload,$options \
88
"a person flying through the streets of Vancouver." \
9-
test_openai_commands_complete-$(abcli_string_timestamp_short) \
9+
test_openai_generate_image-$(abcli_string_timestamp_short) \
1010
--verbose 1
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env bash
22

3-
function test_openai_commands_complete() {
3+
function test_openai_commands_generate_text() {
44
openai_commands \
5-
complete \
5+
generate_text \
66
"Describe Mathematics in seven words."
77
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /usr/bin/env bash
2+
3+
function openai_commands_generate_text() {
4+
python3 -m openai_commands.text_generation \
5+
generate_text \
6+
--prompt "$1" \
7+
"${@:2}"
8+
}

0 commit comments

Comments
 (0)