ben-aaron188 / rgpt3

Making requests from R to the GPT models
GNU General Public License v3.0
101 stars 16 forks source link

Limited to just 10 responses? #6

Closed drleehw closed 1 year ago

drleehw commented 1 year ago

I've tried playing with various parameters, but I seem to be limited to just 10 responses. Is this a limitation or am I doing something stupid?


tweets <- c(
  "Just spilled coffee on myself, not off to a great start",
  "Feeling productive and motivated today!",
  "Got stuck in traffic this morning, already stressed out",
  "Excited to try that new lunch spot everyone's been talking about",
  "Woke up feeling refreshed and ready to take on the day",
  "Feeling overwhelmed with work and deadlines",
  "Finally finished that big project I've been working on for weeks!",
  "Forgot my lunch at home, having a hungry day",
  "Had a great meeting with my boss this morning, feeling appreciated",
  "Feeling under the weather, hoping to get some rest later",
  "Just got a promotion, feeling on top of the world!",
  "Feeling discouraged after getting some negative feedback at work",
  "Met up with an old friend for lunch, feeling grateful for good company",
  "Feeling tired and unmotivated today, need some coffee ASAP",
  "Spent the morning in back-to-back meetings, feeling drained",
  "Received some good news today, feeling optimistic",
  "Feeling stressed about upcoming deadlines, but trying to stay focused",
  "Having a great day so far, feeling productive and energized",
  "Feeling disappointed after not getting that job I applied for",
  "Celebrating a coworker's birthday today, feeling festive"
)

# create a data frame with one column called "tweets"
tweet_data <- data.frame(tweets)

# add a column called "promptID" that contains the row number

tweet_data <- tweet_data %>%
  mutate(promptID = paste0(row_number()))

# Create the root prompt for GPT to apply to each data point
the_prompt_prefix <- "Categorise this tweet whether the tweeter would be happy or not. 
                      Respond with just [positive/negative/neutral] ["
the_prompt_postfix <- "]"

# Make the API request, using the prompts from the data frame
# Note that we are using a different model here, text-ada-001
# Different models cost different amounts of API credits!!!
GPT_tweet_sentiment <- gpt3_completions(prompt_var = paste0(the_prompt_prefix, our_date_data$Date, the_prompt_postfix),
                              id_var = our_date_data$promptID,
                              param_model = 'text-davinci-003',
                              param_max_tokens = 100,
                              param_n = 1,
                              param_temperature = 0.4,
                              )

# use dplyr mutate to add the GPT-3 responses to the data frame
tweet_data <- tweet_data %>%
  mutate(GPT_tweet_sentiment = GPT_tweet_sentiment[[1]]$gpt3)

# Print the data frame
tweet_data```
ben-aaron188 commented 1 year ago

Hi. I can't fully replicate your example as I don't have the our_date_data object. I'd do it like this: create a new variable that has the prompt in it and paste it to the tweet of interest -->

tweet_data$prompt = paste0('Categorise this tweet whether the tweeter would be happy or not.
                      Respond with just [positive/negative/neutral]. \nTweet: ', tweet_data$tweets, '\n Response: ')

GPT_tweet_sentiment <- gpt3_completions(prompt_var = tweet_data$prompt,
                                        id_var = tweet_data$promptID,
                                        param_model = 'text-davinci-003',
                                        param_max_tokens = 100,
                                        param_n = 1,
                                        param_temperature = 0.4)

Output (no rate limit issues) is in the expected form (i.e., negative, positive, ...).

Could you try running this? If that doesn't work, check if you're still within your API limits (funds and/or expiry of free trial). There are some limits at play but I don't think these apply for this example.

Let me know if this worked or not.