{"id":27598143,"url":"https://github.com/sulmanweb/openai_chatgpt","last_synced_at":"2025-06-14T13:32:55.158Z","repository":{"id":117371718,"uuid":"610232722","full_name":"sulmanweb/openai_chatgpt","owner":"sulmanweb","description":"OpenAI ChatGPT unofficial Ruby wrapper Gem","archived":false,"fork":false,"pushed_at":"2023-04-07T01:59:13.000Z","size":28,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-15T05:29:09.503Z","etag":null,"topics":["gem","ruby","ruby-gem","ruby-on-rails","rubygem","rubygems"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/openai_chatgpt","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sulmanweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","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":"2023-03-06T11:11:26.000Z","updated_at":"2024-01-17T17:10:59.000Z","dependencies_parsed_at":"2023-04-20T14:01:37.753Z","dependency_job_id":null,"html_url":"https://github.com/sulmanweb/openai_chatgpt","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"2361c429c4bbad3588df543f63e8544e51f92b02"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulmanweb%2Fopenai_chatgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulmanweb%2Fopenai_chatgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulmanweb%2Fopenai_chatgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulmanweb%2Fopenai_chatgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sulmanweb","download_url":"https://codeload.github.com/sulmanweb/openai_chatgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250255788,"owners_count":21400410,"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":["gem","ruby","ruby-gem","ruby-on-rails","rubygem","rubygems"],"created_at":"2025-04-22T14:12:28.637Z","updated_at":"2025-04-22T14:12:29.388Z","avatar_url":"https://github.com/sulmanweb.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/openai_chatgpt.svg)](https://badge.fury.io/rb/openai_chatgpt)\n\n# OpenaiChatgpt\n\nOpenAI ChatGPT API is a light-weight Ruby wrapper for the Rubyists. It gives nice struct objects for completions of the chatgpt, even the raw responses are returned in nice open struct objects. It uses Faraday for HTTP requests.\n\n\u003e It supports all models of gpt-4 and gpt-3.5\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add openai_chatgpt\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install openai_chatgpt\n\n---\n\n## Usage\n\n### API Documentation\n\nThe API documentation can be found at [https://platform.openai.com/docs/api-reference/chat/create](https://platform.openai.com/docs/api-reference/chat/create).\n\n### Get an API key\nYou can get API for the chatgpt by doing the following [here](https://platform.openai.com/account/api-keys).\n\n### Configuration\n\n```ruby\nrequire 'openai_chatgpt'\nclient = OpenaiChatgpt::Client.new(api_key: ENV['CHATGPT_API_KEY'])\n```\nParams:\n- `api_key`: String - Required - The API key for the openai chatgpt api.\n\nResponse:\n```ruby\n#\u003cOpenaiChatgpt::Client:0x00000001055fc318 @adapter=:net_http, @api_key=\"YOUR_API_KEY\", @stubs=nil\u003e\n```\n\n### Get completion text\n\n```ruby\nresp = OpenaiChatgpt::Client.new(api_key: \"fake\").completions(\n  messages: [\n    {role: \"user\", content: \"Hello, how are you?\"},\n    {role: \"assistant\", content: \"I am good, how are you?\"},\n    {role: \"user\", content: \"What is your name?\"},\n  ]\n)\n```\nParams:\n- messages: Array[String] - Required - Messages to generate response for\n   `[{role: \"user\", text: \"Hello\"}, {role: \"bot\", text: \"Hi\"}]`\n- model: String - Optional - Default: \"gpt-4\" - Model to use for generating response\n   [\"gpt-4\", \"gpt-4-0314\", \"gpt-4-32k\", \"gpt-4-32k-0314\", \"gpt-3.5-turbo\", \"gpt-3.5-turbo-0301\"]\n- temperature: Float - Optional - Default: 1.0 - Temperature for response generation between 0.0 and 2.0\n- top_p: Float - Optional - Default: 1.0 - Top p for response generation between 0.0 and 1.0\n- n: Integer - Optional - Default: 1 - Number of responses to generate\n- stream: Boolean - Optional - Default: false - Stream response\n- stop: Array[String] - Optional - Default: nil - Stop sequence for response generation\n- max_tokens: Integer - Optional - Default: 4096 - Maximum number of tokens to generate\n- presence_penalty: Float - Optional - Default: 0.0 - Presence penalty for response generation between -2.0 and 2.0\n- frequency_penalty: Float - Optional - Default: 0.0 - Frequency penalty for response generation between\n   -2.0 and 2.0\n- logit_bias: Hash - Optional - Default: nil - Logit bias for response generation\n- user: String - Optional - Default: nil - User for response generation\n\nResponse:\n```ruby\nresp.results\n=\u003e [#\u003cOpenaiChatgpt::Choice:0x0000000107abca68 @content=\"I am an AI language model created by Open\", @index=0, @role=\"assistant\"\u003e]\n```\n```ruby\nresp.usage\n=\u003e #\u003cOpenaiChatgpt::Usage:0x0000000107aba808 @completion_tokens=10, @prompt_tokens=36, @total_tokens=46\u003e\n```\n\n\u003e Also `raw_response` is available if you want the raw response from the API. This is useful if you want to do something with the raw response. Also that response is in OpenStruct Object which is a nice wrapper for the raw response and you can use 'dot' notation.\n\n### Error Handling\n\n```ruby\nbegin\n  client.completions(messages: [{role: \"user\", text: \"Hello, how are you?\"}]) # this should be content instead of text\nrescue OpenaiChatgpt::Error =\u003e e\n  puts e.message\nend\n```\n\n---\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sulmanweb/openai_chatgpt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sulmanweb/openai_chatgpt/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the OpenaiChatgpt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sulmanweb/openai_chatgpt/blob/main/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsulmanweb%2Fopenai_chatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsulmanweb%2Fopenai_chatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsulmanweb%2Fopenai_chatgpt/lists"}