Chris4K commited on
Commit
f44a6d7
·
verified ·
1 Parent(s): 37ef0c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -114,13 +114,41 @@ def index_urls_in_rag(urls):
114
  async def startup():
115
  domain_url = 'https://www.bofrost.de/faq/'
116
  urls = get_all_links_from_domain(domain_url)
 
117
  retriever_chain = index_urls_in_rag(urls)
118
 
119
  # Define API endpoint to receive queries and provide responses
120
  @app.post("/generate/")
121
  def generate(user_input):
122
- response = retriever_chain.invoke({
123
- "chat_history": [],
124
- "input": user_input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  })
126
- return response['answer']
 
 
 
 
 
114
  async def startup():
115
  domain_url = 'https://www.bofrost.de/faq/'
116
  urls = get_all_links_from_domain(domain_url)
117
+
118
  retriever_chain = index_urls_in_rag(urls)
119
 
120
  # Define API endpoint to receive queries and provide responses
121
  @app.post("/generate/")
122
  def generate(user_input):
123
+
124
+ return get_response(user_input, []])
125
+
126
+
127
+ def get_response(message, history=[]):
128
+ dialog = history_to_dialog_format(history)
129
+ dialog.append({"role": "user", "content": message})
130
+
131
+ # Define the prompt as a ChatPromptValue object
132
+ #user_input = ChatPromptValue(user_input)
133
+
134
+ # Convert the prompt to a tensor
135
+ #input_ids = user_input.tensor
136
+
137
+
138
+ #vs = get_vectorstore_from_url(user_url, all_domain)
139
+ vs = get_vectorstore_from_url("https://huggingface.co/Chris4K")
140
+
141
+ history =[]
142
+ retriever_chain = get_context_retriever_chain(vs)
143
+ conversation_rag_chain = get_conversational_rag_chain(retriever_chain)
144
+
145
+ response = conversation_rag_chain.invoke({
146
+ "chat_history": history,
147
+ "input": message + " Assistant: ",
148
+ "chat_message": message + " Assistant: "
149
  })
150
+ #print("get_response " +response)
151
+ res = response['answer']
152
+ parts = res.split(" Assistant: ")
153
+ last_part = parts[-1]
154
+ return last_part#[-1]['generation']['content']