Spaces:
Sleeping
Sleeping
Update app.py
Browse files329 unmodified lines33033133233333433333433533633749 unmodified lines38738838939039139039139239339438 unmodified lines43343443543643643743843926 unmodified lines4664674684694694704714724734744754764764774784797 unmodified lines4874884894904904914924932 unmodified lines49649749849949950050150250350450450550650710 unmodified lines5185195205215225215225235245257 unmodified lines533534535536536537538539329 unmodified lines completion = client.chat.completions.create( model="gpt-3.5-turbo-0125", messages=[ {"role": "system", "content": directions}, {"role": "user", "content": prompt} {{"role": "system", "content": directions}}, {{"role": "user", "content": prompt}} ] ) 49 unmodified lines # Loop through each row of the DataFrame for index, row in df.iterrows(): # Create a dictionary with the current question and answer qa_dict_quest = {"role": "user", "content": row["questions"]} qa_dict_ans = {"role": "assistant", "content": row["answers"]} qa_dict_quest = {{"role": "user", "content": row["questions"]}} qa_dict_ans = {{"role": "assistant", "content": row["answers"]}} # Add the dictionary to the result list result.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}" 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 lines collection.add( ids=[str(i) for i in range(0, L)], # IDs are just strings documents=dataset["train"]["questions"], # Enter questions here metadatas=[{"type": "support"} for _ in range(0, L)], metadatas=[{{"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.messages.append({{"role": "assistant", "content": init_message}}) st.session_state.curr_domain = domain 7 unmodified lines # Display user message in chat message container st.chat_message("user").markdown(prompt) # Add user message to chat history st.session_state.messages.append({"role": "user", "content": prompt}) st.session_state.messages.append({{"role": "user", "content": prompt}}) question = prompt 2 unmodified lines idx = 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 lines final_ref = ref engineered_prompt = f''' Based on the context: {ref_from_db_search}, answer the user question: {question}. Based on the context: {{ref_from_db_search}}, answer the user question: {{question}}. ''' directions = chatbot_instructions[domain]7 unmodified lines with st.expander("See reference:"): st.table(final_ref) # Add assistant response to chat history st.session_state.messages.append({"role": "assistant", "content": response}) st.session_state.messages.append({{"role": "assistant", "content": response}}) """ st.session_state.clear()app.py+13-13