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() # Check if prompts is a list of dictionaries if isinstance(prompts, list) and all(isinstance(i, dict) for i in prompts): # Create a DataFrame df = pd.DataFrame(prompts) # Check if 'name', 'context', and 'text' are in df columns if 'name' in df.columns and 'context' in df.columns and 'text' in df.columns: # Extract 'name' from 'context' dictionary df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x) # Get first 50 characters from 'text' and add "..." at the end df['text'] = df['text'].apply(lambda x: x[:50] + "..." if isinstance(x, str) else x) # Group by 'context' grouped = df.groupby('context') for name, group in grouped: st.subheader(name) # Display the context name as a subheader for i, row in group.iterrows(): col1, col2, col3, col4 = st.columns((1, 2, 2, 1)) col1.write(i) # index col2.write(row['name']) # name col3.write(row['text']) # text button_phold = col4.empty() # create a placeholder do_action = button_phold.button('Show More', key=i) if do_action: st.text(prompts[i]['text']) # Display the full text button_phold.empty() # remove button 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)