/
dev_manager_start_local_env.py
54 lines (38 loc) · 1.36 KB
/
dev_manager_start_local_env.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import yaml
from pinecone import Pinecone, PodSpec
from config.main import PINECONE_API_KEY, LOCAL_GEN_CONFIG_FILE_NAME
from typing import TypedDict
from uuid import uuid4
OUTPUTFILE_PATH = f"./{LOCAL_GEN_CONFIG_FILE_NAME}.yaml"
DIMENSION = 256 # NOTE: 次元数(256次元で固定)
class _GenerationConfigYamlFilePineCone(TypedDict):
index: str
class GenerationConfigYamlFile(TypedDict):
pinecone: _GenerationConfigYamlFilePineCone
if __name__ == '__main__':
# NOTE: check exist configuration file
if os.path.exists(OUTPUTFILE_PATH):
raise Exception(f"【Already Find {LOCAL_GEN_CONFIG_FILE_NAME} file】")
pinecone_index_name = "local-" + str(uuid4())
pinecone_client = Pinecone(api_key=PINECONE_API_KEY)
try:
pinecone_client.create_index(
name=pinecone_index_name,
dimension=DIMENSION,
metric="cosine",
spec=PodSpec(
environment="asia-northeast1-gcp",
pod_type="s1.x1",
pods=1
)
)
with open(OUTPUTFILE_PATH, "w") as f:
data: GenerationConfigYamlFile = {
"pinecone": {
"index": pinecone_index_name
}
}
yaml.dump(data, f, encoding='utf-8', allow_unicode=True)
except Exception as e:
print(str(e))