File size: 3,815 Bytes
8bc7dc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

def article_generator(idea, outline, section, llm, tone_of_voice):
    
    '''
    Description:
        This function generates paragraphs for an article based on provided inputs such as the main idea, outline, specific section, Long Language Model (LLM), and desired tone of voice. 
        It uses a language model to create content either for a catchy introduction paragraph or to expand the article based on an existing outline.

    Parameters:
        idea (str) -> Required: The main idea or topic of the article.
        outline (str) -> Required: The existing outline (if any) that has been covered in the article.
        section (str) -> Required: The specific section or point that needs content creation or elaboration.
        llm -> Required: The Long Language Model (LLM) used for generating article content.
        tone_of_voice (str) -> Required: The intended tone of the article (e.g., professional, conversational, persuasive).

    Return Value:
        article (str): The generated article paragraph based on the provided inputs.
    '''

    if len(outline) == 0:
        article_prompt = f"Generate Catchy Introduction paragraph for my article on {idea} using the following main point: {section}\nThe tone should be {tone_of_voice}."
    else:
        article_prompt = f"Generate well-organized paragraph for my article on {idea}. I have already covered: {outline} in the outline. I need help with the following main point: {section}. Please ensure the paragraphs are connected logically and provide a smooth transition between main topics. The tone should be {tone_of_voice}."

    article_promptTemp = PromptTemplate(
    input_variables=["text_input"],
    template="You are a Professional content creator and article Writer:\n\n{text_input}\n\nParagraph:")
    
    print(article_prompt)
    article_extraction_chain = LLMChain(llm=llm, prompt=article_promptTemp)
    article = article_extraction_chain.run(article_prompt)
    
    return article

def full_article(idea, outline_list, tone_of_voice, llm):
    
    '''
    Description:
        This function generates a full article by iteratively calling the article_generator function for each section in the provided outline list. It accumulates paragraphs generated for each section to construct a complete article based on the specified idea, outline, tone of voice, and Long Language Model (LLM).

    Parameters:
        idea (str) -> Required: The main idea or topic for the article.
        outline_list (list) -> Required: A list containing sections or subsections for the article's structure.
        tone_of_voice (str) -> Required: The desired tone of the article (e.g., professional, conversational, persuasive).
        llm -> Required: The Long Language Model (LLM) used for generating article content.

    Return Value:
        article (list): A list of paragraphs representing the article content for each section in the provided outline.
    '''
    
    article = []
    outline = []
    
    try:
        
        for section in outline_list:

            para = article_generator(idea, ' '.join(outline), section, llm, tone_of_voice)
            outline.append(section)
            article.append(para)
            
    except:
        pass
    
    return article

def rephrase(par, llm):
    
    paraCheck_prompt = f"Rephrase the following paragraph and make it more unique and excited: {par}"

    paraCheck_promptTemp = PromptTemplate(
    input_variables=["text_input"],
    template="You are a content creator.\n{text_input}")
   
    paraCheck_extraction_chain = LLMChain(llm=llm, prompt=paraCheck_promptTemp)
    rephrased_paragraph = paraCheck_extraction_chain.run(paraCheck_prompt)
    
    return rephrased_paragraph