File size: 1,659 Bytes
ac2020e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Display components for LegisQA"""

import streamlit as st
from legisqa_local.utils.text import escape_markdown, replace_legis_ids_with_urls
from legisqa_local.utils.usage import display_api_usage
from legisqa_local.utils.formatting import render_retrieved_chunks
from legisqa_local.config.models import PROVIDER_MODELS


def render_example_queries():
    """Render example queries in an expander"""
    with st.expander("Example Queries"):
        st.write(
            """

```
What are the themes around artificial intelligence?
```

```
Write a well cited 3 paragraph essay on food insecurity.
```

```
Create a table summarizing major climate change ideas with columns legis_id, title, idea.
```

```
Write an action plan to keep social security solvent.
```

```
Suggest reforms that would benefit the Medicaid program.
```

        """
        )


def render_response(
    response: dict,
    model_info: dict,
    provider: str,
    should_escape_markdown: bool,
    should_add_legis_urls: bool,
    tag: str | None = None,
):
    """Render a RAG response with usage information and retrieved chunks"""
    response_text = response["aimessage"].content
    if should_escape_markdown:
        response_text = escape_markdown(response_text)
    if should_add_legis_urls:
        response_text = replace_legis_ids_with_urls(response_text)

    with st.container(border=True):
        if tag is None:
            st.write("Response")
        else:
            st.write(f"Response ({tag})")
        st.info(response_text)

    display_api_usage(response["aimessage"], model_info, provider, tag=tag)
    render_retrieved_chunks(response["docs"], tag=tag)