{"id":13645524,"url":"https://github.com/samterfa/openai","last_synced_at":"2025-04-21T14:31:30.882Z","repository":{"id":63932730,"uuid":"432828660","full_name":"samterfa/openai","owner":"samterfa","description":"This R package provides an SDK to the Open AI API","archived":false,"fork":false,"pushed_at":"2024-02-10T19:41:02.000Z","size":873,"stargazers_count":134,"open_issues_count":4,"forks_count":19,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-08-02T01:25:29.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samterfa.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-28T21:25:06.000Z","updated_at":"2024-05-31T04:36:42.000Z","dependencies_parsed_at":"2023-11-07T22:52:12.933Z","dependency_job_id":"ce808da9-d349-435f-a557-006eb8408abe","html_url":"https://github.com/samterfa/openai","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samterfa%2Fopenai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samterfa%2Fopenai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samterfa%2Fopenai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samterfa%2Fopenai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samterfa","download_url":"https://codeload.github.com/samterfa/openai/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223868326,"owners_count":17217072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:36.512Z","updated_at":"2024-11-09T18:31:38.958Z","avatar_url":"https://github.com/samterfa.png","language":"R","funding_links":[],"categories":["Openai","R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = T,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# openai\n\n\u003c!-- badges: start --\u003e\n\n\u003c!-- badges: end --\u003e\n\nThe openai package provides R scripts to use the [Open AI API](https://platform.openai.com/docs/api-reference/). In order to get started you will need to sign up for an account at [https://openai.com/](https://openai.com/). You will also need to set up billing to use the API.\n\n## Installation\n\nYou can install the development version of openai from [GitHub](https://github.com/samterfa/openai) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"samterfa/openai\")\n```\n\n## Set Up\n\nAPI calls are authenticated using your [API keys](https://beta.openai.com/account/api-keys). The environment variables set below are consulted while making each call.\n\n```{r, eval=F}\nSys.setenv(openai_organization_id = {your_organization_id})\nSys.setenv(openai_secret_key = {your_secret_key})\n```\n\nMore details on authentication can be found [here](https://platform.openai.com/docs/api-reference/authentication).\n\n## Examples\n\n#### Retrieve the currently available models used to generate text.\n\n```{r}\nlibrary(openai)\n\nlist_models()$data %\u003e% \n  dplyr::bind_rows()\n```\n\n#### Create a completion request using the davinci engine.\n\n```{r, tidy=TRUE, tidy.opts=list(width.cutoff=60)}\ncreate_chat_completion(\n  model = 'gpt-3.5-turbo', \n  messages = \n    list(\n      list(role = 'system', content = 'You are a helpful assistant.'),\n      list(role = 'user', content = 'Who won the world series in 2020?'),\n      list(role = 'assistant', content = 'The Los Angeles Dodgers won the world series in 2020.'),\n      list(role = 'user', content = 'Where was it played?')\n    )\n)$choices[[1]]$message$content\n```\n\n#### Generate an image based on a prompt.\n\n```{r}\nimg_url \u003c-\n  create_image(\n    model = 'dall-e-3',\n    prompt = 'a white siamese cat', \n    n = 1, \n    size = '1024x1024')$data[[1]]$url\n\nknitr::include_graphics(img_url)\n```\n\n#### NEW! Ask a question about an image.\n\n```{r}\nopenai::create_chat_completion(\n  model = 'gpt-4-vision-preview',\n  messages = list(\n    list(role = 'user', \n         content = list(\n           list(\n             type = 'text',\n             text = 'What is this a picture of?'\n           ),\n           list(\n             type = 'image_url',\n             image_url = list(\n               url = img_url\n             )\n           )\n         )\n    )\n  ), \n  max_tokens = 1000\n)$choices[[1]]$message$content\n```\n\n#### Use the included addin to code collaboratively with a model.\n\n![](addin_demo_1.gif)\n\nAccess it via the Addins menu, or by Tools -\\\u003e Addins -\\\u003e Browse Addins. Search for \"openai\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamterfa%2Fopenai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamterfa%2Fopenai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamterfa%2Fopenai/lists"}