Skip to content

Commit

Permalink
add: Display rendered System and User prompts
Browse files Browse the repository at this point in the history
* Ensure that when jinja2 is used, the rendered versions of the System
  and User prompts are also shown in the UI.

Signed-off-by: mrshu <[email protected]>
  • Loading branch information
mrshu committed Feb 27, 2024
1 parent 280406f commit 8d4771e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions prompterator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _get_coloured_patch(patch):
)


def set_up_prompt_attrs_area(st_container):
def set_up_prompt_attrs_area(st_container, st):
env = u.jinja_env()
parsed_content = env.parse(st.session_state.system_prompt)
vars = meta.find_undeclared_variables(parsed_content)
Expand All @@ -470,6 +470,26 @@ def set_up_prompt_attrs_area(st_container):
height=c.DATA_POINT_TEXT_AREA_HEIGHT,
)

system_prompt = env.from_string(st.session_state.system_prompt).render(**st.session_state.row.to_dict())
user_prompt = env.from_string(st.session_state.user_prompt).render(**st.session_state.row.to_dict())
# Show the rendered System and User prompts
col1, col2 = st.columns([1, 1])
col1.text_area(
label=f"Rendered system prompt",
key="system_prompt_jinja2",
value=system_prompt,
disabled=True,
height=c.DATA_POINT_TEXT_AREA_HEIGHT,
)

col2.text_area(
label=f"Rendered user prompt",
key="user_prompt_jinja2",
value=user_prompt,
disabled=True,
height=c.DATA_POINT_TEXT_AREA_HEIGHT,
)


def display_image(st_container, base64_str):
st_container.markdown(
Expand All @@ -489,7 +509,7 @@ def set_up_ui_labelling():
disabled=True,
height=c.DATA_POINT_TEXT_AREA_HEIGHT,
)
set_up_prompt_attrs_area(col2_orig)
set_up_prompt_attrs_area(col2_orig, st)

if "image" in st.session_state.row:
display_image(col2_orig, st.session_state.row["image"])
Expand Down

0 comments on commit 8d4771e

Please sign in to comment.