import gradio as gr from langchain import PromptTemplate, LLMChain from langchain.llms import CTransformers def generate_prompts(user_input): prompt_template = PromptTemplate( input_variables=["Question"], template=f"Just list 10 quetion prompts for {user_input} and don't put number before each of the prompts." ) config = {'max_new_tokens': 2048, 'temperature': 0.7, 'context_length': 4096} llm = CTransformers(model="TheBloke/Mistral-7B-Instruct-v0.1-GGUF", config=config, threads=os.cpu_count()) hub_chain = LLMChain(prompt = prompt_template, llm = llm) input_data = {"Question": user_input} generated_prompts = hub_chain.run(input_data) questions_list = generated_prompts.split('\n') formatted_questions = "\n".join(f"Question: {question}" for i, question in enumerate(questions_list) if question.strip()) questions_list = formatted_questions.split("Question:")[1:] return questions_list def answer_question(prompt): prompt_template = PromptTemplate( input_variables=["Question"], template=f"give one answer for {prompt} and do not consider the number behind it." ) config = {'max_new_tokens': 2048, 'temperature': 0.7, 'context_length': 4096} llm = CTransformers(model="TheBloke/Llama-2-7B-Chat-GGML", config=config, threads=os.cpu_count()) hub_chain = LLMChain(prompt = prompt_template, llm = llm) input_data = {"Question": prompt} generated_answer = hub_chain.run(input_data) return generated_answer text_list = [] def updateChoices(prompt): newChoices = generate_prompts(prompt) return gr.CheckboxGroup(choices=newChoices) def setTextVisibility(cbg, model_name_input): sentences = [] result = [] model = SentenceTransformer('all-mpnet-base-v2') exclude_words = {"a", "the", "for", "from", "of", "in", "over", "as", "on", "is", "am", "have", "an", "has", "had", "and", "by", "it", "its", "those", "these", "above", "to"} sentences_org = ["In a quaint little town nestled in the heart of the mountains, a small bakery famous for its artisanal breads and pastries had a line of customers stretching out the door, eagerly waiting to savor the freshly baked goods that were known far and wide for their delightful flavors.", "Within a picturesque mountain village, there stood a renowned bakery, celebrated for its handcrafted bread and sweet treats, attracting a long queue of patrons each morning, all keen to enjoy the baked delicacies that had gained widespread acclaim for their exceptional taste.", "A charming bakery, located in a small mountainous hamlet, renowned for producing exquisite handmade pastries and bread, was bustling with a crowd of eager customers lined up outside, each anticipating the chance to indulge in the famous baked items celebrated for their extraordinary deliciousness.", "In a cozy, mountain-encircled village, a beloved bakery was the center of attraction, known for its traditional baking methods and delightful pastries, drawing a consistent stream of people waiting outside, all desiring to experience the renowned flavors that made the bakery's products distinctively mouth-watering."] for text in cbg: sentences.append(answer_question(text, model_name_input)) # Step 1: Cluster the sentences num_clusters = 1 sentence_clusters = cluster_sentences(sentences, model, num_clusters) # Step 2: Highlight similar words within each cluster clustered_sentences = [[] for _ in range(num_clusters)] for sentence, cluster_id in zip(sentences, sentence_clusters): clustered_sentences[cluster_id].append(sentence) highlighted_clustered_sentences = [] for cluster in clustered_sentences: highlighted_clustered_sentences.extend(highlight_words_within_cluster(cluster, model, exclude_words)) for idx, sentence in enumerate(highlighted_sentences): result.append("
"+ cbg[idx] +"
"+ sentence +"
First, select the LLM you wish to audit. Then, enter your question. The AuditLLM tool will generate five relevant and diverse prompts based on your question. You can now select these prompts for auditing the LLMs. Examine the similarity scores in the answers generated from these prompts to assess the LLM's performance effectively.
In batch auditing mode, you have the capability to probe the LLM. To begin, you must first select the LLM you wish to audit and then input the questions you intend to explore. For each question submitted, the model will generate five prompts, each accompanied by its respective answers.
To tailor the generation of these five prompts from your original question, you can adjust the relevance and diversity scores. The relevance score determines how closely the generated prompts should align with the original question, while the diversity score dictates the variance among the prompts themselves.
Upon completion, please provide your email address. We will compile and send the answers to you promptly.