-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_indexer.py
More file actions
59 lines (43 loc) · 1.94 KB
/
Copy pathcode_indexer.py
File metadata and controls
59 lines (43 loc) · 1.94 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import requests
from langchain.embeddings import BedrockEmbeddings
from langchain.vectorstores import FAISS
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.document_loaders import UnstructuredHTMLLoader
from pathlib import Path
# response = requests.get("https://d3bnjxknjlugy9.cloudfront.net/")
# with open("data/documents.html", "w") as f:
# f.write(response.text)
def get_html():
"""Function takes in the pdf data and returns the
splits so for further processing can be done."""
loader = UnstructuredHTMLLoader("data/documents.html")
return loader.load()
def embed_index(doc_list, embed_fn, index_store):
# check whether the doc_list is documents, or text
faiss_db = FAISS.from_documents(doc_list, embed_fn)
if os.path.exists(index_store):
local_db = FAISS.load_local(index_store, embed_fn)
local_db.merge_from(faiss_db)
print("Merge completed")
local_db.save_local(index_store)
print("Updated index saved")
else:
faiss_db.save_local(folder_path=index_store)
print("New store created...")
embeddings = BedrockEmbeddings(
credentials_profile_name="default", # sets the profile name to use for AWS credentials (if not the default)
region_name="us-east-1", # sets the region name (if not the default)
# model_id="meta.llama2-70b-chat-v1", # set the foundation model
# endpoint_url=os.environ.get("BWB_ENDPOINT_URL"), #sets the endpoint URL (if necessary)
) # create a Titan Embeddings client
document = get_html()
embed_index(
doc_list=document,
embed_fn=embeddings,
index_store='code_new_index'
)
print("---------------")
# input_text = """Instruction: Create a single recipe request body in JSON format. Ensure the JSON follows the structure of a recipe based on the Description of each field.
# The recipe is:""" + input_text
# llm_model(maxTokens=2048,temperature=0.1, topP=0.3).get_model()