Spaces:
Running
Running
geekyrakshit
commited on
Commit
·
b20052a
1
Parent(s):
b850722
add: weave link to response
Browse files
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
st.
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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})
|