Cohere RAG Inline Citation Markdown Generator
Cohere RAG Inline Citation Markdown Generator
This helper function generates a formatted response with citations in both markdown and HTML formats. The function can be customized to change the look and feel of the output.
Parameters:
non_cited_response (str): The response text without citations. citations (list): List of citation objects. Each citation object should have the attributes start, end, text, and document_ids. doc_url_mapping (dict): A dictionary mapping document IDs to their URLs. text_color (str, optional): The color for the cited text. Default is "SkyBlue". link_color (str, optional): The color for the links. Default is "green". font_family (str, optional): The font family for the response text. Default is "Arial". line_height (str, optional): The line height for the response text. Default is "1.6". Returns:
A tuple containing: markdown_response (str): The response formatted as markdown. html_response (str): The response formatted as HTML. Markdown Formatting:
Cited Text: Cited text within the response is styled using tags with the specified text_color. Links: Links to the cited documents are created using tags with the specified link_color. Bullet Points: Bullet points are preserved by converting them to
tags.
Initiate Cohere Stream Chat with Web Connector
Try it out by running the cell below.
Streamed chat response: Photosynthesis is the process by which plants, algae, and some types of bacteria use sunlight, water, and carbon dioxide to create oxygen and energy in the form of sugar. During photosynthesis, plants take in carbon dioxide and water from the air and soil. Within the plant cell, the water is oxidised, meaning it loses electrons, while the carbon dioxide is reduced, meaning it gains electrons. This transforms the water into oxygen and the carbon dioxide into glucose. The plant then releases the oxygen back into the air and stores energy within the glucose molecules. The process can be broken down into two stages: light-dependent reactions and light-independent reactions. Light-dependent reactions take place within the thylakoid membrane and require a steady stream of sunlight. The light-independent stage, also known as the Calvin cycle, takes place in the stroma and does not require light.Markdown Response: