Arthur2G commited on
Commit
05883f8
·
1 Parent(s): 033d96f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -19,6 +19,21 @@ from llama_index.indices.vector_store.base import GPTVectorStoreIndex
19
  from adlfs import AzureBlobFileSystem
20
  import time
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  def construct_index(doc):
23
 
24
  ## Define the prompt helper
@@ -51,7 +66,6 @@ def construct_index(doc):
51
 
52
  # save index to disk
53
  index.set_index_id("vector_index")
54
- index.storage_context.persist('/gpttest')
55
 
56
  return index
57
 
@@ -77,10 +91,10 @@ def ask_ai(doc, question):
77
  index = construct_index([Document(text)])
78
 
79
  # Save index to Azure blob storage
80
- index.storage_context.persist(f'gpttest/{file_name}', fs=fs)
81
 
82
  # Rebuild storage context
83
- storage_context = StorageContext.from_defaults(persist_dir=f'gpttest/{file_name}')
84
 
85
  # Load index
86
  index = load_index_from_storage(storage_context)
 
19
  from adlfs import AzureBlobFileSystem
20
  import time
21
 
22
+ # Blob storage parameters
23
+ account_name = 'apeazdlkini07s'
24
+ account_key = os.environ['account_key']
25
+ file_system_name = "gpt"
26
+ service_client = DataLakeServiceClient(account_url=f"https://{account_name}.dfs.core.windows.net", credential=account_key)
27
+ file_system_client = service_client.get_file_system_client(file_system_name)
28
+
29
+ AZURE_ACCOUNT_NAME = account_name
30
+ AZURE_ACCOUNT_KEY = account_key
31
+
32
+ assert AZURE_ACCOUNT_NAME is not None and AZURE_ACCOUNT_NAME != ""
33
+
34
+ fs = AzureBlobFileSystem(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY)
35
+
36
+
37
  def construct_index(doc):
38
 
39
  ## Define the prompt helper
 
66
 
67
  # save index to disk
68
  index.set_index_id("vector_index")
 
69
 
70
  return index
71
 
 
91
  index = construct_index([Document(text)])
92
 
93
  # Save index to Azure blob storage
94
+ index.storage_context.persist(f'gpt/storage_demo/{file_name}', fs=fs)
95
 
96
  # Rebuild storage context
97
+ storage_context = StorageContext.from_defaults(persist_dir=f'gpt/storage_demo/{file_name}', fs=fs)
98
 
99
  # Load index
100
  index = load_index_from_storage(storage_context)