{"id":14066219,"url":"https://github.com/irudnyts/openai","last_synced_at":"2025-10-22T05:59:12.313Z","repository":{"id":62459202,"uuid":"490662110","full_name":"irudnyts/openai","owner":"irudnyts","description":"An R package-wrapper around OpenAI API","archived":false,"fork":false,"pushed_at":"2024-11-13T12:47:28.000Z","size":2871,"stargazers_count":172,"open_issues_count":34,"forks_count":36,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-10-22T05:59:10.308Z","etag":null,"topics":["api","ml","nlp","openai","package","r"],"latest_commit_sha":null,"homepage":"https://irudnyts.github.io/openai/","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/irudnyts.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","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":"2022-05-10T11:12:59.000Z","updated_at":"2025-10-06T09:38:54.000Z","dependencies_parsed_at":"2024-01-08T23:42:54.559Z","dependency_job_id":"798c4fe6-e9fa-4492-a9a0-f7c8131cc633","html_url":"https://github.com/irudnyts/openai","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/irudnyts/openai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irudnyts%2Fopenai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irudnyts%2Fopenai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irudnyts%2Fopenai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irudnyts%2Fopenai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/irudnyts","download_url":"https://codeload.github.com/irudnyts/openai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irudnyts%2Fopenai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280389299,"owners_count":26322507,"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","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","ml","nlp","openai","package","r"],"created_at":"2024-08-13T07:04:59.669Z","updated_at":"2025-10-22T05:59:12.298Z","avatar_url":"https://github.com/irudnyts.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n## :warning: :warning: :warning: The project is shelved and archived :warning: :warning: :warning:\n\nSince the project has been stalled for more than a year, it has been archived and won't be maintained. There are other amazing packages you can use instead, e.g., [elmer](https://github.com/tidyverse/elmer) by Hadley Wickham and friends. \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 = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# openai \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"120\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/irudnyts/openai/workflows/R-CMD-check/badge.svg)](https://github.com/irudnyts/openai/actions)\n[![Codecov test coverage](https://codecov.io/gh/irudnyts/openai/branch/main/graph/badge.svg)](https://app.codecov.io/gh/irudnyts/openai?branch=main)\n[![CRAN status](https://www.r-pkg.org/badges/version/openai)](https://CRAN.R-project.org/package=openai)\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/grand-total/openai?color=brightgreen)](https://cranlogs.r-pkg.org/badges/grand-total/openai?color=brightgreen)\n\u003c!-- badges: end --\u003e\n\n\u003e :warning: **Note:** :warning: OpenAI introduced major changes in package's version 1.0.0. Since the idea of this package is to mimic OpenAI's official Python package, from now on, everything will be re-written in object-oriented way. Current implementation will be gradually and gently depricated. One can install the development verion using:\n\u003e```\n\u003e remotes::install_github(\"irudnyts/openai\", ref = \"r6\")\n\u003e ```\n\u003e Then, the code will look like:\n\u003e ```\n\u003e library(openai)\n\u003e client \u003c- OpenAI()\n\u003e completion \u003c- client$chat$completions$create(\n\u003e     model = \"gpt-3.5-turbo\",\n\u003e     messages = list(list(\"role\" = \"user\", \"content\" = \"What's up?\"))\n\u003e )\n\u003e ```\n\n## Overview \n\n`{openai}` is an R wrapper of OpenAI API endpoints. This package covers Models, Completions, Chat, Edits, Images, Embeddings, Audio, Files, Fine-tunes, Moderations, and legacy Engines endpoints. The latter endpoints, namely Engines, are left for backward compatibility and will be removed soon.\n\n## Installation\n\nThe easiest way to install `{openai}` from CRAN is to use the \"official\" `install.packages()` function:\n\n```{r, eval = FALSE}\ninstall.packages(\"openai\")\n```\n\nYou can also install the development version of `{openai}` from [GitHub](https://github.com/), which uses the latest version of official OpenAI's Python package:\n\n```{r, eval = FALSE}\nif (!require(remotes))\n    install.packages(\"remotes\")\nremotes::install_github(\"irudnyts/openai\", ref = \"r6\")\n```\n\n## Authentication\n\nTo use the OpenAI API, you need to provide an API key. First, sign up for OpenAI API on [this page](https://openai.com/api/). Once you signed up and logged in, you need to open [this page](https://platform.openai.com), click on **Personal**, and select **View API keys** in drop-down menu. You can then copy the key by clicking on the green text **Copy**.\n\nBy default, functions of `{openai}` will look for `OPENAI_API_KEY` environment variable. If you want to set a global environment variable, you can use the following command (where `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` should be replaced with your actual key):\n\n```{r, eval = FALSE}\nSys.setenv(\n    OPENAI_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'\n)\n```\n\nOtherwise, you can add the key to the `.Renviron` file of the project. The following commands will open `.Renviron` for editing:\n\n```{r, eval = FALSE}\nif (!require(usethis))\n    install.packages(\"usethis\")\n\nusethis::edit_r_environ(scope = \"project\")\n```\n\nYou can add the following line to the file (again, replace `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` with your actual key):\n\n```{r, eval = FALSE}\nOPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Note:** If you are using GitHub/Gitlab, do not forget to add `.Renviron` to `.gitignore`! \n\nFinally, you can always provide the key manually to the functions of the package.\n\n## Example\n\nFunctions of `{openai}` have self-explanatory names. For example, to create a completion, one can use `create_completion()` function:\n\n```{r, eval=FALSE}\nlibrary(openai)\n\ncreate_completion(\n    model = \"ada\",\n    prompt = \"Generate a question and an answer\"\n)\n#\u003e $id\n#\u003e [1] \"cmpl-6MiImjcaCSuQYY6u8UA2Mm0rCdbEo\"\n#\u003e \n#\u003e $object\n#\u003e [1] \"text_completion\"\n#\u003e \n#\u003e $created\n#\u003e [1] 1670871532\n#\u003e \n#\u003e $model\n#\u003e [1] \"ada\"\n#\u003e \n#\u003e $choices\n#\u003e                                                                             text\n#\u003e 1  within 5 minutes, up to an hour depending on how your users are different and\n#\u003e   index logprobs finish_reason\n#\u003e 1     0       NA        length\n#\u003e \n#\u003e $usage\n#\u003e $usage$prompt_tokens\n#\u003e [1] 7\n#\u003e \n#\u003e $usage$completion_tokens\n#\u003e [1] 16\n#\u003e \n#\u003e $usage$total_tokens\n#\u003e [1] 23\n```\n\nFurther, one can generate an image using DALL·E text-to-image model with `create_image()`:\n\n```{r, eval=FALSE}\ncreate_image(\"An astronaut riding a horse in a photorealistic style\")\n```\n\n```{r, echo=FALSE, out.width = \"256px\", fig.align = \"center\"}\nknitr::include_graphics(\"man/figures/astronaut.png\")\n```\n\nIt is also possible to use ChatGPT's `gpt-3.5-turbo` model via `create_chat_completion()`:\n\n```{r, eval=FALSE}\ncreate_chat_completion(\n    model = \"gpt-3.5-turbo\",\n    messages = list(\n        list(\n            \"role\" = \"system\",\n            \"content\" = \"You are a helpful assistant.\"\n        ),\n        list(\n            \"role\" = \"user\",\n            \"content\" = \"Who won the world series in 2020?\"\n        ),\n        list(\n            \"role\" = \"assistant\",\n            \"content\" = \"The Los Angeles Dodgers won the World Series in 2020.\"\n        ),\n        list(\n            \"role\" = \"user\",\n            \"content\" = \"Where was it played?\"\n        )\n    )\n)\n#\u003e $id\n#\u003e [1] \"chatcmpl-6r7N6YXcMhg8xmVM4ohOcAmzPOy3f\"\n#\u003e \n#\u003e $object\n#\u003e [1] \"chat.completion\"\n#\u003e \n#\u003e $created\n#\u003e [1] 1678117740\n#\u003e \n#\u003e $model\n#\u003e [1] \"gpt-3.5-turbo-0301\"\n#\u003e \n#\u003e $usage\n#\u003e $usage$prompt_tokens\n#\u003e [1] 56\n#\u003e \n#\u003e $usage$completion_tokens\n#\u003e [1] 19\n#\u003e \n#\u003e $usage$total_tokens\n#\u003e [1] 75\n#\u003e \n#\u003e \n#\u003e $choices\n#\u003e finish_reason index message.role\n#\u003e 1          stop     0    assistant\n#\u003e message.content\n#\u003e 1 The 2020 World Series was played at Globe Life Field in Arlington, Texas.\n```\n\nFinally, the speech-to-text [Whisper](https://openai.com/research/whisper) is available via `create_transcription()` and `create_translation()`:\n\n```{r, eval=FALSE}\nvoice_sample_ua \u003c- system.file(\"extdata\", \"sample-ua.m4a\", package = \"openai\")\ncreate_translation(file = voice_sample_ua, model = \"whisper-1\")\n#\u003e $text\n#\u003e [1] \"I want to check how this model works\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firudnyts%2Fopenai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firudnyts%2Fopenai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firudnyts%2Fopenai/lists"}