from langchain.prompts import PromptTemplate from langchain.chains import LLMChain def article_to_x_thread_gen(article, llm): article_to_x_thread_prompt = f"Transform the ensuing article into a sequence of Twitter posts, creating a coherent Twitter thread between 5 to 20 tweets\nArticle: “{article}.“" article_to_x_thread_promptTemp = PromptTemplate( input_variables=["text_input"], template="You are a twitter copywriter\n{text_input}\n\nCoherent Twitter Thread:") article_to_x_thread_extraction_chain = LLMChain(llm=llm, prompt=article_to_x_thread_promptTemp) article_to_x_thread = article_to_x_thread_extraction_chain.run(article_to_x_thread_prompt) return article_to_x_thread