geekyrakshit commited on
Commit
b20052a
·
1 Parent(s): b850722

add: weave link to response

Browse files
Files changed (1) hide show
  1. app.py +36 -27
app.py CHANGED
@@ -7,30 +7,39 @@ from guardrails_genie.llm import OpenAIModel
7
  load_dotenv()
8
  weave.init(project_name="guardrails-genie")
9
 
10
- st.title("Echo Bot")
11
-
12
- # Initialize chat history
13
- if "messages" not in st.session_state:
14
- st.session_state.messages = []
15
-
16
- llm_model = OpenAIModel(model_name="gpt-4o-mini")
17
-
18
- # Display chat messages from history on app rerun
19
- for message in st.session_state.messages:
20
- with st.chat_message(message["role"]):
21
- st.markdown(message["content"])
22
-
23
- # React to user input
24
- if prompt := st.chat_input("What is up?"):
25
- # Display user message in chat message container
26
- st.chat_message("user").markdown(prompt)
27
- # Add user message to chat history
28
- st.session_state.messages.append({"role": "user", "content": prompt})
29
-
30
- response = llm_model.predict(prompt, messages=st.session_state.messages)
31
- response = response.choices[0].message.content
32
- # Display assistant response in chat message container
33
- with st.chat_message("assistant"):
34
- st.markdown(response)
35
- # Add assistant response to chat history
36
- st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
 
 
 
 
 
 
 
7
  load_dotenv()
8
  weave.init(project_name="guardrails-genie")
9
 
10
+
11
+ openai_model = st.sidebar.selectbox("OpenAI LLM", ["", "gpt-4o-mini", "gpt-4o"])
12
+ chat_condition = openai_model != ""
13
+
14
+
15
+ if chat_condition:
16
+ st.title("Guardrails Genie")
17
+
18
+ # Initialize chat history
19
+ if "messages" not in st.session_state:
20
+ st.session_state.messages = []
21
+
22
+ llm_model = OpenAIModel(model_name="gpt-4o-mini")
23
+
24
+ # Display chat messages from history on app rerun
25
+ for message in st.session_state.messages:
26
+ with st.chat_message(message["role"]):
27
+ st.markdown(message["content"])
28
+
29
+ # React to user input
30
+ if prompt := st.chat_input("What is up?"):
31
+ # Display user message in chat message container
32
+ st.chat_message("user").markdown(prompt)
33
+ # Add user message to chat history
34
+ st.session_state.messages.append({"role": "user", "content": prompt})
35
+
36
+ response, call = llm_model.predict.call(
37
+ llm_model, user_prompts=prompt, messages=st.session_state.messages
38
+ )
39
+ response = response.choices[0].message.content
40
+ response += f"\n\n---\n[Explore in Weave]({call.ui_url})"
41
+ # Display assistant response in chat message container
42
+ with st.chat_message("assistant"):
43
+ st.markdown(response)
44
+ # Add assistant response to chat history
45
+ st.session_state.messages.append({"role": "assistant", "content": response})