python

[GPT][MEETINGGPT] Refine Chain

으누아빠 2024. 5. 14. 12:47
반응형

 

refine[문서 분할-병합 요약]
 입력 문서를 순회하며 반복적으로 답변을 업데이트하여 응답을 구성합니다. 
각 문서에 대해, 모든 비문서 입력, 현재 문서, 그리고 최신 중간 답변을 LLM chain에 전달하여 새로운 답변을 얻습니다.

    with summary_tab:
        start = st.button("Generate summary")
        if start:
            loader = TextLoader(transcript_path, encoding="utf-8")

            docs = loader.load_and_split(text_splitter=splitter)

            first_summary_prompt = ChatPromptTemplate.from_template(
                """
                Write a concise summary of the following:
                "{text}"
                CONCISE SUMMARY:
            """
            )

            first_summary_chain = first_summary_prompt | llm | StrOutputParser()

            summary = first_summary_chain.invoke(
                {"text": docs[0].page_content},
            )

            refine_prompt = ChatPromptTemplate.from_template(
                """
                Your job is to produce a final summary.
                We have provided an existing summary up to a certain point: {existing_summary}
                We have the opportunity to refine the existing summary (only if needed) with some more context below.
                ------------
                {context}
                ------------
                Given the new context, refine the original summary.
                If the context isn't useful, RETURN the original summary.
                Please summarize it in Korean
                """
            )

            refine_chain = refine_prompt | llm | StrOutputParser()

            with st.status("Summarizing...") as status:
                for i, doc in enumerate(docs[1:]):
                    status.update(label=f"Processing document {i+1}/{len(docs)-1} ")
                    summary = refine_chain.invoke(
                        {
                            "existing_summary": summary,
                            "context": doc.page_content,
                        }
                    )
                    st.write(summary)
            st.write(summary)

 

 

'python' 카테고리의 다른 글

[GPT][INVESTORGPT] Agent  (0) 2024.05.20
[GPT][MEETINGGPT] 최종 예제  (0) 2024.05.14
[GPT][MEETINGGPT] Whisper Transcript  (0) 2024.05.14
[GPT][MEETINGGPT] Cutting The Audio  (0) 2024.05.14
[GPT][MEETINGGPT] Audio Extraction  (0) 2024.05.14