@@ -56,34 +56,62 @@ The code for these apps can be viewed in the [trubrics-sdk](https://github.com/t
5656 ```
5757
5858## Add the FeedbackCollector to your App
59- To get started with the bare bones code , you can add this code snippet directly to your streamlit app:
59+ To get started, you can add this code snippet directly to your streamlit app:
6060``` py
6161import streamlit as st
6262from trubrics.integrations.streamlit import FeedbackCollector
6363
64+ if " logged_prompt" not in st.session_state:
65+ st.session_state.logged_prompt = None
66+
67+ # 1. authenticate with trubrics
6468collector = FeedbackCollector(
65- component_name = " default " ,
66- email = st.secrets[ " TRUBRICS_EMAIL " ], # Store your Trubrics credentials in st.secrets:
67- password = st.secrets[ " TRUBRICS_PASSWORD " ], # https://blog.streamlit.io/secrets-in-sharing-apps/
69+ email = st.secrets. TRUBRICS_EMAIL ,
70+ password = st.secrets. TRUBRICS_PASSWORD ,
71+ project = " default "
6872)
6973
70- collector.st_feedback(
71- feedback_type = " thumbs" ,
72- model = " your_model_name" ,
73- open_feedback_label = " [Optional] Provide additional feedback" ,
74- )
74+ if st.button(" Predict" ):
75+ # 2. log a user prompt & model response
76+ st.session_state.logged_prompt = collector.log_prompt(
77+ config_model = {" model" : " gpt-3.5-turbo" },
78+ prompt = " Tell me a joke" ,
79+ generation = " Why did the chicken cross the road? To get to the other side." ,
80+ )
81+
82+ if st.session_state.logged_prompt:
83+ st.write(" A model generation..." )
84+
85+ # 3. log some user feedback
86+ user_feedback = collector.st_feedback(
87+ component = " default" ,
88+ feedback_type = " thumbs" ,
89+ open_feedback_label = " [Optional] Provide additional feedback" ,
90+ model = st.session_state.logged_prompt.config_model.model,
91+ prompt_id = st.session_state.logged_prompt.id,
92+ align = " flex-start" ,
93+ single_submit = False
94+ )
7595```
7696
7797What's going on here? Let's break down this snippet:
7898
79- 1 . The FeedbackCollector holds Trubrics account information
99+ 1 . ` collector = FeedbackCollector() ` allows you to authenticate with Trubrics
100+
101+ !!!tip
102+ The authentication token is cached already, but to optimise your app further, wrap the ` FeedbackCollector ` in [ @st .cache_data] ( https://docs.streamlit.io/library/api-reference/performance/st.cache_data ) .
80103
81- !!!tip "FeedbackCollector object"
104+ !!!note "FeedbackCollector object"
82105 :::trubrics.integrations.streamlit.FeedbackCollector.__ init__
83106
84- 2 . Its st_feeedback() method allows users to embed UI widgets in their apps
107+ 2 . ` collector.log_prompt() ` allows you to log all user prompts and model generations
108+
109+ !!!note ".log_prompt() parameters"
110+ :::trubrics.Trubrics.log_prompt
111+
112+ 3 . ` collector.log_feedback() ` allows users to embed UI widgets to collect feedback from users
85113
86- !!!tip ".st_feedback() parameters"
114+ !!!note ".st_feedback() parameters"
87115 :::trubrics.integrations.streamlit.FeedbackCollector.st_feedback
88116
89117!!!Note
0 commit comments