Created
April 10, 2024 00:45
-
-
Save halfprice06/01ebaacdf3873834b28a7f650347e1e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is the generator function that streams back to the client with htmx SSE | |
async def process_and_stream_rag_response(user_query, search_terms, message_id, role="assistant"): | |
final_output = "" # Initialize an empty string to store the final output | |
async for text in retrieval_augmented_generation(user_query, search_terms): | |
# Convert the text from Markdown to HTML for each chunk | |
text_html = markdown.markdown(text, extensions=['tables', 'footnotes', 'fenced_code']) | |
# Apply nl2br_table to convert newlines to <br> tags in the HTML text | |
final_output = nl2br_table(text_html) | |
yield f'<div hx-swap-oob="true" class="pl-11 pr-4 text-justify text-gray-700" id="{role}_message_{message_id}">{final_output}</div>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment