Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
})
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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']
|