{"id":14955806,"url":"https://github.com/rubyonai/chatgpt-ruby","last_synced_at":"2025-11-11T18:23:01.244Z","repository":{"id":145806916,"uuid":"617457583","full_name":"rubyonai/chatgpt-ruby","owner":"rubyonai","description":"🤖💎 ChatGPT Ruby – a simple gem for accessing the OpenAI API","archived":false,"fork":false,"pushed_at":"2025-09-12T18:59:03.000Z","size":114,"stargazers_count":40,"open_issues_count":6,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T05:59:17.515Z","etag":null,"topics":["ai","chatgpt","openai","rails-api","ruby","rubygem","rubyonrails","sinatra"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubyonai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-22T12:43:09.000Z","updated_at":"2025-09-12T19:01:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d6110c4-41c2-4e6e-9959-23fa00d1437e","html_url":"https://github.com/rubyonai/chatgpt-ruby","commit_stats":{"total_commits":55,"total_committers":2,"mean_commits":27.5,"dds":"0.018181818181818188","last_synced_commit":"cd4a3e83cbaa1076bdd6724013ae03411aac0719"},"previous_names":["rubyonai/chatgpt-ruby","nagstler/chatgpt-ruby"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/rubyonai/chatgpt-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyonai%2Fchatgpt-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyonai%2Fchatgpt-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyonai%2Fchatgpt-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyonai%2Fchatgpt-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubyonai","download_url":"https://codeload.github.com/rubyonai/chatgpt-ruby/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyonai%2Fchatgpt-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283906754,"owners_count":26914696,"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-11-11T02:00:06.610Z","response_time":65,"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":["ai","chatgpt","openai","rails-api","ruby","rubygem","rubyonrails","sinatra"],"created_at":"2024-09-24T13:11:49.781Z","updated_at":"2025-11-11T18:23:01.207Z","avatar_url":"https://github.com/rubyonai.png","language":"Ruby","readme":"# ChatGPT Ruby\n\n\u003ca href=\"https://badge.fury.io/rb/chatgpt-ruby\"\u003e\u003cimg src=\"https://img.shields.io/gem/v/chatgpt-ruby?style=for-the-badge\" alt=\"Gem Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow?style=for-the-badge\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codeclimate.com/github/nagstler/chatgpt-ruby/test_coverage\"\u003e\u003cimg src=\"https://img.shields.io/codeclimate/coverage/nagstler/chatgpt-ruby?style=for-the-badge\" alt=\"Test Coverage\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/nagstler/chatgpt-ruby/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/nagstler/chatgpt-ruby/ci.yml?branch=main\u0026style=for-the-badge\" alt=\"CI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/nagstler/chatgpt-ruby/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/nagstler/chatgpt-ruby?style=for-the-badge\" alt=\"GitHub stars\"\u003e\u003c/a\u003e\n\n🤖💎 A lightweight Ruby wrapper for the OpenAI API, designed for simplicity and ease of integration.\n\n## Features\n\n- API integration for chat completions and text completions\n- Streaming capability for handling real-time response chunks\n- Custom exception classes for different API error types\n- Configurable timeout, retries and default parameters\n- Complete test suite with mocked API responses\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Configuration](#configuration)\n- [Rails Integration](#rails-integration)\n- [Error Handling](#error-handling)\n- [Current Capabilities](#current-capabilities)\n  - [Chat Completions](#chat-completions)\n  - [Text Completions](#text-completions)\n- [Roadmap](#roadmap)\n- [Development](#development)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nAdd to your Gemfile:\n\n```ruby\ngem 'chatgpt-ruby'\n```\n\nOr install directly:\n\n```bash\n$ gem install chatgpt-ruby\n```\n\n## Quick Start\n\n```ruby\nrequire 'chatgpt'\n\n# Initialize with API key\nclient = ChatGPT::Client.new(ENV['OPENAI_API_KEY'])\n\n# Chat API (Recommended for GPT-3.5-turbo, GPT-4)\nresponse = client.chat([\n  { role: \"user\", content: \"What is Ruby?\" }\n])\n\nputs response.dig(\"choices\", 0, \"message\", \"content\")\n\n# Completions API (For GPT-3.5-turbo-instruct)\nresponse = client.completions(\"What is Ruby?\")\nputs response.dig(\"choices\", 0, \"text\")\n\n```\n\n## Rails Integration\n\nIn a Rails application, create an initializer:\n\n```ruby\n# config/initializers/chat_gpt.rb\nrequire 'chatgpt'\n\nChatGPT.configure do |config|\n  config.api_key = Rails.application.credentials.openai[:api_key]\n  config.default_engine = 'gpt-3.5-turbo'\n  config.request_timeout = 30\nend\n```\nThen use it in your controllers or services:\n\n```ruby\n# app/services/chat_gpt_service.rb\nclass ChatGPTService\n  def initialize\n    @client = ChatGPT::Client.new\n  end\n  \n  def ask_question(question)\n    response = @client.chat([\n      { role: \"user\", content: question }\n    ])\n    \n    response.dig(\"choices\", 0, \"message\", \"content\")\n  end\nend\n\n# Usage in controller\ndef show\n  service = ChatGPTService.new\n  @response = service.ask_question(\"Tell me about Ruby on Rails\")\nend\n```\n\n## Configuration\n\n```ruby\nChatGPT.configure do |config|\n  config.api_key = ENV['OPENAI_API_KEY']\n  config.api_version = 'v1'\n  config.default_engine = 'gpt-3.5-turbo'\n  config.request_timeout = 30\n  config.max_retries = 3\n  config.default_parameters = {\n    max_tokens: 16,\n    temperature: 0.5,\n    top_p: 1.0,\n    n: 1\n  }\nend\n```\n\n## Error handling\n\n```ruby\nbegin\n  response = client.chat([\n    { role: \"user\", content: \"Hello!\" }\n  ])\nrescue ChatGPT::AuthenticationError =\u003e e\n  puts \"Authentication error: #{e.message}\"\nrescue ChatGPT::RateLimitError =\u003e e\n  puts \"Rate limit hit: #{e.message}\"\nrescue ChatGPT::InvalidRequestError =\u003e e\n  puts \"Bad request: #{e.message}\"\nrescue ChatGPT::APIError =\u003e e\n  puts \"API error: #{e.message}\"\nend\n```\n\n## Current Capabilities\n\n### Chat Completions\n```ruby\n# Basic chat\nresponse = client.chat([\n  { role: \"user\", content: \"What is Ruby?\" }\n])\n\n# With streaming\nclient.chat_stream([{ role: \"user\", content: \"Tell me a story\" }]) do |chunk|\n  print chunk.dig(\"choices\", 0, \"delta\", \"content\")\nend\n```\n\n### Text Completions\n```ruby\n# Basic completion with GPT-3.5-turbo-instruct\nresponse = client.completions(\"What is Ruby?\")\nputs response.dig(\"choices\", 0, \"text\")\n```\n\n## Roadmap\n\nWhile ChatGPT Ruby is functional, there are several areas planned for improvement:\n\n- [ ] Response object wrapper \u0026 Rails integration with Railtie (v2.2)\n- [ ] Token counting, function calling, and rate limiting (v2.3)\n- [ ] Batch operations and async support (v3.0)\n- [ ] DALL-E image generation and fine-tuning (Future)\n\n❤️ Contributions in any of these areas are welcome!\n\n## Development\n\n```bash\n# Run tests\nbundle exec rake test\n\n# Run linter\nbundle exec rubocop\n\n# Generate documentation\nbundle exec yard doc\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b feature/my-new-feature`)\n3. Add tests for your feature\n4. Make your changes\n5. Commit your changes (`git commit -am 'Add some feature'`)\n6. Push to the branch (`git push origin feature/my-new-feature`)\n7. Create a new Pull Request\n\n## License\n\nReleased under the MIT License. See [LICENSE](LICENSE.txt) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonai%2Fchatgpt-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonai%2Fchatgpt-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonai%2Fchatgpt-ruby/lists"}