Add functionality for using vector storages and file uploads
This commit is contained in:
parent
19b13ecbff
commit
aa77d05721
|
@ -1,4 +1,4 @@
|
||||||
base_url = "https://api.openai.com/v1/"
|
base_url = "https://api.openai.com/v1/"
|
||||||
secret_key = "YOUR-OPENAI-SECRET-KEY-HERE"
|
secret_key = "YOUR-OPENAI-SECRET-KEY-HERE"
|
||||||
|
vector_store = "YOUR-VECTOR-STORE-ID-HERE"
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ def create_model_response(conversation,model,message):
|
||||||
"model": model,
|
"model": model,
|
||||||
"tools": [
|
"tools": [
|
||||||
{"type": "web_search"},
|
{"type": "web_search"},
|
||||||
|
{"type": "file_search", "vector_store_ids" :[vector_store]}
|
||||||
],
|
],
|
||||||
"input": message,
|
"input": message,
|
||||||
"conversation": conversation
|
"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)
|
||||||
|
|
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]))
|
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
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