我想从R中使用以下curl命令访问OpenAI API:
curl https://api.openai.com/v1/engines/davinci/completions \-H "Content-Type: application/json" \-H "Authorization: Bearer YOUR_API_KEY" \-d '{"prompt": "This is a test", "max_tokens": 5}'
我认为CRAN上的curl包可能是最好的选择(?)。我从未使用过这个包,所以有谁能帮我开始使用这个简单的调用吗?
回答:
我创建了一个名为”openapi”的R包(https://github.com/zhanghao-njmu/openapi),它支持所有OpenAI API,并且可以生成流式返回(目前,其他包没有好的解决方案),还有chatGPT应用程序和各种RStudio插件。欢迎使用。