AIsmart / utils3.py
palitrajarshi's picture
Upload 2 files
becbcc8
raw
history blame
3.37 kB
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.tools import DuckDuckGoSearchRun
# Function to generate video script
def generate_script(prompt,duration,origin,budget,api_key):
# Template for generating 'Itinerary' using search engine
itinerary_template = PromptTemplate(
input_variables = ['location','duration','DuckDuckGo_Search','expense','origin'],
template='Please come up with a detailed itinerary for a trip to {location} for a duration: {duration} days using this search data {DuckDuckGo_Search}. The maximum budget per person in INR is {expense}. The origin of the journey is {origin}. '
)
# Template for generating 'Conveyance Used' using search engine
conveyance_template = PromptTemplate(
input_variables = ['location', 'origin', 'DuckDuckGo_Search'],
#template='Based on this itinerary: {itinerary}, please mention the conveyance to be taken during the trip while going from one place to another using this search data {DuckDuckGo_Search} '
template='Please mention the different ways to reach the {location} from {origin} and the different modes of travel using this search data {DuckDuckGo_Search} '
)
# Template for generating 'Cuisines' using search engine
cuisines_template = PromptTemplate(
input_variables = ['itinerary', 'DuckDuckGo_Search'],
template='Based on this itinerary: {itinerary}, please mention the cuisines that I can try during the trip using this search data {DuckDuckGo_Search} '
)
# Template for generating 'Accomodation' using search engine
accomodation_template = PromptTemplate(
input_variables = ['itinerary', 'DuckDuckGo_Search'],
template='Based on this itinerary: {itinerary}, please mention the accomodation/hotel that I can stay in during the trip using this search data {DuckDuckGo_Search} '
)
#Setting up OpenAI LLM
llm = OpenAI(temperature=0.5, openai_api_key=api_key, model_name='gpt-3.5-turbo')
#Creating chain for 'Itinerary', 'Conveyance', 'Cuisines', 'Accomodation'
itinerary_chain = LLMChain(llm=llm, prompt=itinerary_template, verbose=True)
conveyance_chain = LLMChain(llm=llm, prompt=conveyance_template, verbose=True)
cuisines_chain = LLMChain(llm=llm, prompt=cuisines_template, verbose=True)
accomodation_chain = LLMChain(llm=llm, prompt=accomodation_template, verbose=True)
# https://python.langchain.com/docs/modules/agents/tools/integrations/ddg
search = DuckDuckGoSearchRun()
search_result = search.run(prompt)
# Executing the chains we created for 'Itinerary' by taking help of search engine 'DuckDuckGo'
itinerary = itinerary_chain.run(location=prompt,duration=duration,DuckDuckGo_Search=search_result,expense=budget,origin=origin)
# Executing the chains we created for 'Conveyance', 'Cuisines', 'Accomodation' by taking help of search engine 'DuckDuckGo'
conveyance = conveyance_chain.run(location=prompt,origin=origin,DuckDuckGo_Search=search_result)
hotel = accomodation_chain.run(itinerary=itinerary,DuckDuckGo_Search=search_result)
cuisine = cuisines_chain.run(itinerary=itinerary,DuckDuckGo_Search=search_result)
# Returning the output
return search_result,itinerary,conveyance,hotel,cuisine