TextGen / product_description_generation.py
abdullah10's picture
Upload 17 files
dfc4131
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI
from load_model import call_palm
from calling_apis import google_api_key, openai_api_key
def product_description_gen(product_name:str, product_desc:str, tone_of_voice:str, language='En', model_name = 'Google Palm 2', creativity = 'Original') -> str:
'''
Description:
This function generates an engaging product description based on user-provided inputs.
It utilizes the LangChain library to prompt an AI model (Language Model) to create a product description tailored to the specified product name, description, tone of voice, and a provided LLM (Long Language Model).
'''
'''
Parameters:
product_name (str) -> Required: The name of the product for which the description is generated.
product_desc (str) -> Required: A brief description of the product.
tone_of_voice (str) -> Required: The intended tone of the product description (e.g., professional, friendly, persuasive).
language (str): Opitonal Parameter -> The language of the model.
creativity (str): Optional Parameter -> Controling the randomness of the model. Default value is Original
model_name (str): Optional Parameter -> select the LLM model. Default Value is Google Palm 2
'''
'''
Return Value:
product_desc (str): The generated Amazon product description.
'''
temp = 0
if creativity == 'Original':
temp = 0
elif creativity == 'Balanced':
temp = 0.25
elif creativity == 'Creative':
temp = 0.5
elif creativity == 'Spirited':
temp = 0.75
elif creativity == 'Visionary':
temp = 1
if model_name == 'Google Palm 2':
llm = call_palm(google_api_key, temperature=temp)
elif model_name == 'GPT-3.5':
llm = OpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key, temperature=temp)
elif model_name == 'GPT-4':
llm = OpenAI(model_name='gpt-4', openai_api_key=openai_api_key, temperature=temp)
if language == 'En':
productDesc_prompt = f"Write an engagging and {tone_of_voice} Amazon product description of {product_name} Product here is a short description of my product:\n\n{product_desc}\n"
productDesc_promptTemp = PromptTemplate(
input_variables=["text_input"],
template="You are a content creator and product description writer who helps clients to write their product description on amazon:\n{text_input}\nAmazon Product Description:")
elif language == 'Ar':
productDesc_prompt = f"اكتب وصفًا جذابًا و{tone_of_voice} عن منتج {product_name} في أمازون. هنا وصف قصير لمنتجي:\n\n{product_desc}\n"
productDesc_promptTemp = PromptTemplate(
input_variables=["text_input"],
template="أنت كاتب محتوى وكاتب وصف المنتجات الذي يساعد العملاء في كتابة وصف منتجاتهم على أمازون:\n{text_input}\nوصف منتج أمازون:")
productDesc_extraction_chain = LLMChain(llm=llm, prompt=productDesc_promptTemp)
product_desc = productDesc_extraction_chain.run(productDesc_prompt)
return product_desc