From c3df9826904621680e99411bb5b0843e1487fbd8 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 29 Oct 2024 07:16:51 -0400 Subject: [PATCH] Add sentiment_analysis.py example for analyzing sentiment of text --- examples/sentiment_analysis.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/sentiment_analysis.py diff --git a/examples/sentiment_analysis.py b/examples/sentiment_analysis.py new file mode 100644 index 0000000..94ae229 --- /dev/null +++ b/examples/sentiment_analysis.py @@ -0,0 +1,19 @@ +from _context import sm + +from pydantic import BaseModel +from typing import Literal + + +class SentimentAnalysis(BaseModel): + sentiment: Literal["positive", "negative", "neutral"] + confidence: float + + +print( + sm.generate_data( + prompt="Analyze the sentiment of the following text:\n\n'The product arrived late and was broken. Worst purchase ever!'", + llm_provider="openai", + llm_model="gpt-4o", + response_model=SentimentAnalysis, + ) +)