{"id":13428012,"url":"https://github.com/drnic/ruby-chatgpt-plugin-random-numbers","last_synced_at":"2025-04-14T13:56:37.207Z","repository":{"id":152433547,"uuid":"624677227","full_name":"drnic/ruby-chatgpt-plugin-random-numbers","owner":"drnic","description":"This Ruby/Sinatra app is a ChatGPT plugin that provides a random number.","archived":false,"fork":false,"pushed_at":"2023-04-07T10:29:02.000Z","size":1576,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-28T03:01:40.743Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/drnic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-04-07T02:14:12.000Z","updated_at":"2023-06-19T00:10:05.000Z","dependencies_parsed_at":"2024-01-13T23:18:45.497Z","dependency_job_id":"a7d7441a-0223-4b4b-90eb-b5b8fec9ccaa","html_url":"https://github.com/drnic/ruby-chatgpt-plugin-random-numbers","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/drnic%2Fruby-chatgpt-plugin-random-numbers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fruby-chatgpt-plugin-random-numbers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fruby-chatgpt-plugin-random-numbers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drnic%2Fruby-chatgpt-plugin-random-numbers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drnic","download_url":"https://codeload.github.com/drnic/ruby-chatgpt-plugin-random-numbers/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248893222,"owners_count":21178973,"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-07-31T01:00:44.249Z","updated_at":"2025-04-14T13:56:37.178Z","avatar_url":"https://github.com/drnic.png","language":"Ruby","funding_links":[],"categories":["Tutorials"],"sub_categories":[],"readme":"# Sample ChatGPT plugin in Ruby\n\nThis Ruby/Sinatra app is a ChatGPT plugin that provides a random number.\n\n## Example usage\n\n![demo1](docs/demo1.png)\n\n![demo2](docs/demo2.png)\n\n![demo3](docs/demo3.png)\n\n![demo4](docs/demo4.png)\n\n![demo5](docs/demo5.png)\n\n## Run locally and test on ChatGPT\n\nTo start up the application and bind to port 9292:\n\n```plain\nbundle\nrerun rackup\n```\n\nYou will need to expose the application to the internet. I use \u003chttps://ngrok.com/\u003e.\n\n```plain\nngrok http --region=au 9292\n```\n\nThe output shows you your domain\n\n```plain\nSession Status                online\nRegion                        Australia (au)\nForwarding                    https://e92baeb18b8a.ngrok.app -\u003e http://localhost:9292\n```\n\nThe domain `e92baeb18b8a.ngrok.app` will be passed to ChatGPT when we register the plugin.\n\n## Register plugin with ChatGPT\n\nOpen \u003chttps://chat.openai.com/chat\u003e, and switch to the ChatGPT \"Plugins\" model.\n\n![setup-model-plugins](docs/setup-model-plugins.png)\n\nNext, under the Plugins dropdown, select \"Plugin Store\".\n\n![setup-open-plugin-store](docs/setup-open-plugin-store.png)\n\nAt the bottom of the modal, click on **\"Develop your own plugin\"**.\n\nClick the green **\"My manifest is ready\"** button.\n\nCopy your ngrok domain `e92baeb18b8a.ngrok.app` into the form, and click the green \"Find manifest file\" button.\n\nChatGPT will validate the two manifest files. Click the green **Next** button.\n\n![setup-validate-manifests](docs/setup-validate-manifests.png)\n\nNext, click **Install for me**, then **Continue**, then **Install plugin**.\n\n## Testing the plugin\n\nTry the prompts:\n\n* Generate two random numbers\n* Add three random numbers together and say the answer in English\n* Create a rectangular prism with random sides, each between 10 and 30 cm in length\n* Or the other examples above\n\n![testing-example-prompts](docs/testing-example-prompts.png)\n\n## Implementation\n\nThe Sinatra app provides a `POST /random` endpoint that returns `{random_number: 35}` or similar.\n\n```plain\nexport DOMAIN=e92baeb18b8a.ngrok.app\ncurl \"https://$DOMAIN/random\" -d '{}'\n```\n\nYou can also pass `min` or `max` to override the defaults of 0 and 100 respectively.\n\n```plain\n$ curl \"https://$DOMAIN/random\" -d '{\"min\":10,\"max\":20}'\n{\"random_number\":15}\n```\n\nBut ChatGPT Plugins doesn't know the details of this API until we tell it. When you register ChatGPT it fetches two files from our plugin.\n\nThe high-level plugin definition:\n\n```plain\ncurl \"https://$DOMAIN/.well-known/ai-plugin.json\"\n```\n\nAnd the description of our `POST /random` endpoint:\n\n```plain\ncurl \"https://$DOMAIN/.well-known/openapi.yaml\"\n```\n\nThe source files are within this repo's `.well-known` folder, but our `app.rb` sinatra script loads them, replaces `DOMAIN` with our `$DOMAIN` ngrok domain, and returns the modified file.\n\n## Writing your own openapi.yaml file\n\nI actually asked GPT-4 to write my file:\n\n\u003e Create an openapi.yaml for a service that has a POST /random endpoint that returns single integer which is a random number\n\nThrough debugging, I needed to manually change the result a little bit to add `operationId: query_query_post` to my `/random` `paths` entry.\n\nAnd then I asked GPT-4 to write the initial Sinatra app:\n\n\u003e Create a ruby sinatra app.rb that implements this endpoint\n\nAnd I was half way there. Good times.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrnic%2Fruby-chatgpt-plugin-random-numbers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrnic%2Fruby-chatgpt-plugin-random-numbers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrnic%2Fruby-chatgpt-plugin-random-numbers/lists"}