Spaces:
Sleeping
Sleeping
| from pydantic import BaseModel, Field | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from typing import List | |
| from src.config.llm import llm_2_0 as llm | |
| class HighlightExplain(BaseModel): | |
| """Explain the highlight terms in a concise and easy to understand manner.""" | |
| explanation: str = Field(description="The explanation of the highlight terms.") | |
| class HighlightExplainQuestionGenerate(BaseModel): | |
| """Gợi ý 3 câu hỏi liên quan""" | |
| questions: List[str] = Field( | |
| description="Các câu hỏi gợi ý liên quan" | |
| ) | |
| highlight_explain_prompt = ChatPromptTemplate( | |
| [ | |
| ( | |
| "system", | |
| """You are an expert in explaining highlighted terms in the {domain} domain. | |
| You are provided with highlighted terms/sentences, adjacent paragraphs of those terms/sentences. | |
| Your task is to explain the highlighted terms in a concise and easy-to-understand way. | |
| You are also provided with user questions. | |
| The explanation must be primarily in {language}. But you can use {domain} domain terms in the explanation. | |
| """, | |
| ), | |
| ( | |
| "human", | |
| """ | |
| Câu hỏi của người dùng: {question} | |
| Highlight terms: {highlight_terms} | |
| Câu xung quanh highlight terms: {adjacent_paragraphs} | |
| """, | |
| ), | |
| ] | |
| ) | |
| highlight_explain_question_generate_prompt = ChatPromptTemplate( | |
| [ | |
| ( | |
| "system", | |
| """Bạn là chuyên gia gợi ý câu hỏi ở lĩnh vực {domain}. | |
| Bạn được cung cấp với các từ khóa được nhấn và các đoạn văn xung quanh từ khóa. | |
| Bạn cần gợi ý các câu hỏi phù hợp với các từ khóa được nhấn và các đoạn văn xung quanh từ khóa. | |
| Gen ra 3 gợi ý | |
| Câu hỏi phải được viết chủ yếu bằng {language}. Nhưng bạn có thể sử dụng các từ khóa trong lĩnh vực {domain}. | |
| """, | |
| ), | |
| ( | |
| "human", | |
| """ | |
| Highlight terms: {highlight_terms} | |
| Câu xung quanh highlight terms: {adjacent_paragraphs} | |
| """, | |
| ), | |
| ] | |
| ) | |
| highlight_explain_chain = highlight_explain_prompt | llm.with_structured_output( | |
| HighlightExplain | |
| ) | |
| highlight_explain_question_generate_chain = ( | |
| highlight_explain_question_generate_prompt | |
| | llm.with_structured_output(HighlightExplainQuestionGenerate) | |
| ) | |