File size: 1,093 Bytes
1c041ec
 
 
 
3fd8457
1c041ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fd8457
1c041ec
 
 
 
 
 
 
 
 
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
import langchain as lc
from langchain import PromptTemplate
from langchain.prompts import load_prompt
import wikipedia
import model

# save templates to a file


# An example prompt with multiple input variables
multiple_input_prompt = PromptTemplate(
    input_variables=["adjective", "content"],
    template="Tell me a {adjective} joke about {content}.",
)
multiple_input_prompt.save("awesome_prompt.json")  # Save to JSON file
# multiple_input_prompt.format(adjective="funny", content="chickens")
# -> "Tell me a funny joke about chickens."


prompt = load_prompt("awesome_prompt.json")


def pipeline(text, word):
    model_output = ""
    input_text = prompt.format(adjective="funny", content=text)
    while word not in model_output:
        model_output = model.run(input_text)
        wikipedia_entry = wikipedia.search(word)[1]
        wiki = wikipedia.summary(wikipedia_entry, auto_suggest=False, redirect=True)
        input_text += model_output + wiki
    return model_output


if __name__ == "__main__":
    print("pipline test")
    pipeline("This is the input text.", "input")