-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
170ccb4
commit 4f0eec2
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
## 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)) | ||
``` |