-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path__init__.py
More file actions
38 lines (32 loc) · 1.21 KB
/
__init__.py
File metadata and controls
38 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from lib.logging_utils import init_logger
from lib.openai_client import get_openai_client
import json
import os
import redis_mgr
logger = init_logger(__name__)
default_options = {
"organization_key": "org-xxxxx",
"project_key": "proj_xxxxxxx",
"api_key": "sk-proj-xxxxxx",
"vector_store_id": "xxxxxx",
"purpose": "assistants",
}
def save(vcon_uuid: str, options: dict = default_options) -> None:
"""Save a vCon to ChatGPT files.
Args:
vcon_uuid (str): The UUID of the vCon to be saved.
options (dict, optional): Dictionary containing organization and project keys, API key,
vector store ID, and purpose. Defaults to default_options.
"""
try:
vcon = redis_mgr.get_key(vcon_uuid)
file_name = f"{vcon_uuid}.vcon.json"
with open(file_name, "w") as file:
json.dump(vcon, file)
client = get_openai_client(options)
with open(file_name, "rb") as upload_file:
file = client.files.create(file=upload_file, purpose=options["purpose"])
os.remove(file_name)
client.beta.vector_stores.files.create(vector_store_id=options["vector_store_id"], file_id=file.id)
except Exception as error:
raise error