Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
|
d09a57062c | ||
|
c14e81fd86 | ||
|
8d8cd8950f | ||
|
98660d372b | ||
|
ed86a269c1 | ||
|
74e940c45d | ||
|
70194de64c | ||
|
656bfa79df | ||
|
aa77d05721 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
# Sensitive files
|
||||
config.py
|
||||
*.png
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
|
58
README.md
58
README.md
|
@ -7,6 +7,8 @@ You can manipulate the main abstractions of the OpenAI model:
|
|||
* Responses
|
||||
* Inputs
|
||||
* Items
|
||||
* Vector Stores
|
||||
* Files
|
||||
|
||||
**Requirements**
|
||||
|
||||
|
@ -16,22 +18,42 @@ You can manipulate the main abstractions of the OpenAI model:
|
|||
**How to run this application**
|
||||
|
||||
* Copy the file `config-sample.py` to `config.py`.
|
||||
* Edit `config.py` with your credentials and defaults.
|
||||
* Each script has a number of mandatory parameters in strict order:
|
||||
| Script | Parameter 1 | Parameter 2 | Parameter 3 | Purpose |
|
||||
| ---------------------------- | ----------------- | --------------- | --------------- | -------------------------------------------------------- |
|
||||
| `cancel_model_response.py` | `response_id` | | | Cancel a Response running in the background |
|
||||
| `create_conversation.py` | | | | Create a new 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 |
|
||||
| `delete_conversation.py` | `conversation_id` | | | Delete a Conversation |
|
||||
| `delete_item.py` | `conversation_id` | `item_id` | | Delete an Item (input or Response) from a Conversation |
|
||||
| `delete_model_response.py` | `response_id` | | | Delete a Response |
|
||||
| `list_input_items.py` | `response_id` | | | List all input Items used to generate a Response |
|
||||
| `list_items.py` | `conversation_id` | | | List all Items (inputs or Responses) in a Conversation |
|
||||
| `retrieve_conversation.py` | `conversation_id` | | | Retrieve a Conversation |
|
||||
| `retrieve_item.py` | `conversation_id` | `item_id` | | Retrieve an Item from a Conversation |
|
||||
| `retrieve_model_response.py` | `response_id` | | | Retrieve a model Response |
|
||||
| `update_conversation.py` | `conversation_id` | `metadata` | | Update a Conversation metadata |
|
||||
* To execute these scripts run `python3 <script.py> <parameter_1> ...`.
|
||||
|
||||
* Edit `config.py` with your credentials and defaults.
|
||||
|
||||
* Each script has a number of mandatory parameters in strict order:
|
||||
|
||||
| Script | Parameter 1 | Parameter 2 | Parameter 3 | Purpose |
|
||||
| --------------------------------------- | ----------------- | --------------- | --------------- | -------------------------------------------------------- |
|
||||
| `cancel_model_response.py` | `response_id` | | | Cancel a Response running in the background |
|
||||
| `create_conversation.py` | | | | Create a new Conversation |
|
||||
| `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_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_file.py` | `vector_store_id` | `file_id` | | Create a File in a Vector Store |
|
||||
| `delete_conversation.py` | `conversation_id` | | | Delete a Conversation |
|
||||
| `delete_file.py` | `file_id` | | | Delete a File |
|
||||
| `delete_item.py` | `conversation_id` | `item_id` | | Delete an Item (input or Response) from a Conversation |
|
||||
| `delete_model_response.py` | `response_id` | | | Delete a Response |
|
||||
| `delete_vector_store.py` | `vector_store_id` | | | Delete a Vector Store |
|
||||
| `delete_vector_store_file.py` | `vector_store_id` | `file_id` | | Delete a File from a Vector Store |
|
||||
| `list_files.py` | | | | List all uploaded Files |
|
||||
| `list_input_items.py` | `response_id` | | | List all input Items used to generate a Response |
|
||||
| `list_items.py` | `conversation_id` | | | List all Items (inputs or Responses) in a Conversation |
|
||||
| `list_vector_store_files.py` | `vector_store_id` | | | List all Files in a Vector Store |
|
||||
| `list_vector_stores.py` | | | | List all Vector Stores |
|
||||
| `modify_vector_store.py` | `vector_store_id` | `metadata` | | Update a Vector Store metadata |
|
||||
| `retrieve_conversation.py` | `conversation_id` | | | Retrieve a Conversation |
|
||||
| `retrieve_file.py` | `file_id` | | | Retrieve a File |
|
||||
| `retrieve_file_content.py` | `file_id` | | | Retrieve the content of File |
|
||||
| `retrieve_item.py` | `conversation_id` | `item_id` | | Retrieve an Item from a Conversation |
|
||||
| `retrieve_model_response.py` | `response_id` | | | Retrieve a model Response |
|
||||
| `retrieve_vector_store.py` | `vector_store_id` | | | Retrieve a Vector Store |
|
||||
| `retrieve_vector_store_file.py` | `vector_store_id` | `file_id` | | Retrieve a File from a Vector Store |
|
||||
| `retrieve_vector_store_file_content.py` | `vector_store_id` | `file_id` | | Retrieve the content of a File from a Vector Store |
|
||||
| `update_conversation.py` | `conversation_id` | `metadata` | | Update a Conversation metadata |
|
||||
| `update_vector_store_file.py` | `vector_store_id` | `file_id` | `attributes` | Update a File attributes |
|
||||
| `upload_file.py` | `filename` | `path-to-file` | | Upload a File to the OpenAI platform |
|
||||
|
||||
* To execute these scripts run `python3 <script.py> <parameter_1> ...`.
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 0.4.x | :heavy_check_mark: |
|
||||
| 0.3.x | :heavy_check_mark: |
|
||||
| 0.2.x | :heavy_check_mark: |
|
||||
| 0.1.x | :heavy_check_mark: |
|
||||
|
||||
## Reporting
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
base_url = "https://api.openai.com/v1/"
|
||||
secret_key = "YOUR-OPENAI-SECRET-KEY-HERE"
|
||||
|
||||
vector_store = "YOUR-VECTOR-STORE-ID-HERE"
|
||||
|
||||
|
|
33
create_image.py
Normal file
33
create_image.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from config import *
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
import base64
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
from datetime import datetime
|
||||
|
||||
def create_image(model,prompt):
|
||||
url = base_url+"images/generations"
|
||||
|
||||
payload = json.dumps({
|
||||
"prompt": prompt,
|
||||
"model": model
|
||||
})
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
date_time_string = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
decoded_bytes = base64.b64decode(response.json()["data"][0]["b64_json"])
|
||||
byte_stream = BytesIO(decoded_bytes)
|
||||
image = Image.open(byte_stream)
|
||||
image.save("./output_images/output-"+date_time_string+".png", "PNG")
|
||||
|
||||
print("Image ./output_images/output-"+date_time_string+".png has been generated.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
create_image(str(sys.argv[1]),str(sys.argv[2]))
|
|
@ -10,6 +10,7 @@ def create_model_response(conversation,model,message):
|
|||
"model": model,
|
||||
"tools": [
|
||||
{"type": "web_search"},
|
||||
{"type": "file_search", "vector_store_ids" :[vector_store]}
|
||||
],
|
||||
"input": message,
|
||||
"conversation": conversation
|
||||
|
|
14
create_vector_store.py
Normal file
14
create_vector_store.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from config import *
|
||||
import requests
|
||||
|
||||
url = base_url+"vector_stores"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
23
create_vector_store_file.py
Normal file
23
create_vector_store_file.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from config import *
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
def create_vector_store_file(vector_store_id,file_id):
|
||||
url = base_url+"vector_stores/"+vector_store_id+"/files"
|
||||
|
||||
payload = json.dumps({
|
||||
"file_id": file_id
|
||||
})
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
create_vector_store_file(str(sys.argv[1]),str(sys.argv[2]))
|
19
delete_file.py
Normal file
19
delete_file.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def delete_file(file_id):
|
||||
url = base_url+"files/"+file_id
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
delete_file(str(sys.argv[1]))
|
19
delete_vector_store.py
Normal file
19
delete_vector_store.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def delete_vector_store(vector_store):
|
||||
url = base_url+"vector_stores/"+vector_store
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
delete_vector_store(str(sys.argv[1]))
|
19
delete_vector_store_file.py
Normal file
19
delete_vector_store_file.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def delete_vector_store_file(vector_store,file_id):
|
||||
url = base_url+"vector_stores/"+vector_store+"/files/"+file_id
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("DELETE", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
delete_vector_store_file(str(sys.argv[1]),str(sys.argv[2]))
|
14
list_files.py
Normal file
14
list_files.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from config import *
|
||||
import requests
|
||||
|
||||
url = base_url+"files"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
19
list_vector_store_files.py
Normal file
19
list_vector_store_files.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def list_vector_store_files(vector_store):
|
||||
url = base_url+"vector_stores/"+vector_store+"/files"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
list_vector_store_files(str(sys.argv[1]))
|
14
list_vector_stores.py
Normal file
14
list_vector_stores.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from config import *
|
||||
import requests
|
||||
|
||||
url = base_url+"vector_stores"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
22
modify_vector_store.py
Normal file
22
modify_vector_store.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from config import *
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
def modify_vector_store(vector_store_id,metadata):
|
||||
url = base_url+"vector_stores/"+vector_store_id
|
||||
|
||||
payload = json.dumps({
|
||||
"metadata": json.loads(metadata)
|
||||
})
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
if __name__ == '__main__':
|
||||
modify_vector_store(str(sys.argv[1]),str(sys.argv[2]))
|
0
output_images/__init__.py
Normal file
0
output_images/__init__.py
Normal file
19
retrieve_file.py
Normal file
19
retrieve_file.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def retrieve_file(file_id):
|
||||
url = base_url+"files/"+file_id
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
retrieve_file(str(sys.argv[1]))
|
19
retrieve_file_content.py
Normal file
19
retrieve_file_content.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def retrieve_file_content(file_id):
|
||||
url = base_url+"files/"+file_id+"/content"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
retrieve_file_content(str(sys.argv[1]))
|
|
@ -13,6 +13,7 @@ def retrieve_item(conversation,message):
|
|||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
print(response.json()["content"][0]["text"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
19
retrieve_vector_store.py
Normal file
19
retrieve_vector_store.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def retrieve_vector_store(vector_store):
|
||||
url = base_url+"vector_stores/"+vector_store
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
retrieve_vector_store(str(sys.argv[1]))
|
19
retrieve_vector_store_file.py
Normal file
19
retrieve_vector_store_file.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def retrieve_vector_store_file(vector_store,file_id):
|
||||
url = base_url+"vector_stores/"+vector_store+"/files/"+file_id
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
retrieve_vector_store_file(str(sys.argv[1]),str(sys.argv[2]))
|
19
retrieve_vector_store_file_content.py
Normal file
19
retrieve_vector_store_file_content.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def retrieve_vector_store_file_content(vector_store,file_id):
|
||||
url = base_url+"vector_stores/"+vector_store+"/files/"+file_id+"/content"
|
||||
|
||||
payload = {}
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
retrieve_vector_store_file_content(str(sys.argv[1]),str(sys.argv[2]))
|
22
update_vector_store_file.py
Normal file
22
update_vector_store_file.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from config import *
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
|
||||
def update_vector_store_file(vector_store_id,file_id,attributes):
|
||||
url = base_url+"vector_stores/"+vector_store_id+"/files/"+file_id
|
||||
|
||||
payload = json.dumps({
|
||||
"attributes": json.loads(attributes)
|
||||
})
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
print(response.text)
|
||||
|
||||
if __name__ == '__main__':
|
||||
update_vector_store_file(str(sys.argv[1]),str(sys.argv[2]),str(sys.argv[3]))
|
22
upload_file.py
Normal file
22
upload_file.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from config import *
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def upload_file(filename, path):
|
||||
url = base_url+"files"
|
||||
|
||||
payload = {'purpose': 'user_data'}
|
||||
files=[
|
||||
('file',(filename,open(path,'rb'),'application/pdf'))
|
||||
]
|
||||
headers = {
|
||||
'Authorization': 'Bearer '+secret_key,
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload, files=files)
|
||||
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
upload_file(str(sys.argv[1]),str(sys.argv[2]))
|
Loading…
Reference in a new issue