[feat][abaoxomtieu]: grammar check route
Browse filesFiles changed (2)
99 unmodified lines10010110210310410510610799 unmodified linesYou must return in JSON format, field is mandatory:{{summary: a concise summary about the document/papertype: must be "Business" or "RnD" based on document content}}"""return prompt99 unmodified lines10010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214399 unmodified linesYou must return in JSON format, field is mandatory:{{"summary": a concise summary about the document/paper"type": must be "Business" or "RnD" based on document content}}"""return promptdef grammar_check_prompt(sentence):prompt = f"""# Introduction: You are an expert in English grammar. You are given a text to check grammar.# System instructions:0. No yapping1. Read the text carefully.2. Correct the grammar mistakes in the text.3. Return the corrected text.Examples:1.Sentence: "She don't know nothing about the new project, and there is many details that needs to be explained."Incorrect: [don't know nothing, is, needs]Correct: [doesn't know anything, are, need]Corrected sentence: "She doesn't know anything about the new project, and there are many details that need to be explained."2.Sentence: "He go to the store every day, but he never buy nothing."Incorrect: [go, buy nothing]Correct: [goes, buys anything]Corrected sentence: "He goes to the store every day, but he never buys anything."***My sentence: {sentence}You must return in JSON format, field is mandatory:{{"sentence": my origin sentence,"incorrect": [list of incorrect words or phrases, it can be repeated],"correct": [list of correct words or phrases, it can be repeated],"corrected_sentence": corrected sentence}}"""return prompt
12345678910111213141516171819204 unmodified lines252627282930313210 unmodified lines434445464748495051525354553 unmodified lines5960616263646511 unmodified lines777879from fastapi import APIRouter, statusfrom ..utils.response_fmt import jsonResponseFmtfrom ..configs.thread_config import run_in_threadfrom ..prompts.document_type_clf import chain_type_classifyfrom ..prompts.summarize_doc import chain_summarizefrom ..prompts.translate_abstract_BIZ import chain_BIZfrom ..prompts.translate_abstract_RnD import chain_RnDfrom ..configs.llm_config import llmfrom ..prompts.prompt import (classify_document_prompt,summarizeNclassify_doc_prompt,translate_BIZ_prompt,translate_RnD_prompt,)from pydantic import BaseModel, Fieldfrom langchain_core.output_parsers import JsonOutputParserimport asynciorouter = APIRouter(prefix="/llm", tags=["LLM"])# @router.post("/classify_document_type", status_code=status.HTTP_200_OK)4 unmodified lines# result = await run_in_thread(type_classify, text)# return jsonResponseFmt(result)class SummaryNClassifyDocument(BaseModel):text: str@router.post("/summary", status_code=status.HTTP_200_OK)async def summarize_doc(body: SummaryNClassifyDocument):prompt = summarizeNclassify_doc_prompt(body.text)10 unmodified lines@router.post("/translate_RnD", status_code=status.HTTP_200_OK)async def translate_RnD(body: TranslateAbstract):print("Đã vào translate_RnD")await asyncio.sleep(15)result = await run_in_thread(llm.invoke, translate_RnD_prompt(body.abstract, body.sentence, body.word))# result = JsonOutputParser().parse(result)print(result)return jsonResponseFmt(result)3 unmodified linesresult = await run_in_thread(translate_BIZ_prompt, body.abstract, body.sentence, body.word)# result = JsonOutputParser().parse(result)print(result)return jsonResponseFmt(result)11 unmodified linesresult = await run_in_thread(llm.invoke, summarize_doc(body.text))result = JsonOutputParser().parse(result)return jsonResponseFmt(result)1234567891011121314151617184 unmodified lines232425262728293031323310 unmodified lines4445464748495051523 unmodified lines56575859606111 unmodified lines7374757677787980818283848586from fastapi import APIRouter, statusfrom ..utils.response_fmt import jsonResponseFmtfrom ..configs.thread_config import run_in_threadfrom ..configs.llm_config import llmfrom ..prompts.prompt import (classify_document_prompt,summarizeNclassify_doc_prompt,translate_BIZ_prompt,translate_RnD_prompt,grammar_check_prompt,)from pydantic import BaseModel, Fieldfrom langchain_core.output_parsers import JsonOutputParserimport asynciorouter = APIRouter(prefix="/llm", tags=["LLM"])# @router.post("/classify_document_type", status_code=status.HTTP_200_OK)4 unmodified lines# result = await run_in_thread(type_classify, text)# return jsonResponseFmt(result)class SummaryNClassifyDocument(BaseModel):text: str@router.post("/summary", status_code=status.HTTP_200_OK)async def summarize_doc(body: SummaryNClassifyDocument):prompt = summarizeNclassify_doc_prompt(body.text)10 unmodified lines@router.post("/translate_RnD", status_code=status.HTTP_200_OK)async def translate_RnD(body: TranslateAbstract):result = await run_in_thread(llm.invoke, translate_RnD_prompt(body.abstract, body.sentence, body.word))return jsonResponseFmt(result)3 unmodified linesresult = await run_in_thread(translate_BIZ_prompt, body.abstract, body.sentence, body.word)print(result)return jsonResponseFmt(result)11 unmodified linesresult = await run_in_thread(llm.invoke, summarize_doc(body.text))result = JsonOutputParser().parse(result)return jsonResponseFmt(result)class GrammarCheck(BaseModel):sentence: str = Field(description="Sentence to check", min_length=1)@router.post("grammar_check", status_code=status.HTTP_200_OK)async def grammar_check(body: GrammarCheck):result = await run_in_thread(llm.invoke, grammar_check_prompt(body.sentence))result = JsonOutputParser().parse(result)return jsonResponseFmt(result)
apis/V1/prompts/prompt.py+38-2
apis/V1/routes/chat.py+16-9