Skip to content

add sentiments analysis #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/sentiments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Tweet sentiments analysis

This example takes a tweet's URL and analyse the sentiments of the text

## Run the Example

```bash
# Create a Python venv
python3 -m venv venv

# Source it
source venv/bin/activate

# Install the packages
pip install -r requirements.txt

# Set your OpenAI key
export OPENAI_API_KEY=your-api-key

# Run the example
gptscript tweet.gpt --url https://x.com/ibuildthecloud/status/1765748793998467179
```
24 changes: 24 additions & 0 deletions examples/sentiments/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Get url
url = sys.argv[1]

# Setup WebDriver options
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
driver = webdriver.Chrome(options=options)

# Navigate to the page and get field
driver.get(url)
try:
element = WebDriverWait(driver, 50).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div[data-testid='tweetText'] > span"))
)
print(element.text)
finally:
driver.quit()
1 change: 1 addition & 0 deletions examples/sentiments/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
selenium==4.18.1
24 changes: 24 additions & 0 deletions examples/sentiments/tweet.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
tools: sys.write, get-tweet-text, sentiments
description: get the sentiments expressed in a tweet
args: url: URL of the tweet to analyze

Perform the actions in the following order:

Get the text of the tweet referenced by "${url} and save it in the file content.txt
Next analyze the sentiments expressed in this file

---
name: get-tweet-text
description: get text content of a tweet
args: url: url towards a tweet

#!python3 main.py "$url"

---
name: sentiments
description: Get the sentiment of the writer
args: content: any string

You are a program designed to assess the sentiments expressed by a writer in a text.

Do not give too many details, just the overall sentiments that is expressed in "${content}"