jcrodriguez1989 / chatgpt

Interface to ChatGPT from R
GNU General Public License v3.0
316 stars 37 forks source link

Feature: Switch OPENAI's API URL #49

Closed jcrodriguez1989 closed 12 months ago

jcrodriguez1989 commented 12 months ago

As requested in https://github.com/jcrodriguez1989/chatgpt/issues/48 , we need to be able to allow switching OPENAI's API URL. This is now possible by setting the OPENAI_API_URL env variable.

github-actions[bot] commented 12 months ago

Thank you for sharing the GitHub pull request file. I will perform a code review to identify any issues.

In the code snippet provided, I noticed the following issue:

In the file "R/gpt_get_completions.R" on line 65, the URL for the POST request is hardcoded as "https://api.openai.com/v1/chat/completions". It is recommended to use the api_url variable instead to allow flexibility in changing the API URL. This can be fixed by replacing the hardcoded URL with paste0(api_url, "/chat/completions").

That is the only issue I found in the code snippet you shared.

github-actions[bot] commented 12 months ago

Code review findings:

  1. In R/chatgpt-package.R, line 14, it seems that api_url is being initialized in a non-standard way. It is recommended to use the ifelse function to check if the environment variable is set, and then assign the default value if it is not.

  2. In R/gpt_get_completions.R, line 65, where the API endpoint URL is constructed, it is good practice to include a trailing slash (/) after the base URL. This ensures consistency in the URL format and prevents unexpected behavior.

  3. In README.Rmd and README.md, the example usage of setting the OPENAI_API_URL environment variable should be updated to use the correct URL format. The current example (https://api.chatanywhere.com.cn) appears to be fictional.

Please make the necessary changes based on the above recommendations.