Coder Social home page Coder Social logo

chatgpt's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

chatgpt's Issues

How to set the api url?

Excuse me, if using a third-party intermediary service, how should I set up the API URL for chatgpt?

Write function

Cool stuff, thanks for putting this together!

How about a write function like:

write_code <- function(description) {
  prompt <- paste0('Write R code that: "', description, '"')
  trimws(sapply(chatgpt:::gpt_get_completions(prompt)$choices, function(x) x$text))
}

cat(write_code("produces a bar plot using ggplot"))

Which returned:

# Create data frame
d <- data.frame(
  place = c("USA", "UK", "Canada", "Australia"),
  values = c(25, 18, 8, 7)
)

# Create bar plot
ggplot(d, aes(x = place, y = values)) + 
  geom_col()

I'm happy to put in a PR if you like the recommendation, but I did almost nothing :) Just a copy and paste of your function with a new name and request.

No output

Thanks for your work on this package. I've installed the addin to RStudio per the instructions. The addin menu and functions are availble, but I'm not getting any response back from chatGPT.

chatgpt_output

Any suggestions?

Returns character(0) when querying too quickly (e.g. in a loop)

When calling ask_chatgpt in a for loop, I get maybe 3 returns with answers, but after that it will return "character(0)" which just seems to be a null character object. When this occurs in the loop, it stops operation with an error about "...replacement has length 0."

I used this workaround, which was effective for my use: insert sys.sleep(x) into the loop, where x is a number of seconds to temporarily suspend operation. 5 wasn't enough and 15 worked, but it appears as if more complex queries and/or higher numbers of loop iterations requires higher times; I had to move to 20 to get a loop to run 121 times.

I'm not sure what's causing the null response and this workaround suits me fine, but would be interested to learn why it occurs in case faster loops are possible.

"You exceeded your current quota.." Except I have not?

Hi, maybe I missed something, but this package should work with a free plan on chatgpt? I am able to ask questions on the chatgpt webpage but in Rstudio I get the message:

Error in gpt_get_completions(question, messages = chat_session_messages) : 
  list(message = "You exceeded your current quota, please check your plan and billing details.", type = "insufficient_quota", param = NULL, code = NULL)

when I run

cat(ask_chatgpt("What is you purpose?"))

Maybe it only works with a payed subscription?

Thanks,
Tom

ChatGPT generates `testthat` use cases from 2nd edition

Sometimes, ChatGPT will generate testthat use cases that use edition 2 functions rather than edition 3.

For example, ChatGPT often uses testthat::context, which was deprecated with testthat 3e.

It might be useful to specify that ChatGPT should use testthat 3e or add a function that asks ChatGPT to convert the output of create_unit_tests from testthat 2e to testthat 3e.

Can not switch to gpt-4

Greeting,
I have tried to use usethis::edit_r_environ() and add OPENAI_MODEL="gpt-4," but it does not work for me to switch to gpt-4. Am I right on that?
Thanks.
RStudio-2023.12.1-402
R-4.3.3 for Windows

Error: "`OPENAI_API_KEY` not provided."

In Rgui on Windows, I get

ask_chatgpt("How many hours are there in a day?")
Error in gpt_get_completions(question, messages = chat_session_messages) :
OPENAI_API_KEY not provided.

How do I provide OPENAI_API_KEY?

clipr for using the code copied to the clipboard

Hello there - great package, I just thought about building something like this, but it is already done ๐Ÿ‘

I think a good addition could be using the function code that is copied to the clipboard, similar to reprex package. User will select the code, Ctrl/Command + C and run any of the package functions.

It will require clipr as a dependency and one more enviroment variable that will use this "new" approach by default.
Alternatively we can allow running functions without specified value for code argument and it will use the code from clipboard and stop() when the clipboard is NULL.

I just tried it and works quite well.

I can work on it and raise a PR if you're interested. Please let me know your thoughts.

Have a great day!

Denis

Error: exceeded the current quota

When I use chatgpt I recieve an error:

Warning: Error in gpt_get_completions: list(message = "You exceeded your current quota, please check your plan and billing details.", type = "insufficient_quota", param = NULL, code = NULL)

However if I sign in in OpenaAI I can use it without any problem.

Hi @guoliangzeng ,I am trying to use this code but I get this error Downloading GitHub repo jcrodriguez1989/[email protected]_api_url Error in utils::download.file(url, path, method = method, quiet = quiet, : cannot open URL 'https://api.github.com/repos/jcrodriguez1989/chatgpt/tarball/feature.jcr.switch_api_url' any Idea what i can do?

          Hi @guoliangzeng ,

I created a branch that allows changing the OPENAI's API URL. Could you try doing this?
Fully restart your R session, and then:

remotes::install_github("jcrodriguez1989/[email protected]_api_url")
Sys.setenv(OPENAI_API_URL = "https://api.chatanywhere.com.cn/v1")
# If this doesn't work, do `Sys.setenv(OPENAI_API_URL = "https://api.chatanywhere.com.cn")`
library("chatgpt")
cat(ask_chatgpt("What do you think about R language?"))

Please, let me know if you get any errors.

Originally posted by @jcrodriguez1989 in #48 (comment)

Specify to use v4.0 model?

Any chance that we can pass an argument to specify the model to use for the queries made through this package? Appreciate you putting it together and prevent meaningless JSON writing.

assistance api

is there a way to connect the package to an already created custom assistant from the playground

Support for ChatGPT 3.5

A new model for chatGPT has been released, but it uses a different endpoint. Here's some example code to get a result:

library(chatgpt)
library(httr)
library(jsonlite)

Sys.setenv(OPENAI_MODEL = "gpt-3.5-turbo")
Sys.setenv(OPENAI_API_KEY = readLines("~/api_keys/openapi.txt"))

openai_api_key = Sys.getenv("OPENAI_API_KEY")
gpt_model = Sys.getenv("OPENAI_MODEL")

messages = list(
  list(role="system", content= "You are a helpful assistant."),
  list(role="user", content= "Who won the world series in 2020?"),
  list(role="assistant", content= "The Los Angeles Dodgers won the World Series in 2020."),
  list(role="user", content= "Where was it played?")
)


params = list(model = gpt_model,
              messages = messages)


response <- content(
  POST(
    "https://api.openai.com/v1/chat/completions",
    add_headers(Authorization = paste("Bearer",
                                      openai_api_key)),
    content_type_json(),
    body = toJSON(params, auto_unbox = TRUE)
  )
)

`ask_chatgpt` sessions

Ask ChatGPT: Opens an interactive chat session with ChatGPT

Does this means that a new session is opened every time the ask_chatgpt function is called, or is the same session used for each subsequent prompt?

If the former, then how does one start a new chatGPT session? Simply restarting the Rstudio session?

If the latter, how can we make the session persistent across queries?

Thanks,
Brian

Error in gpt_get_completions

Dear Juan,
I confronted an error during using chatgpt package,
the error is "

> cat(ask_chatgpt("What do you think about R language?")) *** ChatGPT input: What do you think about R language? Error in gpt_get_completions(question, messages = chat_session_messages) : list(message = "Incorrect API key provided: sk-7jyy9***************************************PebN. You can find your API key at https://platform.openai.com/account/api-keys.", type = "invalid_request_error", param = NULL, code = "invalid_api_key") -- ย  > | > > " but I am sure the API key is still valid, how can I fix this error?

Thank you!
best wishes,
Shunsen

Tweaking parameters

I am trying to tweak the get parameters, but the document that is linked does not clearly show how to do so. Some examples or explanation would be really helpful.

Timeout was reached

Warning: Error in curl::curl_fetch_memory: Timeout was reached: [api.openai.com] Failed to connect to api.openai.com port 443 after 10006 ms: Timeout was reached

gpt-4 support is still missing.

Hey,

Seems like gpt-4 models listed below are still not covered.

All models;
OpenAI models page

Error that occured when tried "gpt-4" for Sys.setenv(OPENAI_MODEL = "gpt-4")

Error in gpt_get_completions(question) : 
  list(message = "This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?", type = "invalid_request_error", param = "model", code = NULL)

Typo in README

"The following environment variables variables can be set ..." - the word "variables" is repeated.

Is there limit for comment_code function?

Thanks for the helpful package.
I tried the comment_code function and it does what is expected. However, when I give it a somewhat larger chunk (e.g a function with 12-15 commands), it only comments on the first few and ignores the rest. So I wanted to know if there is a limit as to how many lines/commands it can comment?
And is that limit set by you or by chatgpt?
I can provide an example if you want but any code with more than 10 lines would reproduce the behaviour, I think.

Thanks in advance
Rohit

Is there a way to get metadata of responses?

I have my model set, but I want to be able to have confirmation attached to output about which model was used to generate the response. ChatGPT suggests this is possible using Python, where "metadata" is another option that can be set along with temperature, max tokens, etc. Below is the Python code it suggested to me; I looked through the repository and didn't see a metadata option.

Use case: My account provider is telling me I should have access to GPT-4. After generating an API key under the proper default organization, and attempting to set GPT-4 in R, I get the error suggesting I don't have access to it. In the Rate Limits and Playground, I also don't see evidence of having access to GPT-4, only GPT-3.5-turbo. That's fine, that appears to be an administrative error.

But then when having 3.5-turbo set in R, and I ask_chatgpt which model it is, it tells me it is "a simple GPT-2 model." On the other hand, when using the chat.openai.com, it gives me a dramatically different answers about which model it is. Asking for this information probably isn't a reliable solution. So while the OPENAI_MODEL should be the straightforward validation of which model is generating the response, I'm hoping for another way of confirming.


import openai
openai.api_key = "YOUR_API_KEY"

prompt = "Some text you want to generate a response for"
model = "text-davinci-002" # Replace with the CHTAGPT model ID
temperature = 0.5
max_tokens = 50
metadata = True # Include metadata in the response

response = openai.Completion.create(
engine=model,
prompt=prompt,
temperature=temperature,
max_tokens=max_tokens,
metadata=metadata
)

print(response.choices[0].text) # Print the generated text
print(response.choices[0].metadata) # Print the metadata

error in install_github

I followed the installation instructions and got the error:
`

remotes::install_github("jcrodriguez1989/chatgpt")
Downloading GitHub repo jcrodriguez1989/chatgpt@HEAD
Error in utils::download.file(url, path, method = method, quiet = quiet, :
cannot open URL 'https://api.github.com/repos/jcrodriguez1989/chatgpt/tarball/HEAD'

sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)`

Quoted Exceeded error message

After setting the API key with Sys.setenv(OPENAI_API_KEY = "sk-XXXX" any prompt returns the following error:
image
I've tried a couple of accounts, they all return the same error regardless of user history.

Are there other conditions besides exceeded quota that could trigger this message?

Incorrect formatting of text output.

When calling chatgpt() from R, the text body's formatting is lost. Any line breaks, numbered list or code blocks in the text is gone. The text body includes symbols, such as /n, /n1 and ```, that I presume denotes the aforementioned, respectively. In a Jupyter notebook, I tried changing the output from HTML to Markdown. This will change any code to inline code. Line breaks and lists are still not displayed correctly.

It would be helpful if the function had the ability to return ChatGPT's answer with the correct formatting.

Export API code as new package

Hi,

I was looking for an R package to make the API calls to chatGPT and I came across your package. You package does two things:

  • Pulls data from chatGPT
  • Formats requests so chat GPT can understand them

Would it be possible to separate the first into its own package? I think a lot of R users would be interested in it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.