Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating Trubrics SDK for Feedback Collection and Analysis in KnowledgeGPT #51

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions knowledge_gpt/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import streamlit as st
from trubrics.integrations.streamlit import FeedbackCollector


from knowledge_gpt.components.sidebar import sidebar

Expand Down Expand Up @@ -27,12 +29,17 @@
st.set_page_config(page_title="KnowledgeGPT", page_icon="📖", layout="wide")
st.header("📖KnowledgeGPT")

if "submit" not in st.session_state:
st.session_state["submit"] = False

# Enable caching for expensive functions
bootstrap_caching()

sidebar()

openai_api_key = st.session_state.get("OPENAI_API_KEY")
email = st.secrets.get("TRUBRICS_EMAIL")
password = st.secrets.get("TRUBRICS_PASSWORD")


if not openai_api_key:
Expand Down Expand Up @@ -77,6 +84,9 @@
query = st.text_area("Ask a question about the document")
submit = st.form_submit_button("Submit")

if submit:
st.session_state["submit"] = True


with st.expander("Advanced Options"):
return_all_chunks = st.checkbox("Show all chunks retrieved from vector search")
Expand All @@ -89,13 +99,12 @@
st.markdown(f"<p>{wrap_doc_in_html(file.docs)}</p>", unsafe_allow_html=True)


if submit:
if st.session_state["submit"]:
if not is_query_valid(query):
st.stop()

# Output Columns
answer_col, sources_col = st.columns(2)

result = query_folder(
folder_index=folder_index,
query=query,
Expand All @@ -109,9 +118,33 @@
st.markdown("#### Answer")
st.markdown(result.answer)

collector = FeedbackCollector(
component_name="default",
email=email,
password=password,
)

feedback_result = collector.st_feedback(
feedback_type="thumbs",
model=MODEL,
open_feedback_label="[Optional] Provide additional feedback",
key="key_result",
metadata={"response": result.answer, "prompt": query},
tags=["answer"],
)

with sources_col:
st.markdown("#### Sources")
for source in result.sources:
st.markdown(source.page_content)
st.markdown(source.metadata["source"])
st.markdown("---")

feedback_source = collector.st_feedback(
feedback_type="thumbs",
model=MODEL,
open_feedback_label="[Optional] Provide additional feedback",
key="key_source",
metadata={"response": source.metadata["source"], "prompt": query},
tags=["source"],
)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ docx2txt = "^0.8"
pillow = "^9.4.0"
tenacity = "^8.2.0"
tiktoken = "^0.4.0"
trubrics = "^1.4.3"
pycryptodome = "^3.18.0"
pymupdf = "^1.22.5"

Expand Down