Cheselle commited on
Commit
43f37ba
·
verified ·
1 Parent(s): e0a8eac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -42,15 +42,19 @@ HF_TOKEN = os.environ["HF_TOKEN"]
42
  """
43
  ### 1. CREATE TEXT LOADER AND LOAD DOCUMENTS
44
  ### NOTE: PAY ATTENTION TO THE PATH THEY ARE IN.
45
- text_loader =
46
- documents =
47
 
48
  ### 2. CREATE TEXT SPLITTER AND SPLIT DOCUMENTS
49
- text_splitter =
50
- split_documents =
51
 
52
  ### 3. LOAD HUGGINGFACE EMBEDDINGS
53
- hf_embeddings =
 
 
 
 
54
 
55
  async def add_documents_async(vectorstore, documents):
56
  await vectorstore.aadd_documents(documents)
@@ -110,17 +114,39 @@ hf_retriever = asyncio.run(run())
110
  2. Create a Prompt Template from the String Template
111
  """
112
  ### 1. DEFINE STRING TEMPLATE
113
- RAG_PROMPT_TEMPLATE =
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  ### 2. CREATE PROMPT TEMPLATE
116
- rag_prompt =
117
 
118
  # -- GENERATION -- #
119
  """
120
  1. Create a HuggingFaceEndpoint for the LLM
121
  """
122
  ### 1. CREATE HUGGINGFACE ENDPOINT FOR LLM
123
- hf_llm =
 
 
 
 
 
 
 
 
 
124
 
125
  @cl.author_rename
126
  def rename(original_author: str):
 
42
  """
43
  ### 1. CREATE TEXT LOADER AND LOAD DOCUMENTS
44
  ### NOTE: PAY ATTENTION TO THE PATH THEY ARE IN.
45
+ text_loader = TextLoader("./paul-graham-to-kindle/paul_graham_essays.txt")
46
+ documents = document_loader.load()
47
 
48
  ### 2. CREATE TEXT SPLITTER AND SPLIT DOCUMENTS
49
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=30)
50
+ split_documents = text_splitter.split_documents(documents)
51
 
52
  ### 3. LOAD HUGGINGFACE EMBEDDINGS
53
+ hf_embeddings = HuggingFaceEndpointEmbeddings(
54
+ model=YOUR_EMBED_MODEL_URL,
55
+ task="feature-extraction",
56
+ huggingfacehub_api_token=os.environ["HF_TOKEN"],
57
+ )
58
 
59
  async def add_documents_async(vectorstore, documents):
60
  await vectorstore.aadd_documents(documents)
 
114
  2. Create a Prompt Template from the String Template
115
  """
116
  ### 1. DEFINE STRING TEMPLATE
117
+ RAG_PROMPT_TEMPLATE = """\
118
+ <|start_header_id|>system<|end_header_id|>
119
+ You are a helpful assistant. You answer user questions based on provided context. If you can't answer the question with the provided context, say you don't know.<|eot_id|>
120
+
121
+ <|start_header_id|>user<|end_header_id|>
122
+ User Query:
123
+ {query}
124
+
125
+ Context:
126
+ {context}<|eot_id|>
127
+
128
+ <|start_header_id|>assistant<|end_header_id|>
129
+ """
130
+
131
 
132
  ### 2. CREATE PROMPT TEMPLATE
133
+ rag_prompt = PromptTemplate.from_template(RAG_PROMPT_TEMPLATE)
134
 
135
  # -- GENERATION -- #
136
  """
137
  1. Create a HuggingFaceEndpoint for the LLM
138
  """
139
  ### 1. CREATE HUGGINGFACE ENDPOINT FOR LLM
140
+ hf_llm = HuggingFaceEndpoint(
141
+ endpoint_url=f"{YOUR_LLM_ENDPOINT_URL}",
142
+ max_new_tokens=512,
143
+ top_k=10,
144
+ top_p=0.95,
145
+ typical_p=0.95,
146
+ temperature=0.01,
147
+ repetition_penalty=1.03,
148
+ huggingfacehub_api_token=os.environ["HF_TOKEN"]
149
+ )
150
 
151
  @cl.author_rename
152
  def rename(original_author: str):