I am creating an gen ai based solution and I wnat to do proper prompting so that results…
- User
I am creating an gen ai based solution and I wnat to do proper prompting so that results will be good.:
- Assistant
- User
def get_most_similar_question(userText, history): print(userText)
inp_emb = retrieval_model.encode([userText]) corr = np.inner(inp_emb, data_emb) flat_list = [item for sublist in corr for item in sublist] top_20_idx = np.argsort(flat_list)[-5:] print('idx',top_20_idx) top_20_values = [flat_list[i] for i in top_20_idx] print('values',top_20_values) # Get the questions/texts that correspond to these top 20 indices. top_20_texts = new_df.iloc[top_20_idx, 1].values # Assuming column 1 holds the texts/questions. print(top_20_texts) # Re-encode these top 20 texts. data_emb_1 = new_retrieval_model(top_20_texts) # Calculate their similarity to the input text again. inp_emb_1 = new_retrieval_model([userText]) corr_1 = np.inner(inp_emb_1, data_emb_1) print('corr_1',corr_1) # This time corr is 2D but we expect a single list since inp_emb is a single list. flat_list_1 = [item for sublist in corr_1 for item in sublist] print('flat_list_1',flat_list_1) # Find the highest similarity score and its index. top_1_idx = np.argsort(flat_list_1)[-1:] print('top_1_idx',top_1_idx) top_1_value = flat_list_1[top_1_idx] print('top_1_value',top_1_value) top_1_texts = new_df.iloc[top_1_idx, 1].values print('top_1_texts',top_1_texts) - Assistant
- User
Decision to call predict or return the highest ranked text based on similarity threshold
if top_5_values[0] < 0.7: # Placeholder for the 'predict' function, assuming you have it defined elsewhere to handle insufficient similarity scenarios return predict(userText, history) else: # Crafting a DataFrame to convert to HTML, using top_1_idx to find original index in new_df most_similar_data = new_df.iloc[top_5_idx, [1]] # Adjusted for Python's indexing most_similar_data_df = pd.DataFrame(most_similar_data) df_html_with_sql = most_similar_data_df.to_html(index=False) return df_html_with_sqlI want to output with a text heading like 'Here is the top matching results for your query' with the existing ouput
- Assistant
To add a textual heading to your output HTML that reads "Here is the top matching results for your query," you can simply prepend this heading to your DataFrame's HTML representation. Here's the adjusted code snippet that appends the heading to the returned HTML:
# Decision to call predict or return the highest ranked text based on similarity threshold if top_5_values[0] < 0.7: # Placeholder for the 'predict' function, assuming you have it defined elsewhere to handle insufficient similarity scenarios return predict(userText, history) else: # Crafting a DataFrame to convert to HTML, using top_5_idx to find original index in new_df most_similar_data = new_df.iloc[top_5_idx, [1]] # Adjusted for Python's indexing most_similar_data_df = pd.DataFrame(most_similar_data) # Convert the DataFrame to HTML df_html = most_similar_data_df.to_html(index=False) # Prepend the heading to the HTML representation html_output = f"<h3>Here is the top matching result(s) for your query:</h3>{df_html}" return html_output
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.