forked from rishabkumar7/pets-name-langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
langchain_helper.py
28 lines (18 loc) · 877 Bytes
/
langchain_helper.py
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
import streamlit as st
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains import SequentialChain
from dotenv import load_dotenv
load_dotenv()
def generate_pet_name(animal_type, pet_color, openai_api_key):
llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key)
prompt_template_name = PromptTemplate(
input_variables = ['animal_type','pet_color'],
template = "I have a {animal_type} pet and I want a cool name for it, it is {pet_color} in color. Suggest me five cool names for my pet."
)
name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="pet_name")
response = name_chain({'animal_type': animal_type, 'pet_color': pet_color})
return response
if __name__ == "__main__":
print(generate_pet_name("Dog", "Black"))