Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,24 +5,26 @@ from llama_index import GPTSimpleVectorIndex
|
|
5 |
from langchain.agents import ZeroShotAgent, AgentExecutor
|
6 |
from langchain.agents import Tool
|
7 |
from langchain import OpenAI, LLMChain
|
8 |
-
|
9 |
-
|
10 |
|
11 |
s3 = boto3.resource('s3')
|
12 |
bucket_name = "notesinendocrinology"
|
13 |
bucket = s3.Bucket(bucket_name)
|
14 |
for obj in bucket.objects.filter(Prefix="comboindex.json"):
|
15 |
combo_index_path = obj.key
|
16 |
-
bucket.download_file(combo_index_path, "comboindex.json")
|
17 |
-
|
18 |
-
index = GPTSimpleVectorIndex.load_from_disk('comboindex.json')
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def querying_db(query: str):
|
|
|
22 |
response = index.query(query)
|
23 |
return response
|
24 |
|
25 |
-
|
26 |
tools = [
|
27 |
Tool(
|
28 |
name="QueryingDB",
|
|
|
5 |
from langchain.agents import ZeroShotAgent, AgentExecutor
|
6 |
from langchain.agents import Tool
|
7 |
from langchain import OpenAI, LLMChain
|
8 |
+
from cachetools import cached, TTLCache
|
|
|
9 |
|
10 |
s3 = boto3.resource('s3')
|
11 |
bucket_name = "notesinendocrinology"
|
12 |
bucket = s3.Bucket(bucket_name)
|
13 |
for obj in bucket.objects.filter(Prefix="comboindex.json"):
|
14 |
combo_index_path = obj.key
|
|
|
|
|
|
|
15 |
|
16 |
+
@cached(cache=TTLCache(maxsize=1, ttl=3600)) # cache for 1 hour
|
17 |
+
def get_combo_index():
|
18 |
+
# download and load the comboindex.json file
|
19 |
+
bucket.download_file(combo_index_path, "comboindex.json")
|
20 |
+
index = GPTSimpleVectorIndex.load_from_disk('comboindex.json')
|
21 |
+
return index
|
22 |
|
23 |
def querying_db(query: str):
|
24 |
+
index = get_combo_index()
|
25 |
response = index.query(query)
|
26 |
return response
|
27 |
|
|
|
28 |
tools = [
|
29 |
Tool(
|
30 |
name="QueryingDB",
|