{"id":18410967,"url":"https://github.com/analyticsinmotion/chatgpt-python-wrapper","last_synced_at":"2025-10-15T15:44:10.018Z","repository":{"id":142257605,"uuid":"586737804","full_name":"analyticsinmotion/chatgpt-python-wrapper","owner":"analyticsinmotion","description":"Python wrapper to access ChatGPT","archived":false,"fork":false,"pushed_at":"2023-10-23T05:02:59.000Z","size":8277,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T16:52:51.470Z","etag":null,"topics":["analytics-in-motion","chatgpt","chatgpt-api-wrapper","chatgpt-image-generation","chatgpt-moderation","chatgpt-text-completion","python","python-wrapper","python3"],"latest_commit_sha":null,"homepage":"https://www.analyticsinmotion.com","language":"Python","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/analyticsinmotion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-01-09T05:22:53.000Z","updated_at":"2024-08-13T05:43:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e0e6c88-f71c-4139-9cb4-339216cc9061","html_url":"https://github.com/analyticsinmotion/chatgpt-python-wrapper","commit_stats":{"total_commits":60,"total_committers":1,"mean_commits":60.0,"dds":0.0,"last_synced_commit":"c8e28227699dbe4f2b8f2abc612e936c8acbf39d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analyticsinmotion%2Fchatgpt-python-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analyticsinmotion%2Fchatgpt-python-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analyticsinmotion%2Fchatgpt-python-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analyticsinmotion%2Fchatgpt-python-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/analyticsinmotion","download_url":"https://codeload.github.com/analyticsinmotion/chatgpt-python-wrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247637420,"owners_count":20971123,"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":["analytics-in-motion","chatgpt","chatgpt-api-wrapper","chatgpt-image-generation","chatgpt-moderation","chatgpt-text-completion","python","python-wrapper","python3"],"created_at":"2024-11-06T03:34:41.113Z","updated_at":"2025-10-15T15:44:04.977Z","avatar_url":"https://github.com/analyticsinmotion.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChatGPT – Python Wrapper\nPython wrapper to access OpenAI's ChatGPT functionality.\n\u003cbr /\u003e\u003cbr /\u003e\n\n[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg?style=badge\u0026logo=python\u0026logoColor=ffdd54)](https://www.python.org/downloads/release/python-3111/)\u0026nbsp;\u0026nbsp;\n[![ChatGPT](https://img.shields.io/badge/ChatGPT-74aa9c?style=badge\u0026logo=openai\u0026logoColor=white)](https://chat.openai.com)\u0026nbsp;\u0026nbsp;\n[![PEP8](https://img.shields.io/badge/code%20style-PEP8-green.svg?style=badge)](https://www.python.org/dev/peps/pep-0008/)\u0026nbsp;\u0026nbsp;\n[![MIT license](https://img.shields.io/badge/License-MIT-orange.svg?style=badge)](https://mit-license.org/)\u0026nbsp;\u0026nbsp;\n[![action](https://img.shields.io/badge/CodeQL-passing-green.svg?style=badge\u0026logo=github\u0026logoColor=959da4)](https://github.com/analyticsinmotion/chatgpt-python-wrapper/actions)\u0026nbsp;\u0026nbsp;\n[![OpenAI](https://img.shields.io/badge/OpenAI-000000?style=badge\u0026logo=openai\u0026logoColor=white)](https://openai.com)\u0026nbsp;\u0026nbsp;\n[![Analytics in Motion](https://raw.githubusercontent.com/analyticsinmotion/.github/main/assets/images/analytics-in-motion-github-badge-rounded.svg)](https://www.analyticsinmotion.com)\u0026nbsp;\u0026nbsp;\n\n\u003cbr /\u003e\n\n\u003c!-- DESCRIPTION --\u003e\n## 1. Description\nThis project contains a number of test scripts that provide access to OpenAI's ChatGPT models (text, image).\n### 1.1 ChatGPT Text Completions\nFor the ChatGPT text function a user will be requested to enter their text prompt, question or scenario. The resulting answer will be output on the screen. In addition, the output_to_file flag can be changed to output the text prompt, question, scenario, ChatGPT response and associated metadata in a JSON file.\n### 1.2 ChatGPT Image Generator\nFor the ChatGPT image function a user will be requested to enter a description of the image they want created. The resulting image will be created and downloaded. In addition, the output_to_file flag can be changed to output the associated metadata in a JSON file.\n### 1.3 ChatGPT Moderation\nAll user input will be analyzed to ensure it complies with [OpenAI's Content Policy](https://labs.openai.com/policies/content-policy). Any input that is flagged for hate, threats, self-harm, sexual, or violent will not be passed to our text completion or image generator functions. The output_to_file flag can be changed to output the associated metadata in a JSON file for all input requests, regardless of whether they are flagged as in violation or not.\n\u003cbr /\u003e\u003cbr /\u003e\n\n\u003c!-- GETTING STARTED --\u003e\n## 2. Getting Started\n### 2.1 Dependencies\n- Requires an OpenAI API Key\n- Requires the following Modules:\n  - os (makes interaction with the local file system simpler)\n  - json (in-built package to create, store, convert json objects)\n  - openai (\u003ca href=\"https://github.com/openai/openai-python\"\u003ehttps://github.com/openai/openai-python\u003c/a\u003e)\n  - dotenv (\u003ca href=\"https://pypi.org/project/python-dotenv/\"\u003ehttps://pypi.org/project/python-dotenv/\u003c/a\u003e)\n  - re (to enable the use of regular expressions)\n  - requests (to request images from the web)\n  - shutil (to save images locally)\n  - hashlib (create simple file IDs for images)\n  \nPlease be aware of the [costs](https://openai.com/pricing) associated with using the OpenAI API when utilizing this project.\n\n### 2.2 Installing\n- Create an account and get API Key at \u003ca href=\"https://chat.openai.com\"\u003ehttps://chat.openai.com\u003c/a\u003e\n- Add the API Key to the openai-credentials.env file\n\n### 2.3 Executing Program\n- Run the main.py file\n\u003cbr /\u003e\u003cbr /\u003e\n\n\u003c!-- DIRECTORY STRUCTURE --\u003e\n## 3. Directory Structure\n\n    ChatGPT\n    ├── output_chatgpt_images           # Directory\n    │   ├── images                      # Directory\n    ├── output_chatgpt_moderation       # Directory    \n    ├── output_chatgpt_text             # Directory\n    ├── chatgpt_images.py               # File\n    ├── chatgpt_moderation.py           # File\n    ├── chatgpt_text.py                 # File\n    ├── main.py                         # File\n    ├── openai_credentials.env          # File\n    ├── LICENSE.md                      # File\n    └── README.md                       # File\n\u003cbr /\u003e\n\n\u003c!-- INSTRUCTIONS --\u003e\n## 4. Instructions\n\n### 4.1 Text Completion Example\n\nInput Prompt:\n```text\nWhat are the top 5 emerging AI trends?\n```\nResponse:\n```text\n1. Autonomous Vehicles: Autonomous vehicles are becoming increasingly popular and are expected to become a major part of the transportation landscape by 2023. Autonomous vehicles are expected to become commonplace in cities, allowing for faster and more efficient transportation.\n\n2. Smart Cities: Smart cities are cities that use technology to improve the lives of their citizens. This includes things like self-driving cars, smart energy grids, and automated waste management systems.\n\n3. AI-Powered Healthcare: AI-powered healthcare solutions are becoming more popular as they can help diagnose and treat illnesses more accurately and quickly. AI-powered healthcare solutions are expected to become more widespread in the next few years, allowing for more efficient and accurate healthcare.\n\n4. Natural Language Processing: Natural language processing (NLP) is the ability of a computer to understand human language. NLP is becoming more popular and is being used in applications such as voice assistants and customer service chatbots.\n\n5. Edge Computing: Edge computing is the use of computing resources that are located close to the user, such as on the user's device or in the cloud. Edge computing allows for faster and more efficient processing of data, which is becoming increasingly important as data becomes more complex. \n```\n\n\n### 4.2 Image Generation Example\n\nInput Prompt:\n```text\nlandscape painting with water and trees\n```\nResponse:\n\n\u003cimg src=\"/output_chatgpt_images/images/img-hx959DWtE7QaZ8CWbSph0xo7.png\" width=65% height=65%\u003e\n\u003cbr /\u003e\n\n\n### 4.3 Moderation Example\n\nInput Prompt:\n```text\nI want to kill them.\n```\nResponse:\n```text\n(True, ['hate/threatening', 'violence'])\n```\n\u003cbr /\u003e\u003cbr /\u003e\n\n\u003c!-- JSON OUTPUT FILES --\u003e\n## 5. JSON Output Files (Optional)\n\n### 5.1 Text Completion Example\nSet the \u003cb\u003eoutput_to_file\u003c/b\u003e flag to True in the chatgpt_text function in order to generate the a JSON output file for each request.\n```text\nchatgpt_text(prompt, output_to_file=True)\n```\n\u003cbr /\u003e\n\nJSON Response:\n```text\n{\n    \"id\": \"cmpl-6WendmCVAliTTdQZCvh9MQBsrkin2\",\n    \"object\": \"text_completion\",\n    \"created\": 1673241349,\n    \"model\": \"text-davinci-003\",\n    \"choices\": [\n        {\n            \"text\": \"\\n\\nNo, Pluto is no longer considered a planet. It is now classified as a dwarf planet.\",\n            \"index\": 0,\n            \"logprobs\": null,\n            \"finish_reason\": \"stop\"\n        }\n    ],\n    \"usage\": {\n        \"prompt_tokens\": 5,\n        \"completion_tokens\": 21,\n        \"total_tokens\": 26\n    },\n    \"parameters\": [\n        {\n            \"prompt\": \"Is Pluto a planet?\",\n            \"max_tokens\": 2048,\n            \"temperature\": 0.5,\n            \"top_p\": 1,\n            \"frequency_penalty\": 0,\n            \"presence_penalty\": 0,\n            \"n\": 1\n        }\n    ]\n}\n```\n\n### 5.2 Image Generation Example\nSet the \u003cb\u003eoutput_to_file\u003c/b\u003e flag to True in the chatgpt_images function in order to generate the a JSON output file for each request.\n```text\nchatgpt_images(prompt, output_to_file=True)\n```\n\u003cbr /\u003e\n\nJSON Response:\n```text\n{\n    \"created\": 1673589687,\n    \"data\": [\n        {\n            \"url\": \"https://oaidalleapiprodscus.blob.core.windows.net/private/org-XXXXXXXXXXXXXXXXXXXXXXXX/user-XXXXXXXXXXXXXXXXXXXXXXXX/img-hx959DWtE7QaZ8CWbSph0xo7.png?st=2023-01-13T05%3A01%3A27Z\u0026se=2023-01-13T07%3A01%3A27Z\u0026sp=r\u0026sv=2021-08-06\u0026sr=b\u0026rscd=inline\u0026rsct=image/png\u0026skoid=6aaadede-4fb3-4698-a8f6-684d7786b067\u0026sktid=a48cca56-e6da-484e-a814-9c849652bcb3\u0026skt=2023-01-13T00%3A13%3A40Z\u0026ske=2023-01-14T00%3A13%3A40Z\u0026sks=b\u0026skv=2021-08-06\u0026sig=nf9r9g20TYpxORNGKy3zT82atGsoAy/Q22sJrLTDKUE%3D\"\n        }\n    ],\n    \"_response_ms\": 5705,\n    \"parameters\": [\n        {\n            \"prompt\": \"landscape painting with water and trees\",\n            \"size\": \"1024x1024\",\n            \"n\": 1\n        }\n    ],\n    \"ids\": [\n        \"img-hx959DWtE7QaZ8CWbSph0xo7\"\n    ]\n}\n```\n\n\n### 5.3 Moderation Example\nSet the \u003cb\u003eoutput_to_file\u003c/b\u003e flag to True in the chatgpt_moderation function in order to generate the a JSON output file for each request.\n```text\nchatgpt_moderation('I want to kill them.', output_to_file=True)\n```\n\u003cbr /\u003e\n\nJSON Response:\n```text\n{\n    \"id\": \"modr-6Yu9h3Lz1mwNdfQLMmynkROTAynjF\",\n    \"model\": \"text-moderation-001\",\n    \"results\": [\n        {\n            \"categories\": {\n                \"hate\": false,\n                \"hate/threatening\": true,\n                \"self-harm\": false,\n                \"sexual\": false,\n                \"sexual/minors\": false,\n                \"violence\": true,\n                \"violence/graphic\": false\n            },\n            \"category_scores\": {\n                \"hate\": 0.22702568769454956,\n                \"hate/threatening\": 0.4133393466472626,\n                \"self-harm\": 0.005232803523540497,\n                \"sexual\": 0.01407555304467678,\n                \"sexual/minors\": 0.0038546782452613115,\n                \"violence\": 0.922382652759552,\n                \"violence/graphic\": 0.036863770335912704\n            },\n            \"flagged\": true\n        }\n    ],\n    \"_response_ms\": 136,\n    \"parameters\": [\n        {\n            \"input\": \"I want to kill them.\",\n            \"model\": \"text-moderation-stable\"\n        }\n    ],\n    \"created\": 1673777034\n}\n```\n\n\u003c!-- Best Practices for API Key Safety --\u003e\n## 6. Best Practices for API Key Safety\n\nYour OpenAI APIKEY key/s should be kept secure and private at all times.\n\nPlease follow the best practices guide for API security from OpenAI \n\u003cbr /\u003e\n\u003ca href=\"https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\"\u003ehttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanalyticsinmotion%2Fchatgpt-python-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanalyticsinmotion%2Fchatgpt-python-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanalyticsinmotion%2Fchatgpt-python-wrapper/lists"}