o
    /ifz                     @   s0  d dl mZ d dlmZmZ d dlmZ edddddd	d
ddd	gddgddddZeddddddddddddgg dddddZedd d!d"d#d	d$d%d&d	gddgddddZ	ed'd(d)d*d+d,d-d+gdgddddZ
ed.d/d0d1d2d3d+gdgdd4ddZed5d6d7d8d9d:d;d<d=d>d?d:d;d<d@dAdBdCd;d<gddgdDd4ddZedEdFdGdHg dIidJdKdHg dLidJgdMgdd4dNZedOdPdQdRdSdTdUdVdWdTdXdYdZdTgdd[gdddNZed\d]d^d_d`dagidJdbd_dcddgidJgdMgdd4dNZededfdg dgdhdidjgidkdlg dmdhdidjgidkgddngdd4ddZedodpdqdrdsdtdudvdwdxdydugg dzddddZG d{d| d|eZG d}d~ d~eZG dd deZeedZeedZeedZeddeededdiddd ddeddjddd ddedjdididid dgdgdd4ddZeddeededdd d+deddd d+dedd d d+deddid d+dedd d d+gdgdd4ddZeddeeddedd d dddeddid dddeddid dgddgdd4ddZdS )    )	BaseModel)RagasoutputParserget_json_format_instructions)Promptreasoning_questiona  Complicate the given question by rewriting question into a multi-hop reasoning question based on the provided context.
    Answering the question should require the reader to make multiple logical connections or inferences using the information available in given context.
    Rules to follow when rewriting question:
    1. Ensure that the rewritten question can be answered entirely from the information present in the contexts.
    2. Do not frame questions that contains more than 15 words. Use abbreviation wherever possible.
    3. Make sure the question is clear and unambiguous.
    4. phrases like 'based on the provided context','according to the context',etc are not allowed to appear in the question.zWhat is the capital of France?zFrance is a country in Western Europe. It has several cities, including Paris, Lyon, and Marseille. Paris is not only known for its cultural landmarks like the Eiffel Tower and the Louvre Museum but also as the administrative center.zNLinking the Eiffel Tower and administrative center, which city stands as both?)questioncontextoutputz+What does the append() method do in Python?zIn Python, lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types used to store collections of data. The append() method adds a single item to the end of a list.zOIf a list represents a variable collection, what method extends it by one item?r   r   r	   strenglish)nameinstructionexamples
input_keys
output_keyoutput_typelanguagemulti_context_questiona  
    The task is to rewrite and complicate the given question in a way that answering it requires information derived from both context1 and context2. 
    Follow the rules given below while rewriting the question.
        1. The rewritten question should not be very long. Use abbreviation wherever possible.
        2. The rewritten question must be reasonable and must be understood and responded by humans.
        3. The rewritten question must be fully answerable from information present in context1 and context2. 
        4. Read and understand both contexts and rewrite the question so that answering requires insight from both context1 and context2.
        5. phrases like 'based on the provided context','according to the context?',etc are not allowed to appear in the question.z What process turns plants green?z^Chlorophyll is the pigment that gives plants their green color and helps them photosynthesize.z\Photosynthesis in plants typically occurs in the leaves where chloroplasts are concentrated.zgIn which plant structures does the pigment responsible for their verdancy facilitate energy production?)r   context1context2r	   z-How do you calculate the area of a rectangle?zThe area of a shape is calculated based on the shape's dimensions. For rectangles, this involves multiplying the length and width.zgRectangles have four sides with opposite sides being equal in length. They are a type of quadrilateral.zLWhat multiplication involving equal opposites yields a quadrilateral's area?)r   r   r   conditional_questiona  Rewrite the provided question to increase its complexity by introducing a conditional element.
    The goal is to make the question more intricate by incorporating a scenario or condition that affects the context of the question.
    Follow the rules given below while rewriting the question.
        1. The rewritten question should not be longer than 25 words. Use abbreviation wherever possible.
        2. The rewritten question must be reasonable and must be understood and responded by humans.
        3. The rewritten question must be fully answerable from information present context.
        4. phrases like 'provided context','according to the context?',etc are not allowed to appear in the question.z-What is the function of the roots of a plant?znThe roots of a plant absorb water and nutrients from the soil, anchor the plant in the ground, and store food.zOWhat dual purpose do plant roots serve concerning soil nutrients and stability?z)How do vaccines protect against diseases?zVaccines protect against diseases by stimulating the body's immune response to produce antibodies, which recognize and combat pathogens.zMHow do vaccines utilize the body's immune system to defend against pathogens?compress_questiona&  Rewrite the following question to make it more indirect and shorter while retaining the essence of the original question.
    The goal is to create a question that conveys the same meaning but in a less direct manner. The rewritten question should shorter so use abbreviation wherever possible.z4What is the distance between the Earth and the Moon?zHow far is the Moon from Earth?)r   r	   z7What ingredients are required to bake a chocolate cake?z#What's needed for a chocolate cake?conversation_questiona  Reformat the provided question into two separate questions as if it were to be part of a conversation. Each question should focus on a specific aspect or subtopic related to the original question.
    Follow the rules given below while rewriting the question.
        1. The rewritten question should not be longer than 25 words. Use abbreviation wherever possible.
        2. The rewritten question must be reasonable and must be understood and responded by humans.
        3. The rewritten question must be fully answerable from information present context.
        4. phrases like 'provided context','according to the context?',etc are not allowed to appear in the question.z9What are the advantages and disadvantages of remote work?z%What are the benefits of remote work?zHOn the flip side, what challenges are encountered when working remotely?)first_questionsecond_questionjsonanswer_formulatezAnswer the question using the information from the given context. Output verdict as '1' if answer is present '-1' if answer is not present in the context.a  Climate change is significantly influenced by human activities, notably the emission of greenhouse gases from burning fossil fuels. The increased greenhouse gas concentration in the atmosphere traps more heat, leading to global warming and changes in weather patterns.z5How do human activities contribute to climate change?a  Human activities contribute to climate change primarily through the emission of greenhouse gases from burning fossil fuels. These emissions increase the concentration of greenhouse gases in the atmosphere, which traps more heat and leads to global warming and altered weather patterns.1)answerverdict)r   r   r   a.  The concept of artificial intelligence (AI) has evolved over time, but it fundamentally refers to machines designed to mimic human cognitive functions. AI can learn, reason, perceive, and, in some instances, react like humans, making it pivotal in fields ranging from healthcare to autonomous vehicles.z9What are the key capabilities of artificial intelligence?a*  Artificial intelligence is designed to mimic human cognitive functions, with key capabilities including learning, reasoning, perception, and reacting to the environment in a manner similar to humans. These capabilities make AI pivotal in various fields, including healthcare and autonomous driving.zThe novel "Pride and Prejudice" by Jane Austen revolves around the character Elizabeth Bennet and her family. The story is set in the 19th century in rural England and deals with issues of marriage, morality, and misconceptions.z.What year was 'Pride and Prejudice' published?z6The answer to given question is not present in contextz-1r   keyphrase_extractionztExtract the top 3 to 5 keyphrases from the provided text, focusing on the most significant and distinctive aspects. a  A black hole is a region of spacetime where gravity is so strong that nothing, including light and other electromagnetic waves, has enough energy to escape it. The theory of general relativity predicts that a sufficiently compact mass can deform spacetime to form a black hole.
keyphrases)z
Black holezRegion of spacetimezStrong gravityzLight and electromagnetic waveszTheory of general relativity)textr	   zThe Great Wall of China is an ancient series of walls and fortifications located in northern China, built around 500 years ago. This immense wall stretches over 13,000 miles and is a testament to the skill and persistence of ancient Chinese engineers.)zGreat Wall of ChinazAncient fortificationszNorthern Chinar"   )r   r   r   r   r   r   seed_questionzlGenerate a question that can be fully answered from given context. The question should be formed using topiczPhotosynthesis in plants involves converting light energy into chemical energy, using chlorophyll and other pigments to absorb light. This process is crucial for plant growth and the production of oxygen.Photosynthesisz3What is the role of photosynthesis in plant growth?)r   	keyphraser   zThe Industrial Revolution, starting in the 18th century, marked a major turning point in history as it led to the development of factories and urbanization.zIndustrial RevolutionzHHow did the Industrial Revolution mark a major turning point in history?zThe process of evaporation plays a crucial role in the water cycle, converting water from liquid to vapor and allowing it to rise into the atmosphere.Evaporationz0Why is evaporation important in the water cycle?r%   main_topic_extractionzNIdentify and extract the two main topics discussed in depth in the given text.a  Blockchain technology presents a decentralized ledger that ensures the integrity and transparency of data transactions. It underpins cryptocurrencies like Bitcoin, providing a secure and immutable record of all transactions. Beyond finance, blockchain has potential applications in supply chain management, where it can streamline operations, enhance traceability, and improve fraud prevention. It allows for real-time tracking of goods and transparent sharing of data among participants.topicszCBlockchain technology and its foundational role in cryptocurrenciesz5Applications of blockchain in supply chain managementa  Telemedicine has revolutionized the way healthcare is delivered, particularly in rural and underserved areas. It allows patients to consult with doctors via video conferencing, improving access to care and reducing the need for travel. Another significant advancement in healthcare is precision medicine, which tailors treatments to individual genetic profiles. This approach has led to more effective therapies for a variety of conditions, including certain cancers and chronic diseases.z7Telemedicine and its impact on healthcare accessibilityzKPrecision medicine and its role in tailoring treatments to genetic profilesfind_relevant_contextz]Given a question and set of contexts, find the most relevant contexts to answer the question.)z1. France is a country in Western Europe. It has several cities, including Paris, Lyon, and Marseille. Paris is not only known for its cultural landmarks like the Eiffel Tower and the Louvre Museum but also as the administrative center.z2. The capital of France is Paris. It is also the most populous city in France, with a population of over 2 million people. Paris is known for its cultural landmarks like the Eiffel Tower and the Louvre Museum.z3. Paris is the capital of France. It is also the most populous city in France, with a population of over 2 million people. Paris is known for its cultural landmarks like the Eiffel Tower and the Louvre Museum.relevant_contexts      )r   contextsr	   zBHow does caffeine affect the body and what are its common sources?)z1. Caffeine is a central nervous system stimulant. It can temporarily ward off drowsiness and restore alertness. It primarily affects the brain, where it alters the function of neurotransmitters.z2. Regular physical activity is essential for maintaining good health. It can help control weight, combat health conditions, boost energy, and promote better sleep.z3. Common sources of caffeine include coffee, tea, cola, and energy drinks. These beverages are consumed worldwide and are known for providing a quick boost of energy.r-   rewrite_questionzGiven a context, question and feedback, rewrite the question to improve its clarity and answerability based on the feedback provided.a  The Eiffel Tower was constructed using iron and was originally intended as a temporary exhibit for the 1889 World's Fair held in Paris. Despite its initial temporary purpose, the Eiffel Tower quickly became a symbol of Parisian ingenuity and an iconic landmark of the city, attracting millions of visitors each year. The tower's design, created by Gustave Eiffel, was initially met with criticism from some French artists and intellectuals, but it has since been celebrated as a masterpiece of structural engineering and architectural design.z%Who created the design for the Tower?aU  The question asks about the creator of the design for 'the Tower', but it does not specify which tower it refers to. There are many towers worldwide, and without specifying the exact tower, the question is unclear and unanswerable. To improve the question, it should include the name or a clear description of the specific tower in question.z,Who created the design for the Eiffel Tower?)r   r   feedbackr	   z'Exploring Zero-Shot Learning in Neural Networks' was published by Smith and Lee in 2021, focusing on the application of zero-shot learning techniques in artificial intelligence.zDWhat datasets were used for the zero-shot evaluations in this study?a  The question asks about the datasets used for zero-shot evaluations in 'this study', without specifying or providing any details about the study in question. This makes the question unclear for those who do not have access to or knowledge of the specific study. To improve clarity and answerability, the question should specify the study it refers to, or provide enough context about the study for the question to be understood and answered independently.zlWhat datasets were used for the zero-shot evaluations Exploring Zero-Shot Learning in Neural Networks paper?)r   r   r/   c                   @   s.   e Zd ZU eed< eed< eed< eed< dS )ContextScoringclaritydepth	structure	relevanceN)__name__
__module____qualname__int__annotations__ r:   r:   N/var/www/html/corbot_env/lib/python3.10/site-packages/ragas/testset/prompts.pyr0   =  s
   
 r0   c                   @      e Zd ZU eed< eed< dS )QuestionFilterr/   r   Nr5   r6   r7   r
   r9   r8   r:   r:   r:   r;   r=   D     
 r=   c                   @   r<   )EvolutionEliminationreasonr   Nr>   r:   r:   r:   r;   r@   I  r?   r@   )pydantic_objectscore_contextaV  
    Given a context, perform the following task and output the answer in VALID JSON format: Assess the provided context and assign a numerical score of 1 (Low), 2 (Medium), or 3 (High) for each of the following criteria in your JSON response:

clarity: Evaluate the precision and understandability of the information presented. High scores (3) are reserved for contexts that are both precise in their information and easy to understand. Low scores (1) are for contexts where the information is vague or hard to comprehend.
depth: Determine the level of detailed examination and the inclusion of innovative insights within the context. A high score indicates a comprehensive and insightful analysis, while a low score suggests a superficial treatment of the topic.
structure: Assess how well the content is organized and whether it flows logically. High scores are awarded to contexts that demonstrate coherent organization and logical progression, whereas low scores indicate a lack of structure or clarity in progression.
relevance: Judge the pertinence of the content to the main topic, awarding high scores to contexts tightly focused on the subject without unnecessary digressions, and low scores to those that are cluttered with irrelevant information.
Structure your JSON output to reflect these criteria as keys with their corresponding scores as values
    a  The Pythagorean theorem is a fundamental principle in geometry. It states that in a right-angled triangle, the square of the length of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the lengths of the other two sides. This can be written as a^2 + b^2 = c^2 where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.   )r1   r2   r3   r4   )r   r	   zAlbert Einstein (14 March 1879 - 18 April 1955) was a German-born theoretical physicist who is widely held to be one of the greatest and most influential scientists of all time.zI love chocolate. It's really tasty. Oh, and by the way, the earth orbits the sun, not the other way around. Also, my favorite color is blue.)r   r   output_format_instructionr   r   r   r   r   filter_questiona  
Asses the given question for clarity and answerability given enough domain knowledge, consider the following criteria:
1.Independence: Can the question be understood and answered without needing additional context or access to external references not provided within the question itself? Questions should be self-contained, meaning they do not rely on specific documents, tables, or prior knowledge not shared within the question.
2.Clear Intent: Is it clear what type of answer or information the question seeks? The question should convey its purpose without ambiguity, allowing for a direct and relevant response.
Based on these criteria, assign a verdict of "1" if a question is specific, independent, and has a clear intent, making it understandable and answerable based on the details provided. Assign "0" if it fails to meet one or more of these criteria due to vagueness, reliance on external references, or ambiguity in intent.
Provide feedback and a verdict in JSON format, including suggestions for improvement if the question is deemed unclear. Highlight aspects of the question that contribute to its clarity or lack thereof, and offer advice on how it could be reframed or detailed for better understanding and answerability.
z"What is the discovery about space?a  The question is too vague and broad, asking for a 'discovery about space' without specifying any particular aspect, time frame, or context of interest. This could refer to a wide range of topics, from the discovery of new celestial bodies to advancements in space travel technology. To improve clarity and answerability, the question could specify the type of discovery (e.g., astronomical, technological), the time frame (e.g., recent, historical), or the context (e.g., within a specific research study or space mission).0)r/   r   zHow does ALMA-13B-R perform compared to other translation models in the WMT'23 study, based on the results in context1 and context2?a  This question asks for a comparison of the ALMA-13B-R model's performance against other translation models within the WMT'23 study, specifically referring to results in 'context1' and 'context2'. While it clearly specifies the model of interest (ALMA-13B-R) and the study (WMT'23), it assumes access to and understanding of 'context1' and 'context2' without explaining what these contexts entail. This makes the question unclear for those not familiar with the WMT'23 study or these specific contexts. To improve clarity and answerability for a broader audience, the question could benefit from defining or describing 'context1' and 'context2' or explaining the criteria used for comparison in these contexts.zHow do KIWI-XXL and XCOMET compare to the gold standard references in Table 1 in terms of evaluation scores, translation model performance, and success rate in surpassing the references?a  The question requests a comparison between KIWI-XXL and XCOMET models and gold standard references in 'Table 1', focusing on evaluation scores, translation model performance, and success rates in surpassing the references. It specifies the models and criteria for comparison, making the intent clear. However, the question assumes access to 'Table 1' without providing its content or context, making it unclear for those without direct access to the source material. To be clearer and more answerable for a general audience, the question could include a brief description of the content or key findings of 'Table 1', or alternatively, frame the question in a way that does not rely on specific, unpublished documents.znWhat is the configuration of UL2 training objective in OpenMoE and why is it a better choice for pre-training?a  The question asks for the configuration of the UL2 training objective within the OpenMoE framework and the rationale behind its suitability for pre-training. It is clear in specifying the topic of interest (UL2 training objective, OpenMoE) and seeks detailed information on both the configuration and the reasons for its effectiveness in pre-training. However, the question might be challenging for those unfamiliar with the specific terminology or the context of OpenMoE and UL2. For broader clarity and answerability, it would be helpful if the question included a brief explanation or context about OpenMoE and the UL2 training objective, or clarified the aspects of pre-training effectiveness it refers to (e.g., efficiency, accuracy, generalization).zkWhat is the detailed configuration of the UL2 training objective in OpenMoE, based on the provided context?a  The question seeks detailed information on the UL2 training objective's configuration within the OpenMoE framework, mentioning 'the provided context' without actually including or describing this context within the query. This makes the question unclear for those who do not have access to the unspecified context. For the question to be clear and answerable, it needs to either include the relevant context directly within the question or be framed in a way that does not require external information. Detailing the specific aspects of the configuration of interest (e.g., loss functions, data augmentation techniques) could also help clarify the query.evolution_eliminationzCheck if the given two questions are equal based on following requirements:
    1. They have same constraints and requirements.
    2. They have same depth and breadth of the inquiry.
    Output verdict as 1 if they are equal and 0 if they are notz.What are the primary causes of climate change?z*What factors contribute to global warming?zWhile both questions deal with environmental issues, 'climate change' encompasses broader changes than 'global warming', leading to different depths of inquiry.)rA   r   )	question1	question2r	   z'How does photosynthesis work in plants?z8Can you explain the process of photosynthesis in plants?zBoth questions ask for an explanation of the photosynthesis process in plants, sharing the same depth, breadth, and requirements for the answer.z1What are the health benefits of regular exercise?z?Can you list the advantages of exercising regularly for health?zBoth questions seek information about the positive effects of regular exercise on health. They require a similar level of detail in listing the health benefits.rI   rJ   N)langchain_core.pydantic_v1r   ragas.llms.output_parserr   r   ragas.llms.promptr   reasoning_question_promptmulti_context_question_promptconditional_question_promptcompress_question_promptconversational_question_promptquestion_answer_promptkeyphrase_extraction_promptseed_question_promptmain_topic_extraction_promptfind_relevant_context_promptquestion_rewrite_promptr0   r=   r@   context_scoring_parserquestion_filter_parserevolution_elimination_parser	parse_objdictcontext_scoring_promptfilter_question_promptevolution_elimination_promptr:   r:   r:   r;   <module>   s   	
	
			#!

 


	'



/? 
