Spaces:
Sleeping
Sleeping
Update app.py
Browse files329 unmodified lines33033133233333433533633749 unmodified lines38738838939039139239339438 unmodified lines43343443543643743843926 unmodified lines4664674684694704714724734744754764774784797 unmodified lines4874884894904914924932 unmodified lines49649749849950050150250350450550650710 unmodified lines5185195205215225235245257 unmodified lines533534535536537538539329 unmodified linescompletion = client.chat.completions.create(model="gpt-3.5-turbo-0125",messages=[{"role": "system", "content": directions},{"role": "user", "content": prompt}])49 unmodified lines# Loop through each row of the DataFramefor index, row in df.iterrows():# Create a dictionary with the current question and answerqa_dict_quest = {"role": "user", "content": row["questions"]}qa_dict_ans = {"role": "assistant", "content": row["answers"]}# Add the dictionary to the result listresult.append(qa_dict_quest)38 unmodified lines)# Combine the random number and random string into one identifier.combined_string: str = f"{random_number}{random_string}"# Create a new collection in ChromeDB with the combined string as its name.collection = client.create_collection(combined_string)26 unmodified linescollection.add(ids=[str(i) for i in range(0, L)], # IDs are just stringsdocuments=dataset["train"]["questions"], # Enter questions heremetadatas=[{"type": "support"} for _ in range(0, L)],)if st.session_state.curr_domain != domain:st.session_state.messages = []init_message = init_messages[domain]st.session_state.messages.append({"role": "assistant", "content": init_message})st.session_state.curr_domain = domain7 unmodified lines# Display user message in chat message containerst.chat_message("user").markdown(prompt)# Add user message to chat historyst.session_state.messages.append({"role": "user", "content": prompt})question = prompt2 unmodified linesidx = results["ids"][0]idx = [int(i) for i in idx]ref = pd.DataFrame({"idx": idx,"questions": [dataset["train"]["questions"][i] for i in idx],"answers": [dataset["train"]["answers"][i] for i in idx],"distances": results["distances"][0],})# special_threshold = st.sidebar.slider('How old are you?', 0, 0.6, 0.1) # 0.3# special_threshold = 0.310 unmodified linesfinal_ref = refengineered_prompt = f'''Based on the context: {ref_from_db_search},answer the user question: {question}.'''directions = chatbot_instructions[domain]7 unmodified lineswith st.expander("See reference:"):st.table(final_ref)# Add assistant response to chat historyst.session_state.messages.append({"role": "assistant", "content": response})"""st.session_state.clear()329 unmodified lines33033133233333433533633749 unmodified lines38738838939039139239339438 unmodified lines43343443543643743843926 unmodified lines4664674684694704714724734744754764774784797 unmodified lines4874884894904914924932 unmodified lines49649749849950050150250350450550650710 unmodified lines5185195205215225235245257 unmodified lines533534535536537538539329 unmodified linescompletion = client.chat.completions.create(model="gpt-3.5-turbo-0125",messages=[{{"role": "system", "content": directions}},{{"role": "user", "content": prompt}}])49 unmodified lines# Loop through each row of the DataFramefor index, row in df.iterrows():# Create a dictionary with the current question and answerqa_dict_quest = {{"role": "user", "content": row["questions"]}}qa_dict_ans = {{"role": "assistant", "content": row["answers"]}}# Add the dictionary to the result listresult.append(qa_dict_quest)38 unmodified lines)# Combine the random number and random string into one identifier.combined_string: str = f"{{random_number}}{{random_string}}"# Create a new collection in ChromeDB with the combined string as its name.collection = client.create_collection(combined_string)26 unmodified linescollection.add(ids=[str(i) for i in range(0, L)], # IDs are just stringsdocuments=dataset["train"]["questions"], # Enter questions heremetadatas=[{{"type": "support"}} for _ in range(0, L)],)if st.session_state.curr_domain != domain:st.session_state.messages = []init_message = init_messages[domain]st.session_state.messages.append({{"role": "assistant", "content": init_message}})st.session_state.curr_domain = domain7 unmodified lines# Display user message in chat message containerst.chat_message("user").markdown(prompt)# Add user message to chat historyst.session_state.messages.append({{"role": "user", "content": prompt}})question = prompt2 unmodified linesidx = results["ids"][0]idx = [int(i) for i in idx]ref = pd.DataFrame({{"idx": idx,"questions": [dataset["train"]["questions"][i] for i in idx],"answers": [dataset["train"]["answers"][i] for i in idx],"distances": results["distances"][0],}})# special_threshold = st.sidebar.slider('How old are you?', 0, 0.6, 0.1) # 0.3# special_threshold = 0.310 unmodified linesfinal_ref = refengineered_prompt = f'''Based on the context: {{ref_from_db_search}},answer the user question: {{question}}.'''directions = chatbot_instructions[domain]7 unmodified lineswith st.expander("See reference:"):st.table(final_ref)# Add assistant response to chat historyst.session_state.messages.append({{"role": "assistant", "content": response}})"""st.session_state.clear()
app.py+13-13