Compare commits

..

No commits in common. "dc23d1ac9eee8ee1f391b256c778c33c9b591a4d" and "2032483e6473997108d220e48a19df5af7a3f932" have entirely different histories.

3 changed files with 41 additions and 66 deletions

View file

@ -24,10 +24,10 @@ You can manipulate the main abstractions of the OpenAI model:
* Each script has a number of mandatory parameters in strict order: * Each script has a number of mandatory parameters in strict order:
| Script | Parameter 1 | Parameter 2 | Parameter 3 | Purpose | | Script | Parameter 1 | Parameter 2 | Parameter 3 | Purpose |
| --------------------------------------- | ----------------- | --------------- | --------------- | ------------------------------------------------------------------------- | | --------------------------------------- | ----------------- | --------------- | --------------- | -------------------------------------------------------- |
| `cancel_model_response.py` | `response_id` | | | Cancel a Response running in the background | | `cancel_model_response.py` | `response_id` | | | Cancel a Response running in the background |
| `create_conversation.py` | | | | Create a new Conversation | | `create_conversation.py` | | | | Create a new Conversation |
| `create_image.py` | `model_id` | `prompt` | `image.png` | Create an image based on the prompt description and/or the image provided | | `create_image.py` | `model_id` | `prompt` | | Create an image based on the prompt description |
| `create_model_response.py` | `conversation_id` | `model_id` | `input_message` | Create a Response within a Conversation | | `create_model_response.py` | `conversation_id` | `model_id` | `input_message` | Create a Response within a Conversation |
| `create_text_item.py` | `conversation_id` | `input_message` | | Create a user input or instruction within a Conversation | | `create_text_item.py` | `conversation_id` | `input_message` | | Create a user input or instruction within a Conversation |
| `create_vector_store.py` | | | | Create a Vector Store | | `create_vector_store.py` | | | | Create a Vector Store |

View file

@ -4,7 +4,6 @@
| Version | Supported | | Version | Supported |
| ------- | ------------------ | | ------- | ------------------ |
| 0.6.x | :heavy_check_mark: |
| 0.5.x | :heavy_check_mark: | | 0.5.x | :heavy_check_mark: |
| 0.4.x | :heavy_check_mark: | | 0.4.x | :heavy_check_mark: |
| 0.3.x | :heavy_check_mark: | | 0.3.x | :heavy_check_mark: |

View file

@ -7,40 +7,20 @@ from PIL import Image
from io import BytesIO from io import BytesIO
from datetime import datetime from datetime import datetime
def create_image(model,prompt,image_path=None): def create_image(model,prompt):
# choose endpoint depending on whether an image is provided
if image_path:
url = base_url+"images/edits"
else:
url = base_url+"images/generations" url = base_url+"images/generations"
headers = {
'Authorization': 'Bearer '+secret_key,
}
date_time_string = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
if image_path:
# For edits, use multipart/form-data
data = {
"prompt": prompt,
"model": model
}
files = {
"image": open(image_path, "rb")
}
response = requests.post(url, headers=headers, data=data, files=files)
else:
# For generations, use JSON
payload = json.dumps({ payload = json.dumps({
"prompt": prompt, "prompt": prompt,
"model": model "model": model
}) })
headers['Content-Type'] = 'application/json' headers = {
response = requests.post(url, headers=headers, data=payload) 'Content-Type': 'application/json',
if response.status_code != 200: 'Authorization': 'Bearer '+secret_key,
print(f"Error: {response.status_code} - {response.text}") }
sys.exit(1) date_time_string = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
# handle response data: both generation and edits return b64_json in data[0]
response = requests.request("POST", url, headers=headers, data=payload)
decoded_bytes = base64.b64decode(response.json()["data"][0]["b64_json"]) decoded_bytes = base64.b64decode(response.json()["data"][0]["b64_json"])
byte_stream = BytesIO(decoded_bytes) byte_stream = BytesIO(decoded_bytes)
image = Image.open(byte_stream) image = Image.open(byte_stream)
@ -50,8 +30,4 @@ def create_image(model,prompt,image_path=None):
if __name__ == '__main__': if __name__ == '__main__':
# usage: python create_image.py <model> <prompt> [image_path] create_image(str(sys.argv[1]),str(sys.argv[2]))
model = str(sys.argv[1]) if len(sys.argv) > 1 else ''
prompt = str(sys.argv[2]) if len(sys.argv) > 2 else ''
image_path = str(sys.argv[3]) if len(sys.argv) > 3 else None
create_image(model,prompt,image_path)