KeshavRa commited on
Commit
05238dd
·
verified ·
1 Parent(s): 505ea14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -330,8 +330,8 @@ if selected_app == "4) Create Chatbot":
330
  completion = client.chat.completions.create(
331
  model="gpt-3.5-turbo-0125",
332
  messages=[
333
- {"role": "system", "content": directions},
334
- {"role": "user", "content": prompt}
335
  ]
336
  )
337
 
@@ -387,8 +387,8 @@ if selected_app == "4) Create Chatbot":
387
  # Loop through each row of the DataFrame
388
  for index, row in df.iterrows():
389
  # Create a dictionary with the current question and answer
390
- qa_dict_quest = {"role": "user", "content": row["questions"]}
391
- qa_dict_ans = {"role": "assistant", "content": row["answers"]}
392
 
393
  # Add the dictionary to the result list
394
  result.append(qa_dict_quest)
@@ -433,7 +433,7 @@ if selected_app == "4) Create Chatbot":
433
  )
434
 
435
  # Combine the random number and random string into one identifier.
436
- combined_string: str = f"{random_number}{random_string}"
437
 
438
  # Create a new collection in ChromeDB with the combined string as its name.
439
  collection = client.create_collection(combined_string)
@@ -466,14 +466,14 @@ if selected_app == "4) Create Chatbot":
466
  collection.add(
467
  ids=[str(i) for i in range(0, L)], # IDs are just strings
468
  documents=dataset["train"]["questions"], # Enter questions here
469
- metadatas=[{"type": "support"} for _ in range(0, L)],
470
  )
471
 
472
  if st.session_state.curr_domain != domain:
473
  st.session_state.messages = []
474
 
475
  init_message = init_messages[domain]
476
- st.session_state.messages.append({"role": "assistant", "content": init_message})
477
 
478
  st.session_state.curr_domain = domain
479
 
@@ -487,7 +487,7 @@ if selected_app == "4) Create Chatbot":
487
  # Display user message in chat message container
488
  st.chat_message("user").markdown(prompt)
489
  # Add user message to chat history
490
- st.session_state.messages.append({"role": "user", "content": prompt})
491
 
492
  question = prompt
493
 
@@ -496,12 +496,12 @@ if selected_app == "4) Create Chatbot":
496
  idx = results["ids"][0]
497
  idx = [int(i) for i in idx]
498
  ref = pd.DataFrame(
499
- {
500
  "idx": idx,
501
  "questions": [dataset["train"]["questions"][i] for i in idx],
502
  "answers": [dataset["train"]["answers"][i] for i in idx],
503
  "distances": results["distances"][0],
504
- }
505
  )
506
  # special_threshold = st.sidebar.slider('How old are you?', 0, 0.6, 0.1) # 0.3
507
  # special_threshold = 0.3
@@ -518,8 +518,8 @@ if selected_app == "4) Create Chatbot":
518
  final_ref = ref
519
 
520
  engineered_prompt = f'''
521
- Based on the context: {ref_from_db_search},
522
- answer the user question: {question}.
523
  '''
524
 
525
  directions = chatbot_instructions[domain]
@@ -533,7 +533,7 @@ if selected_app == "4) Create Chatbot":
533
  with st.expander("See reference:"):
534
  st.table(final_ref)
535
  # Add assistant response to chat history
536
- st.session_state.messages.append({"role": "assistant", "content": response})
537
  """
538
 
539
  st.session_state.clear()
 
330
  completion = client.chat.completions.create(
331
  model="gpt-3.5-turbo-0125",
332
  messages=[
333
+ {{"role": "system", "content": directions}},
334
+ {{"role": "user", "content": prompt}}
335
  ]
336
  )
337
 
 
387
  # Loop through each row of the DataFrame
388
  for index, row in df.iterrows():
389
  # Create a dictionary with the current question and answer
390
+ qa_dict_quest = {{"role": "user", "content": row["questions"]}}
391
+ qa_dict_ans = {{"role": "assistant", "content": row["answers"]}}
392
 
393
  # Add the dictionary to the result list
394
  result.append(qa_dict_quest)
 
433
  )
434
 
435
  # Combine the random number and random string into one identifier.
436
+ combined_string: str = f"{{random_number}}{{random_string}}"
437
 
438
  # Create a new collection in ChromeDB with the combined string as its name.
439
  collection = client.create_collection(combined_string)
 
466
  collection.add(
467
  ids=[str(i) for i in range(0, L)], # IDs are just strings
468
  documents=dataset["train"]["questions"], # Enter questions here
469
+ metadatas=[{{"type": "support"}} for _ in range(0, L)],
470
  )
471
 
472
  if st.session_state.curr_domain != domain:
473
  st.session_state.messages = []
474
 
475
  init_message = init_messages[domain]
476
+ st.session_state.messages.append({{"role": "assistant", "content": init_message}})
477
 
478
  st.session_state.curr_domain = domain
479
 
 
487
  # Display user message in chat message container
488
  st.chat_message("user").markdown(prompt)
489
  # Add user message to chat history
490
+ st.session_state.messages.append({{"role": "user", "content": prompt}})
491
 
492
  question = prompt
493
 
 
496
  idx = results["ids"][0]
497
  idx = [int(i) for i in idx]
498
  ref = pd.DataFrame(
499
+ {{
500
  "idx": idx,
501
  "questions": [dataset["train"]["questions"][i] for i in idx],
502
  "answers": [dataset["train"]["answers"][i] for i in idx],
503
  "distances": results["distances"][0],
504
+ }}
505
  )
506
  # special_threshold = st.sidebar.slider('How old are you?', 0, 0.6, 0.1) # 0.3
507
  # special_threshold = 0.3
 
518
  final_ref = ref
519
 
520
  engineered_prompt = f'''
521
+ Based on the context: {{ref_from_db_search}},
522
+ answer the user question: {{question}}.
523
  '''
524
 
525
  directions = chatbot_instructions[domain]
 
533
  with st.expander("See reference:"):
534
  st.table(final_ref)
535
  # Add assistant response to chat history
536
+ st.session_state.messages.append({{"role": "assistant", "content": response}})
537
  """
538
 
539
  st.session_state.clear()