Closed jcrodriguez1989 closed 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.
Code review findings:
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.
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.
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.
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.