{"id":22769823,"url":"https://github.com/bfontaine/anycode","last_synced_at":"2025-04-15T03:20:48.786Z","repository":{"id":222389583,"uuid":"757108124","full_name":"bfontaine/Anycode","owner":"bfontaine","description":"Python constants and functions generated on-the-fly by ChatGPT.","archived":false,"fork":false,"pushed_at":"2024-02-19T21:15:11.000Z","size":62,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T02:55:28.962Z","etag":null,"topics":["chatgpt","python-module"],"latest_commit_sha":null,"homepage":"","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/bfontaine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.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}},"created_at":"2024-02-13T20:28:20.000Z","updated_at":"2025-01-28T19:36:50.000Z","dependencies_parsed_at":"2024-02-13T23:43:28.291Z","dependency_job_id":null,"html_url":"https://github.com/bfontaine/Anycode","commit_stats":null,"previous_names":["bfontaine/anycode"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2FAnycode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2FAnycode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2FAnycode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2FAnycode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bfontaine","download_url":"https://codeload.github.com/bfontaine/Anycode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997348,"owners_count":21195862,"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":["chatgpt","python-module"],"created_at":"2024-12-11T15:15:59.990Z","updated_at":"2025-04-15T03:20:48.770Z","avatar_url":"https://github.com/bfontaine.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anycode\n\n**Anycode** is a Python module that uses ChatGPT to automatically generate constants and functions based on their name.\n\nJust import `anycode` and use its dynamically-generated attributs: `anycode.PI` is `3.141592`,\n`anycode.SAMPLE_10_NAMES` is `['John', 'Jane', 'Adam', 'Eve', …]`, `anycode.SAMPLE_ISBN` is `\"978-1-56619-909-4\"` and\nso on.\n\nThis works on functions, too:\n\n```python\nimport anycode\n\nanycode.fetch_wikipedia_article_intro(\"Angelina Mango\")\n# =\u003e \"Angelina Mango is an Italian singer-songwriter. …\"\n\nanycode.get_random_number_between(1000, 2000)\n# =\u003e 1241 (for example)\n\nanycode.multiply(4, 5)\n# =\u003e 20\n\nanycode.say_hello(\"Baptiste\")\n# prints \"Hello, Baptiste!\"\n```\n\nYou can also `import` anything `from anycode`:\n\n```python\nfrom anycode import print_whatever\nprint_whatever()\n```\n\n## Install\n\n    pip install anycode\n\nOr with Poetry:\n\n    poetry add anycode\n\nWe support Python 3.9+.\n\n## Usage\n\nNote: you need a valid [OpenAI API key](https://platform.openai.com/api-keys). See below how to configure it.\n\nAny attribute written in `UPPER_CASE` is assumed to be a single value:\n\n```python\nimport anycode\n\nprint(anycode.PI)  # 3.141592...\nprint(anycode.SAMPLE_EAN13)  # 9780141036148\nprint(anycode.SAMPLE_ISBN)  # 978-1-56619-909-4\n\nprint(anycode.TWO + anycode.TWO)  # 4\n\nprint(anycode.ROT13_DICT)  # {'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', ...}\n\nprint(anycode.TEN_RANDOM_QUOTES)  # ['The only way to do great work is to love what you do. - Steve Jobs', ...]\n\nprint(anycode.OPENAI_API_KEY)  # raises a GenerationException(\"Cannot generate code for 'OPENAI_API_KEY'\")\n```\n\nIf you prefer can also import from the module:\n\n```python\nfrom anycode import HELLO, WORLD\n\nprint(HELLO + \" \" + WORLD)\n# prints Hello World\n```\n\nAny other value is a function:\n\n```python\nimport anycode\n\ntype(anycode.say_goodbye)\n# =\u003e \u003cclass 'function'\u003e\n\nanycode.say_goodbye(\"John\")\n# prints \"Goodbye, John!\"\n```\n\n\u003e [!TIP]\n\u003e Simple functions work, but for complex things ChatGPT often fails to generate valid code.\n\n\u003e [!CAUTION]\n\u003e The generated code is executed on the same machine as your code, so do not use this in production.\n\nAccessing a function initiates it, but it doesn’t generate any code. We only do so when it’s called for the first time,\nso we know how many arguments it should take. Further calls reuse the cached function.\n\nOnce a function has been generated, you can access `._openai_fn` on it to get the ChatGPT-generated function\nand `.openai_response` to get the ChatGPT text response.\n\n### Exceptions\n\nWhen OpenAI can’t generate a valid value, the module raises a `GenerationException` that you can inspect to\nunderstand what went wrong.\nUse its `query` attribute to get the query used to generate the code and `openai_response` to get the response text from\nOpenAI.\n\n### Cache\n\nValues are cached so that when you use them a second time we don’t call OpenAI another time.\nYou can delete a value from the cache with `del`:\n\n```python\nimport anycode\n\n# This calls the OpenAI API\nprint(anycode.GITHUB_URL)\n\n# This uses the cache\nprint(anycode.GITHUB_URL)\n\ndel anycode.GITHUB_URL\n\n# This calls the OpenAI API again\nprint(anycode.GITHUB_URL)\n```\n\nYou can dump all the generated code in a file to save it for future usage:\n\n```python\nwith open(\"mycode.py\", \"w\") as f:\n    anycode.dump(f)\n```\n\nThis allows you to inspect and reuse the generated code without Anycode nor OpenAI API calls.\n\n## Configuration\n\n### OpenAI API key\n\nBy default Anycode takes the value of the `OPENAI_API_KEY` from your environment or from a `.env` file.\nYou can also explicitly set it:\n\n```python\nimport anycode\n\nanycode.set_openai_api_key(\"your-api-key\")\n\n# or from an environment variable\nanycode.set_openai_api_key_from_env(\"MY_OPENAI_API_KEY\")\n```\n\nThe typical usage is quite low: to develop and test this entire project I used $0.02 of credit.\n\n### Advanced configuration\n\nThe OpenAI client can be directly accessed and modified:\n\n```python\nfrom anycode.client import openai_client\n\nopenai_client.default_headers = {\"x-foo\": \"true\"}\n```\n\n## License\n\nCopyright © 2024 – Baptiste Fontaine. See the [LICENSE](./LICENSE) file.\n\nAlthough it doesn’t share any code with it, this project was inspired by the\n[StackOverflow Importer](https://github.com/drathier/stack-overflow-import).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfontaine%2Fanycode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbfontaine%2Fanycode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfontaine%2Fanycode/lists"}