Customize the prompts with refine model #10477
Replies: 2 comments 1 reply
-
🤖 Hello, To summarize the entire text in 20 words by combining the prompt as many times as the number of split texts, you can modify your code as follows: from langchain import Document, PromptTemplate
from langchain.openai import ChatOpenAI
from langchain.chains.summarize import load_summarize_chain
llm = ChatOpenAI(model_name="gpt-3.5-turbo" , openai_api_key="example_api_key")
# Assuming 'texts' is your list of split texts
docs = [Document(page_content=t) for t in texts]
# Initialize an empty string to store the final summary
final_summary = ""
# Loop through each document
for doc in docs:
refine_prompt_template = f"Write a summary of the following text : {doc.page_content} please summarize in approximately 20 words"
refine_prompt = PromptTemplate(template=refine_prompt_template, input_variables=[doc.page_content])
refine_chain = load_summarize_chain(llm, chain_type="refine", refine_prompt=refine_prompt)
# Generate the summary for the document
summary = refine_chain.run(doc)
# Add the summary to the final summary
final_summary += summary
# Now 'final_summary' should contain the combined summary of all documents This code will loop through each document in your list of split texts, generate a summary for it using the Please note that the I hope this helps! Let me know if you have any other questions. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
First summarize a large amount of text into few paragraph. Use the following code:
Then, use a simple custom summary prompt or |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I need to customize my summarization using refine model.
I'm working with load_summarize_chain and also i'm working with large documents, so i had to split my documents.
This is a part of code that i wrote :
I want the entire text to be summarized in 20 words (how can i combine this prompt as many as number of texts ?(number of t))
Beta Was this translation helpful? Give feedback.
All reactions