From bed06a4f4ab802bedb3533021da920c05a736810 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Tue, 14 Nov 2023 21:04:57 -0800 Subject: [PATCH] IMPROVEMENT research-assistant configurable report type (#13312) --------- Co-authored-by: Harrison Chase --- .../research_assistant/writer.py | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/templates/research-assistant/research_assistant/writer.py b/templates/research-assistant/research_assistant/writer.py index b72677f9f0e..9af15f4b0d1 100644 --- a/templates/research-assistant/research_assistant/writer.py +++ b/templates/research-assistant/research_assistant/writer.py @@ -1,8 +1,13 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate from langchain.schema.output_parser import StrOutputParser +from langchain.schema.runnable import ConfigurableField -REPORT_TEMPLATE = """Information: +WRITER_SYSTEM_PROMPT = "You are an AI critical thinker research assistant. Your sole purpose is to write well written, critically acclaimed, objective and structured reports on given text." # noqa: E501 + + +# Report prompts from https://github.com/assafelovic/gpt-researcher/blob/master/gpt_researcher/master/prompts.py +RESEARCH_REPORT_TEMPLATE = """Information: -------- {research_summary} -------- @@ -18,14 +23,53 @@ Write all used source urls at the end of the report, and make sure to not add du You must write the report in apa format. Please do your best, this is very important to my career.""" # noqa: E501 + +RESOURCE_REPORT_TEMPLATE = """Information: +-------- +{research_summary} +-------- + +Based on the above information, generate a bibliography recommendation report for the following question or topic: "{question}". \ +The report should provide a detailed analysis of each recommended resource, explaining how each source can contribute to finding answers to the research question. \ +Focus on the relevance, reliability, and significance of each source. \ +Ensure that the report is well-structured, informative, in-depth, and follows Markdown syntax. \ +Include relevant facts, figures, and numbers whenever available. \ +The report should have a minimum length of 1,200 words. + +Please do your best, this is very important to my career.""" # noqa: E501 + +OUTLINE_REPORT_TEMPLATE = """Information: +-------- +{research_summary} +-------- + +Using the above information, generate an outline for a research report in Markdown syntax for the following question or topic: "{question}". \ +The outline should provide a well-structured framework for the research report, including the main sections, subsections, and key points to be covered. \ +The research report should be detailed, informative, in-depth, and a minimum of 1,200 words. \ +Use appropriate Markdown syntax to format the outline and ensure readability. + +Please do your best, this is very important to my career.""" # noqa: E501 + model = ChatOpenAI(temperature=0) prompt = ChatPromptTemplate.from_messages( [ - ( - "system", - "You are an AI critical thinker research assistant. Your sole purpose is to write well written, critically acclaimed, objective and structured reports on given text.", # noqa: E501 - ), - ("user", REPORT_TEMPLATE), + ("system", WRITER_SYSTEM_PROMPT), + ("user", RESEARCH_REPORT_TEMPLATE), ] +).configurable_alternatives( + ConfigurableField("report_type"), + default_key="research_report", + resource_report=ChatPromptTemplate.from_messages( + [ + ("system", WRITER_SYSTEM_PROMPT), + ("user", RESOURCE_REPORT_TEMPLATE), + ] + ), + outline_report=ChatPromptTemplate.from_messages( + [ + ("system", WRITER_SYSTEM_PROMPT), + ("user", OUTLINE_REPORT_TEMPLATE), + ] + ), ) chain = prompt | model | StrOutputParser()