from langchain.llms import OpenAI import os os.environ["OPEN_API_KEY"]=OPEN_API_KEY llm=OpenAI(openai_api_key=os.environ["OPEN_API_KEY"],temperature=0.6) text="What is the capital of India" print(llm.predict(text)) os.environ["HUGGINGFACEHUB_API_TOKEN"]=HuggingFaceHub_API_TOKEN from langchain import HuggingFaceHub llm_huggingface=HuggingFaceHub(repo_id="google/flan-t5-large",model_kwargs={"temperature":0,"max_length":64}) output=llm_huggingface.predict("Can you tell me the capital of Russia") print(output) output=llm_huggingface.predict("Can you write a poem about AI") print(output) llm.predict("Can you write a poem about AI") from langchain.prompts import PromptTemplate prompt_template=PromptTemplate(input_variables=['country'], template="Tell me the capital of this {country}") prompt_template.format(country="India") from langchain.chains import LLMChain chain=LLMChain(llm=llm,prompt=prompt_template) print(chain.run("India")) capital_template=PromptTemplate(input_variables=['country'], template="Please tell me the capital of the {country}") capital_chain=LLMChain(llm=llm,prompt=capital_template) famous_template=PromptTemplate(input_variables=['capital'], template="Suggest me some amazing places to visit in {capital}") famous_chain=LLMChain(llm=llm,prompt=famous_template) from langchain.chains import SimpleSequentialChain chain=SimpleSequentialChain(chains=[capital_chain,famous_chain]) chain.run("India") capital_template=PromptTemplate(input_variables=['country'], template="Please tell me the capital of the {country}") capital_chain=LLMChain(llm=llm,prompt=capital_template,output_key="capital") famous_template=PromptTemplate(input_variables=['capital'], template="Suggest me some amazing places to visit in {capital}") famous_chain=LLMChain(llm=llm,prompt=famous_template,output_key="places") from langchain.chains import SequentialChain chain=SequentialChain(chains=[capital_chain,famous_chain], input_variables=['country'], output_variables=['capital',"places"]) chain({'country':"India"}) from langchain.chat_models import ChatOpenAI from langchain.schema import HumanMessage,SystemMessage,AIMessage chatllm=ChatOpenAI(openai_api_key=os.environ["OPEN_API_KEY"],temperature=0.6,model='gpt-3.5-turbo') chatllm([ SystemMessage(content="Yor are a comedian AI assitant"), HumanMessage(content="Please provide some comedy punchlines on AI") ]) from langchain.chat_models import ChatOpenAI from langchain.prompts.chat import ChatPromptTemplate from langchain.schema import BaseOutputParser class Commaseperatedoutput(BaseOutputParser): def parse(self,text:str): return text.strip().split(",") template="Your are a helpful assistant. When the use given any input , you should generate 5 words synonyms in a comma seperated list" human_template="{text}" chatprompt=ChatPromptTemplate.from_messages([ ("system",template), ("human",human_template) ]) chain=chatprompt|chatllm|Commaseperatedoutput() chain.invoke({"text":"intelligent"})