|
import streamlit as st |
|
import pandas as pd |
|
from data_manager_bziiit import get_prompts |
|
from session import get_rag |
|
|
|
prompts = [] |
|
def get_prompts_list(): |
|
st.header("Prompts") |
|
prompts = get_prompts() |
|
|
|
|
|
if isinstance(prompts, list) and all(isinstance(i, dict) for i in prompts): |
|
|
|
df = pd.DataFrame(prompts) |
|
|
|
|
|
if 'name' in df.columns and 'context' in df.columns and 'text' in df.columns: |
|
|
|
df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x) |
|
|
|
|
|
df['text'] = df['text'].apply(lambda x: x[:50] + "..." if isinstance(x, str) else x) |
|
|
|
|
|
grouped = df.groupby('context') |
|
|
|
for name, group in grouped: |
|
st.subheader(name) |
|
for i, row in group.iterrows(): |
|
col1, col2, col3, col4 = st.columns((1, 2, 2, 1)) |
|
col1.write(i) |
|
col2.write(row['name']) |
|
col3.write(row['text']) |
|
button_phold = col4.empty() |
|
do_action = button_phold.button('Show More', key=i) |
|
if do_action: |
|
st.text(prompts[i]['text']) |
|
button_phold.empty() |
|
else: |
|
st.write("Data does not contain 'name', 'context', and 'text' fields.") |
|
else: |
|
st.write("Data is not in the expected format (list of dictionaries).") |
|
|
|
|
|
def prompt_execution(): |
|
prompts = get_prompts() |
|
|
|
selected_prompt = st.selectbox("Choisissez un prompt", prompts, format_func=lambda prompt: prompt['name']) |
|
if selected_prompt: |
|
return selected_prompt |
|
|
|
return None |
|
|
|
|
|
def execute_prompt(prompt): |
|
vectorstore, chain = get_rag() |
|
|
|
st.header(prompt['name']) |
|
st.text(prompt['text']) |
|
|
|
if vectorstore and chain: |
|
st.success("Vectorestore et chain trouvés") |
|
|
|
if st.button("Exécuter le prompt"): |
|
with st.spinner("Processing..."): |
|
ambition = chain.invoke(prompt['text']) |
|
st.markdown("### Réponse :") |
|
st.markdown(ambition.content) |
|
|