Skip to content

Instantly share code, notes, and snippets.

@rfeers
Created December 19, 2023 16:15
Show Gist options
  • Save rfeers/ccb3022b8218cc27076a2059775112fa to your computer and use it in GitHub Desktop.
Save rfeers/ccb3022b8218cc27076a2059775112fa to your computer and use it in GitHub Desktop.
def analyze_sentiment(review):
response = openai.completions.create(
model="text-davinci-003", # You can choose the model version
prompt=f"Analyze the sentiment of this review: \"{review}\". Is it positive, negative, or neutral?",
max_tokens=60
)
sentiment = response.choices[0].text.strip()
return sentiment
df_short["Polarity"] = df_short.apply(lambda x:analyze_sentiment(x["Text"]), axis=1)
df_short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment