Skip to content

Latest commit

 

History

History
31 lines (19 loc) · 590 Bytes

chapter10.md

File metadata and controls

31 lines (19 loc) · 590 Bytes

Chapter 10: Sentiment Analysis

You can use LangChain to do sentiment analysis on text.

from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import LLMChain


template = """
Analyze the sentiment of the following text:

Text: {text}

Sentiment (positive/negative/neutral):
"""

prompt = PromptTemplate(
    input_variables=["text"],
    template=template
)


chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt)


text = "I love using LangChain for AI development. It's so powerful and easy to use!"
print(chain.run(text))