From fd847c68bb2b5d3a82b0eb3495a4bce111de5961 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 07:49:14 -0600 Subject: [PATCH 01/10] Add `anthropic` support --- poetry.lock | 231 +++++++++++++++++++++++++++++++++++++- pyproject.toml | 4 + src/codergpt/constants.py | 2 +- 3 files changed, 235 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 789ded1..6e71fce 100644 --- a/poetry.lock +++ b/poetry.lock @@ -132,6 +132,26 @@ files = [ {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, ] +[[package]] +name = "anthropic" +version = "0.8.1" +description = "The official Python library for the anthropic API" +optional = false +python-versions = ">=3.7" +files = [ + {file = "anthropic-0.8.1-py3-none-any.whl", hash = "sha256:4578b99d6e140c84ad5f409e460aabc85acffc6e189dfd91378b9277b4c158b7"}, + {file = "anthropic-0.8.1.tar.gz", hash = "sha256:736cf85681b8ed066014b0485d8d5be1f2aae65f86e6a25c76a5d5ebb970eee5"}, +] + +[package.dependencies] +anyio = ">=3.5.0,<5" +distro = ">=1.7.0,<2" +httpx = ">=0.23.0,<1" +pydantic = ">=1.9.0,<3" +sniffio = "*" +tokenizers = ">=0.13.0" +typing-extensions = ">=4.7,<5" + [[package]] name = "anyio" version = "4.2.0" @@ -544,6 +564,41 @@ files = [ {file = "frozenlist-1.4.1.tar.gz", hash = "sha256:c037a86e8513059a2613aaba4d817bb90b9d9b6b69aace3ce9c877e8c8ed402b"}, ] +[[package]] +name = "fsspec" +version = "2024.2.0" +description = "File-system specification" +optional = false +python-versions = ">=3.8" +files = [ + {file = "fsspec-2024.2.0-py3-none-any.whl", hash = "sha256:817f969556fa5916bc682e02ca2045f96ff7f586d45110fcb76022063ad2c7d8"}, + {file = "fsspec-2024.2.0.tar.gz", hash = "sha256:b6ad1a679f760dda52b1168c859d01b7b80648ea6f7f7c7f5a8a91dc3f3ecb84"}, +] + +[package.extras] +abfs = ["adlfs"] +adl = ["adlfs"] +arrow = ["pyarrow (>=1)"] +dask = ["dask", "distributed"] +devel = ["pytest", "pytest-cov"] +dropbox = ["dropbox", "dropboxdrivefs", "requests"] +full = ["adlfs", "aiohttp (!=4.0.0a0,!=4.0.0a1)", "dask", "distributed", "dropbox", "dropboxdrivefs", "fusepy", "gcsfs", "libarchive-c", "ocifs", "panel", "paramiko", "pyarrow (>=1)", "pygit2", "requests", "s3fs", "smbprotocol", "tqdm"] +fuse = ["fusepy"] +gcs = ["gcsfs"] +git = ["pygit2"] +github = ["requests"] +gs = ["gcsfs"] +gui = ["panel"] +hdfs = ["pyarrow (>=1)"] +http = ["aiohttp (!=4.0.0a0,!=4.0.0a1)"] +libarchive = ["libarchive-c"] +oci = ["ocifs"] +s3 = ["s3fs"] +sftp = ["paramiko"] +smb = ["smbprotocol"] +ssh = ["paramiko"] +tqdm = ["tqdm"] + [[package]] name = "google-ai-generativelanguage" version = "0.4.0" @@ -860,6 +915,38 @@ cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"] http2 = ["h2 (>=3,<5)"] socks = ["socksio (==1.*)"] +[[package]] +name = "huggingface-hub" +version = "0.20.3" +description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub" +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "huggingface_hub-0.20.3-py3-none-any.whl", hash = "sha256:d988ae4f00d3e307b0c80c6a05ca6dbb7edba8bba3079f74cda7d9c2e562a7b6"}, + {file = "huggingface_hub-0.20.3.tar.gz", hash = "sha256:94e7f8e074475fbc67d6a71957b678e1b4a74ff1b64a644fd6cbb83da962d05d"}, +] + +[package.dependencies] +filelock = "*" +fsspec = ">=2023.5.0" +packaging = ">=20.9" +pyyaml = ">=5.1" +requests = "*" +tqdm = ">=4.42.1" +typing-extensions = ">=3.7.4.3" + +[package.extras] +all = ["InquirerPy (==0.3.4)", "Jinja2", "Pillow", "aiohttp", "gradio", "jedi", "mypy (==1.5.1)", "numpy", "pydantic (>1.1,<2.0)", "pydantic (>1.1,<3.0)", "pytest", "pytest-asyncio", "pytest-cov", "pytest-env", "pytest-rerunfailures", "pytest-vcr", "pytest-xdist", "ruff (>=0.1.3)", "soundfile", "types-PyYAML", "types-requests", "types-simplejson", "types-toml", "types-tqdm", "types-urllib3", "typing-extensions (>=4.8.0)", "urllib3 (<2.0)"] +cli = ["InquirerPy (==0.3.4)"] +dev = ["InquirerPy (==0.3.4)", "Jinja2", "Pillow", "aiohttp", "gradio", "jedi", "mypy (==1.5.1)", "numpy", "pydantic (>1.1,<2.0)", "pydantic (>1.1,<3.0)", "pytest", "pytest-asyncio", "pytest-cov", "pytest-env", "pytest-rerunfailures", "pytest-vcr", "pytest-xdist", "ruff (>=0.1.3)", "soundfile", "types-PyYAML", "types-requests", "types-simplejson", "types-toml", "types-tqdm", "types-urllib3", "typing-extensions (>=4.8.0)", "urllib3 (<2.0)"] +fastai = ["fastai (>=2.4)", "fastcore (>=1.3.27)", "toml"] +inference = ["aiohttp", "pydantic (>1.1,<2.0)", "pydantic (>1.1,<3.0)"] +quality = ["mypy (==1.5.1)", "ruff (>=0.1.3)"] +tensorflow = ["graphviz", "pydot", "tensorflow"] +testing = ["InquirerPy (==0.3.4)", "Jinja2", "Pillow", "aiohttp", "gradio", "jedi", "numpy", "pydantic (>1.1,<2.0)", "pydantic (>1.1,<3.0)", "pytest", "pytest-asyncio", "pytest-cov", "pytest-env", "pytest-rerunfailures", "pytest-vcr", "pytest-xdist", "soundfile", "urllib3 (<2.0)"] +torch = ["torch"] +typing = ["types-PyYAML", "types-requests", "types-simplejson", "types-toml", "types-tqdm", "types-urllib3", "typing-extensions (>=4.8.0)"] + [[package]] name = "identify" version = "2.5.34" @@ -1008,6 +1095,21 @@ openai = ["openai (<2)", "tiktoken (>=0.3.2,<0.6.0)"] qdrant = ["qdrant-client (>=1.3.1,<2.0.0)"] text-helpers = ["chardet (>=5.1.0,<6.0.0)"] +[[package]] +name = "langchain-anthropic" +version = "0.0.1.post1" +description = "An integration package connecting AnthropicMessages and LangChain" +optional = false +python-versions = ">=3.8.1,<4.0" +files = [ + {file = "langchain_anthropic-0.0.1.post1-py3-none-any.whl", hash = "sha256:1567f906899b9c043e69e3d3b0038d53527e9bba646efddc24ced36ad331b707"}, + {file = "langchain_anthropic-0.0.1.post1.tar.gz", hash = "sha256:6f8840af5389f7c38f2dd811567f7e4284a4c3df49f6d5102c4ee637fbbd205c"}, +] + +[package.dependencies] +anthropic = ">=0.8.0,<0.9.0" +langchain-core = ">=0.0.12" + [[package]] name = "langchain-community" version = "0.0.19" @@ -2374,6 +2476,133 @@ requests = ">=2.26.0" [package.extras] blobfile = ["blobfile (>=2)"] +[[package]] +name = "tokenizers" +version = "0.15.2" +description = "" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tokenizers-0.15.2-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:52f6130c9cbf70544287575a985bf44ae1bda2da7e8c24e97716080593638012"}, + {file = "tokenizers-0.15.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:054c1cc9c6d68f7ffa4e810b3d5131e0ba511b6e4be34157aa08ee54c2f8d9ee"}, + {file = "tokenizers-0.15.2-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:a9b9b070fdad06e347563b88c278995735292ded1132f8657084989a4c84a6d5"}, + {file = "tokenizers-0.15.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ea621a7eef4b70e1f7a4e84dd989ae3f0eeb50fc8690254eacc08acb623e82f1"}, + {file = "tokenizers-0.15.2-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:cf7fd9a5141634fa3aa8d6b7be362e6ae1b4cda60da81388fa533e0b552c98fd"}, + {file = "tokenizers-0.15.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:44f2a832cd0825295f7179eaf173381dc45230f9227ec4b44378322d900447c9"}, + {file = "tokenizers-0.15.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8b9ec69247a23747669ec4b0ca10f8e3dfb3545d550258129bd62291aabe8605"}, + {file = "tokenizers-0.15.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:40b6a4c78da863ff26dbd5ad9a8ecc33d8a8d97b535172601cf00aee9d7ce9ce"}, + {file = "tokenizers-0.15.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:5ab2a4d21dcf76af60e05af8063138849eb1d6553a0d059f6534357bce8ba364"}, + {file = "tokenizers-0.15.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:a47acfac7e511f6bbfcf2d3fb8c26979c780a91e06fb5b9a43831b2c0153d024"}, + {file = "tokenizers-0.15.2-cp310-none-win32.whl", hash = "sha256:064ff87bb6acdbd693666de9a4b692add41308a2c0ec0770d6385737117215f2"}, + {file = "tokenizers-0.15.2-cp310-none-win_amd64.whl", hash = "sha256:3b919afe4df7eb6ac7cafd2bd14fb507d3f408db7a68c43117f579c984a73843"}, + {file = "tokenizers-0.15.2-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:89cd1cb93e4b12ff39bb2d626ad77e35209de9309a71e4d3d4672667b4b256e7"}, + {file = "tokenizers-0.15.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:cfed5c64e5be23d7ee0f0e98081a25c2a46b0b77ce99a4f0605b1ec43dd481fa"}, + {file = "tokenizers-0.15.2-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:a907d76dcfda37023ba203ab4ceeb21bc5683436ebefbd895a0841fd52f6f6f2"}, + {file = "tokenizers-0.15.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:20ea60479de6fc7b8ae756b4b097572372d7e4032e2521c1bbf3d90c90a99ff0"}, + {file = "tokenizers-0.15.2-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:48e2b9335be2bc0171df9281385c2ed06a15f5cf121c44094338306ab7b33f2c"}, + {file = "tokenizers-0.15.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:112a1dd436d2cc06e6ffdc0b06d55ac019a35a63afd26475205cb4b1bf0bfbff"}, + {file = "tokenizers-0.15.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4620cca5c2817177ee8706f860364cc3a8845bc1e291aaf661fb899e5d1c45b0"}, + {file = "tokenizers-0.15.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ccd73a82751c523b3fc31ff8194702e4af4db21dc20e55b30ecc2079c5d43cb7"}, + {file = "tokenizers-0.15.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:107089f135b4ae7817affe6264f8c7a5c5b4fd9a90f9439ed495f54fcea56fb4"}, + {file = "tokenizers-0.15.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:0ff110ecc57b7aa4a594396525a3451ad70988e517237fe91c540997c4e50e29"}, + {file = "tokenizers-0.15.2-cp311-none-win32.whl", hash = "sha256:6d76f00f5c32da36c61f41c58346a4fa7f0a61be02f4301fd30ad59834977cc3"}, + {file = "tokenizers-0.15.2-cp311-none-win_amd64.whl", hash = "sha256:cc90102ed17271cf0a1262babe5939e0134b3890345d11a19c3145184b706055"}, + {file = "tokenizers-0.15.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:f86593c18d2e6248e72fb91c77d413a815153b8ea4e31f7cd443bdf28e467670"}, + {file = "tokenizers-0.15.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0774bccc6608eca23eb9d620196687c8b2360624619623cf4ba9dc9bd53e8b51"}, + {file = "tokenizers-0.15.2-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:d0222c5b7c9b26c0b4822a82f6a7011de0a9d3060e1da176f66274b70f846b98"}, + {file = "tokenizers-0.15.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3835738be1de66624fff2f4f6f6684775da4e9c00bde053be7564cbf3545cc66"}, + {file = "tokenizers-0.15.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:0143e7d9dcd811855c1ce1ab9bf5d96d29bf5e528fd6c7824d0465741e8c10fd"}, + {file = "tokenizers-0.15.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:db35825f6d54215f6b6009a7ff3eedee0848c99a6271c870d2826fbbedf31a38"}, + {file = "tokenizers-0.15.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3f5e64b0389a2be47091d8cc53c87859783b837ea1a06edd9d8e04004df55a5c"}, + {file = "tokenizers-0.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e0480c452217edd35eca56fafe2029fb4d368b7c0475f8dfa3c5c9c400a7456"}, + {file = "tokenizers-0.15.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:a33ab881c8fe70474980577e033d0bc9a27b7ab8272896e500708b212995d834"}, + {file = "tokenizers-0.15.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a308a607ca9de2c64c1b9ba79ec9a403969715a1b8ba5f998a676826f1a7039d"}, + {file = "tokenizers-0.15.2-cp312-none-win32.whl", hash = "sha256:b8fcfa81bcb9447df582c5bc96a031e6df4da2a774b8080d4f02c0c16b42be0b"}, + {file = "tokenizers-0.15.2-cp312-none-win_amd64.whl", hash = "sha256:38d7ab43c6825abfc0b661d95f39c7f8af2449364f01d331f3b51c94dcff7221"}, + {file = "tokenizers-0.15.2-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:38bfb0204ff3246ca4d5e726e8cc8403bfc931090151e6eede54d0e0cf162ef0"}, + {file = "tokenizers-0.15.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:9c861d35e8286a53e06e9e28d030b5a05bcbf5ac9d7229e561e53c352a85b1fc"}, + {file = "tokenizers-0.15.2-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:936bf3842db5b2048eaa53dade907b1160f318e7c90c74bfab86f1e47720bdd6"}, + {file = "tokenizers-0.15.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:620beacc3373277700d0e27718aa8b25f7b383eb8001fba94ee00aeea1459d89"}, + {file = "tokenizers-0.15.2-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2735ecbbf37e52db4ea970e539fd2d450d213517b77745114f92867f3fc246eb"}, + {file = "tokenizers-0.15.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:473c83c5e2359bb81b0b6fde870b41b2764fcdd36d997485e07e72cc3a62264a"}, + {file = "tokenizers-0.15.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:968fa1fb3c27398b28a4eca1cbd1e19355c4d3a6007f7398d48826bbe3a0f728"}, + {file = "tokenizers-0.15.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:865c60ae6eaebdde7da66191ee9b7db52e542ed8ee9d2c653b6d190a9351b980"}, + {file = "tokenizers-0.15.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:7c0d8b52664ab2d4a8d6686eb5effc68b78608a9008f086a122a7b2996befbab"}, + {file = "tokenizers-0.15.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:f33dfbdec3784093a9aebb3680d1f91336c56d86cc70ddf88708251da1fe9064"}, + {file = "tokenizers-0.15.2-cp37-cp37m-macosx_10_12_x86_64.whl", hash = "sha256:d44ba80988ff9424e33e0a49445072ac7029d8c0e1601ad25a0ca5f41ed0c1d6"}, + {file = "tokenizers-0.15.2-cp37-cp37m-macosx_11_0_arm64.whl", hash = "sha256:dce74266919b892f82b1b86025a613956ea0ea62a4843d4c4237be2c5498ed3a"}, + {file = "tokenizers-0.15.2-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:0ef06b9707baeb98b316577acb04f4852239d856b93e9ec3a299622f6084e4be"}, + {file = "tokenizers-0.15.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c73e2e74bbb07910da0d37c326869f34113137b23eadad3fc00856e6b3d9930c"}, + {file = "tokenizers-0.15.2-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4eeb12daf02a59e29f578a865f55d87cd103ce62bd8a3a5874f8fdeaa82e336b"}, + {file = "tokenizers-0.15.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9ba9f6895af58487ca4f54e8a664a322f16c26bbb442effd01087eba391a719e"}, + {file = "tokenizers-0.15.2-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ccec77aa7150e38eec6878a493bf8c263ff1fa8a62404e16c6203c64c1f16a26"}, + {file = "tokenizers-0.15.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3f40604f5042ff210ba82743dda2b6aa3e55aa12df4e9f2378ee01a17e2855e"}, + {file = "tokenizers-0.15.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:5645938a42d78c4885086767c70923abad047163d809c16da75d6b290cb30bbe"}, + {file = "tokenizers-0.15.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:05a77cbfebe28a61ab5c3891f9939cc24798b63fa236d84e5f29f3a85a200c00"}, + {file = "tokenizers-0.15.2-cp37-none-win32.whl", hash = "sha256:361abdc068e8afe9c5b818769a48624687fb6aaed49636ee39bec4e95e1a215b"}, + {file = "tokenizers-0.15.2-cp37-none-win_amd64.whl", hash = "sha256:7ef789f83eb0f9baeb4d09a86cd639c0a5518528f9992f38b28e819df397eb06"}, + {file = "tokenizers-0.15.2-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:4fe1f74a902bee74a3b25aff180fbfbf4f8b444ab37c4d496af7afd13a784ed2"}, + {file = "tokenizers-0.15.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4c4b89038a684f40a6b15d6b09f49650ac64d951ad0f2a3ea9169687bbf2a8ba"}, + {file = "tokenizers-0.15.2-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:d05a1b06f986d41aed5f2de464c003004b2df8aaf66f2b7628254bcbfb72a438"}, + {file = "tokenizers-0.15.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:508711a108684111ec8af89d3a9e9e08755247eda27d0ba5e3c50e9da1600f6d"}, + {file = "tokenizers-0.15.2-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:daa348f02d15160cb35439098ac96e3a53bacf35885072611cd9e5be7d333daa"}, + {file = "tokenizers-0.15.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:494fdbe5932d3416de2a85fc2470b797e6f3226c12845cadf054dd906afd0442"}, + {file = "tokenizers-0.15.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c2d60f5246f4da9373f75ff18d64c69cbf60c3bca597290cea01059c336d2470"}, + {file = "tokenizers-0.15.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:93268e788825f52de4c7bdcb6ebc1fcd4a5442c02e730faa9b6b08f23ead0e24"}, + {file = "tokenizers-0.15.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:6fc7083ab404019fc9acafe78662c192673c1e696bd598d16dc005bd663a5cf9"}, + {file = "tokenizers-0.15.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:41e39b41e5531d6b2122a77532dbea60e171ef87a3820b5a3888daa847df4153"}, + {file = "tokenizers-0.15.2-cp38-none-win32.whl", hash = "sha256:06cd0487b1cbfabefb2cc52fbd6b1f8d4c37799bd6c6e1641281adaa6b2504a7"}, + {file = "tokenizers-0.15.2-cp38-none-win_amd64.whl", hash = "sha256:5179c271aa5de9c71712e31cb5a79e436ecd0d7532a408fa42a8dbfa4bc23fd9"}, + {file = "tokenizers-0.15.2-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:82f8652a74cc107052328b87ea8b34291c0f55b96d8fb261b3880216a9f9e48e"}, + {file = "tokenizers-0.15.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:02458bee6f5f3139f1ebbb6d042b283af712c0981f5bc50edf771d6b762d5e4f"}, + {file = "tokenizers-0.15.2-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:c9a09cd26cca2e1c349f91aa665309ddb48d71636370749414fbf67bc83c5343"}, + {file = "tokenizers-0.15.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:158be8ea8554e5ed69acc1ce3fbb23a06060bd4bbb09029431ad6b9a466a7121"}, + {file = "tokenizers-0.15.2-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:1ddba9a2b0c8c81633eca0bb2e1aa5b3a15362b1277f1ae64176d0f6eba78ab1"}, + {file = "tokenizers-0.15.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3ef5dd1d39797044642dbe53eb2bc56435308432e9c7907728da74c69ee2adca"}, + {file = "tokenizers-0.15.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:454c203164e07a860dbeb3b1f4a733be52b0edbb4dd2e5bd75023ffa8b49403a"}, + {file = "tokenizers-0.15.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0cf6b7f1d4dc59af960e6ffdc4faffe6460bbfa8dce27a58bf75755ffdb2526d"}, + {file = "tokenizers-0.15.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:2ef09bbc16519f6c25d0c7fc0c6a33a6f62923e263c9d7cca4e58b8c61572afb"}, + {file = "tokenizers-0.15.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:c9a2ebdd2ad4ec7a68e7615086e633857c85e2f18025bd05d2a4399e6c5f7169"}, + {file = "tokenizers-0.15.2-cp39-none-win32.whl", hash = "sha256:918fbb0eab96fe08e72a8c2b5461e9cce95585d82a58688e7f01c2bd546c79d0"}, + {file = "tokenizers-0.15.2-cp39-none-win_amd64.whl", hash = "sha256:524e60da0135e106b254bd71f0659be9f89d83f006ea9093ce4d1fab498c6d0d"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:6a9b648a58281c4672212fab04e60648fde574877d0139cd4b4f93fe28ca8944"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:7c7d18b733be6bbca8a55084027f7be428c947ddf871c500ee603e375013ffba"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:13ca3611de8d9ddfbc4dc39ef54ab1d2d4aaa114ac8727dfdc6a6ec4be017378"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:237d1bf3361cf2e6463e6c140628e6406766e8b27274f5fcc62c747ae3c6f094"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:67a0fe1e49e60c664915e9fb6b0cb19bac082ab1f309188230e4b2920230edb3"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:4e022fe65e99230b8fd89ebdfea138c24421f91c1a4f4781a8f5016fd5cdfb4d"}, + {file = "tokenizers-0.15.2-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:d857be2df69763362ac699f8b251a8cd3fac9d21893de129bc788f8baaef2693"}, + {file = "tokenizers-0.15.2-pp37-pypy37_pp73-macosx_10_12_x86_64.whl", hash = "sha256:708bb3e4283177236309e698da5fcd0879ce8fd37457d7c266d16b550bcbbd18"}, + {file = "tokenizers-0.15.2-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:64c35e09e9899b72a76e762f9854e8750213f67567787d45f37ce06daf57ca78"}, + {file = "tokenizers-0.15.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c1257f4394be0d3b00de8c9e840ca5601d0a4a8438361ce9c2b05c7d25f6057b"}, + {file = "tokenizers-0.15.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:02272fe48280e0293a04245ca5d919b2c94a48b408b55e858feae9618138aeda"}, + {file = "tokenizers-0.15.2-pp37-pypy37_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:dc3ad9ebc76eabe8b1d7c04d38be884b8f9d60c0cdc09b0aa4e3bcf746de0388"}, + {file = "tokenizers-0.15.2-pp37-pypy37_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:32e16bdeffa7c4f46bf2152172ca511808b952701d13e7c18833c0b73cb5c23f"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:fb16ba563d59003028b678d2361a27f7e4ae0ab29c7a80690efa20d829c81fdb"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-macosx_11_0_arm64.whl", hash = "sha256:2277c36d2d6cdb7876c274547921a42425b6810d38354327dd65a8009acf870c"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:1cf75d32e8d250781940d07f7eece253f2fe9ecdb1dc7ba6e3833fa17b82fcbc"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f1b3b31884dc8e9b21508bb76da80ebf7308fdb947a17affce815665d5c4d028"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b10122d8d8e30afb43bb1fe21a3619f62c3e2574bff2699cf8af8b0b6c5dc4a3"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:d88b96ff0fe8e91f6ef01ba50b0d71db5017fa4e3b1d99681cec89a85faf7bf7"}, + {file = "tokenizers-0.15.2-pp38-pypy38_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:37aaec5a52e959892870a7c47cef80c53797c0db9149d458460f4f31e2fb250e"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:e2ea752f2b0fe96eb6e2f3adbbf4d72aaa1272079b0dfa1145507bd6a5d537e6"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:4b19a808d8799fda23504a5cd31d2f58e6f52f140380082b352f877017d6342b"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:64c86e5e068ac8b19204419ed8ca90f9d25db20578f5881e337d203b314f4104"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:de19c4dc503c612847edf833c82e9f73cd79926a384af9d801dcf93f110cea4e"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ea09acd2fe3324174063d61ad620dec3bcf042b495515f27f638270a7d466e8b"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:cf27fd43472e07b57cf420eee1e814549203d56de00b5af8659cb99885472f1f"}, + {file = "tokenizers-0.15.2-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:7ca22bd897537a0080521445d91a58886c8c04084a6a19e6c78c586e0cfa92a5"}, + {file = "tokenizers-0.15.2.tar.gz", hash = "sha256:e6e9c6e019dd5484be5beafc775ae6c925f4c69a3487040ed09b45e13df2cb91"}, +] + +[package.dependencies] +huggingface_hub = ">=0.16.4,<1.0" + +[package.extras] +dev = ["tokenizers[testing]"] +docs = ["setuptools_rust", "sphinx", "sphinx_rtd_theme"] +testing = ["black (==22.3)", "datasets", "numpy", "pytest", "requests"] + [[package]] name = "tomli" version = "2.0.1" @@ -2627,4 +2856,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "6bd5078d54112736447bc35eb0a456309854312a859418948d087bc0212f4554" +content-hash = "064c0b1fe234cd6127267ce8dab3ba4e5009a9fee079dc9678be072e7f9b70f0" diff --git a/pyproject.toml b/pyproject.toml index 7113941..3386ae7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,10 @@ sphinx-autodoc-typehints = {version = ">=1.2.0"} sphinx-click = {version = ">=4.3.0"} myst-parser = {version = ">=0.18.1"} + +[tool.poetry.group.anthropic.dependencies] +langchain-anthropic = "^0.0.1.post1" + [tool.poetry.scripts] codergpt = "codergpt.cli:main" diff --git a/src/codergpt/constants.py b/src/codergpt/constants.py index f8671ef..6359a21 100644 --- a/src/codergpt/constants.py +++ b/src/codergpt/constants.py @@ -13,7 +13,7 @@ GPT_3_5_TURBO = "gpt-3.5-turbo" GPT_4 = "gpt-4" GPT_4_TURBO = "gpt-4-turbo-preview" -CLAUDE = "claude" +CLAUDE = "claude-2" GEMINI = "gemini-pro" ALL_MODELS = [ From 6a8b8e781127a199cc770e021abb97620a37b0d4 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 15:18:29 -0600 Subject: [PATCH 02/10] set temp to 0 for deterministic responses --- src/codergpt/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codergpt/main.py b/src/codergpt/main.py index 226b019..4c5e96a 100644 --- a/src/codergpt/main.py +++ b/src/codergpt/main.py @@ -24,7 +24,7 @@ class CoderGPT: def __init__(self, model: str = GPT_4_TURBO): """Initialize the CoderGPT class.""" if model is None or model.startswith("gpt-"): - self.llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"), temperature=0.7, model=model) + self.llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"), temperature=0, model=model) # elif model == CLAUDE: # self.llm = ChatAnthropic() # print("Coming Soon!") From 3f3fa2b3dc0defe3494c218207f2ba14e4b220c8 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 22:55:49 -0600 Subject: [PATCH 03/10] Added Templates --- src/codergpt/cli.py | 6 + src/codergpt/commenter/commenter.py | 27 +- src/codergpt/constants.py | 22 ++ src/codergpt/documenter/documenter.py | 40 +-- src/codergpt/main.py | 8 +- .../templates/python_code_comments.md | 146 +++++++++++ .../templates/sphinx_style_document.md | 234 ++++++++++++++++++ tests/test_documenter.py | 11 +- 8 files changed, 469 insertions(+), 25 deletions(-) create mode 100644 src/codergpt/templates/python_code_comments.md create mode 100644 src/codergpt/templates/sphinx_style_document.md diff --git a/src/codergpt/cli.py b/src/codergpt/cli.py index 22a1d75..b3f81aa 100644 --- a/src/codergpt/cli.py +++ b/src/codergpt/cli.py @@ -44,6 +44,12 @@ default="gpt-4", help="Model to use for code generation.", ) +prompt_option = click.option( + "-p", + "--prompt", + type=Union[str, Path], + help="Prompt to use for code generation.", +) function_option = click.option("-f", "--function", help="Function name to explain or optimize.") class_option = click.option("-c", "--classname", help="Class name to explain or optimize.") overwrite_option = click.option( diff --git a/src/codergpt/commenter/commenter.py b/src/codergpt/commenter/commenter.py index 87ebac9..4eb88be 100644 --- a/src/codergpt/commenter/commenter.py +++ b/src/codergpt/commenter/commenter.py @@ -5,6 +5,8 @@ from langchain_core.runnables.base import RunnableSerializable +from codergpt.constants import TEMPLATES + class CodeCommenter: """Code Explainer class that extracts and explains code from a given file.""" @@ -25,13 +27,30 @@ def comment(self, code: str, filename: str, overwrite: bool = False, language: O :param filename: The original filename of the code file. :param overwrite: A boolean indicating whether to overwrite the original file. Default is False. """ - response = self.chain.invoke( - { + comment_template = None + if language and language in TEMPLATES.keys(): + # Check if "comment" key exists in the language template + if "comment" in TEMPLATES[language]: + # Get the path to the comment template + comment_template_path = TEMPLATES[language]["comment"] + with open(comment_template_path, "r") as comment_template_file: + comment_template = comment_template_file.read() + + if comment_template: + invoke_params = { + "input": f"Rewrite and return this {language} code with\ + comments: \n{code}\n" + f"Use template {comment_template} as reference to render the code comments." + "Return just the code block since all this will be a file." + } + else: + invoke_params = { "input": f"Rewrite and return this {language} code with\ - comments and sphinx docstrings in :param: format: \n{code}\n" + comments: \n{code}\n" "Return just the code block since all this will be a file." } - ) + + response = self.chain.invoke(invoke_params) # Extract the commented code from the response if necessary commented_code = response.content diff --git a/src/codergpt/constants.py b/src/codergpt/constants.py index 6359a21..10cfd49 100644 --- a/src/codergpt/constants.py +++ b/src/codergpt/constants.py @@ -7,6 +7,7 @@ DOCS_DIR = PROJECT_DIR / "docs" SRC = Path(__file__).resolve().parents[1] PACKAGE_DIR = SRC / "codergpt" +TEMPLATES_DIR = PACKAGE_DIR / "templates" EXTENSION_MAP_FILE = PACKAGE_DIR / "extensions.yaml" LANGUAGE_MAP_KEY = "language-map" INSPECTION_HEADERS = ["File", "Language"] @@ -23,3 +24,24 @@ CLAUDE, GEMINI, ] + +SPHINX_DOCUMENTATION_TEMPLATE = TEMPLATES_DIR / "sphinx_style_document.md" +PYTHON_CODE_COMMENT_TEMPLATE = TEMPLATES_DIR / "python_code_comment.md" + +""" +Templates for different languages and commands. + +Follows format: + { + "language": { + "command": "path/to/comment/template", + } + } +""" + +TEMPLATES = { + "Python": { + "comment": PYTHON_CODE_COMMENT_TEMPLATE, + "document": SPHINX_DOCUMENTATION_TEMPLATE, + } +} diff --git a/src/codergpt/documenter/documenter.py b/src/codergpt/documenter/documenter.py index 6935ea1..b9dd3bb 100644 --- a/src/codergpt/documenter/documenter.py +++ b/src/codergpt/documenter/documenter.py @@ -1,11 +1,10 @@ """Documenter module for codergpt.""" -from pathlib import Path -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional from langchain_core.runnables.base import RunnableSerializable -from codergpt.constants import DOCS_DIR +from codergpt.constants import DOCS_DIR, TEMPLATES class CodeDocumenter: @@ -21,7 +20,9 @@ def __init__(self, chain: RunnableSerializable[Dict, Any]): def document( self, - filename: Union[str, Path], + filename: str, + code: str, + language: Optional[str] = None, outfile: Optional[str] = None, ): """ @@ -31,24 +32,33 @@ def document( :param function: The name of the function to document. Default is None. :param classname: The name of the class to document """ - if isinstance(filename, str): - filename = Path(filename) - with open(filename, "r") as source_file: - source_code = source_file.read() - response = self.chain.invoke( - { - "input": f"Document the following code: \n\n```\n{source_code}\n```" - "This should be in reStructuredText (RST, ReST, or reST)" - " format that is Sphinx compatible. Return only the documentation content." + document_template = None + if language and language in TEMPLATES.keys(): + # Check if "document" key exists in the language template + if "document" in TEMPLATES[language]: + # Get the path to the document template + document_template_path = TEMPLATES[language]["document"] + with open(document_template_path, "r") as document_template_file: + document_template = document_template_file.read() + if document_template: + invoke_params = { + "input": f"Document the {language} code with the following: \n{code}\n" + f"Use template {document_template} as reference to render the code documentation." + "Everything in the template are placeholders. Return only the relevant documentation content." } - ) + else: + invoke_params = { + "input": f"Document the {language} code with the following: \n{code}\n" + "Return only the documentation content." + } + response = self.chain.invoke(invoke_params) # Extract the commented code from the response if necessary documentation = response.content if outfile: destination_path = outfile else: - destination_path = DOCS_DIR / f"{filename.stem}.rst" + destination_path = DOCS_DIR / f"{filename}.rst" # Write the documentation to the new file with open(destination_path, "w") as updated_file: updated_file.write(documentation) diff --git a/src/codergpt/main.py b/src/codergpt/main.py index 4c5e96a..caedfb4 100644 --- a/src/codergpt/main.py +++ b/src/codergpt/main.py @@ -24,7 +24,7 @@ class CoderGPT: def __init__(self, model: str = GPT_4_TURBO): """Initialize the CoderGPT class.""" if model is None or model.startswith("gpt-"): - self.llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"), temperature=0, model=model) + self.llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"), temperature=0.3, model=model) # elif model == CLAUDE: # self.llm = ChatAnthropic() # print("Coming Soon!") @@ -153,8 +153,12 @@ def documenter(self, path: Union[str, Path], outfile: str = None): :param path: The path to the code file. """ + if isinstance(path, str): + path = Path(path) code_documenter = CodeDocumenter(self.chain) - code_documenter.document(filename=path, outfile=outfile) + filename = path.stem + code, language = self.get_code(filename=path) + code_documenter.document(filename=filename, code=code, language=language, outfile=outfile) if __name__ == "__main__": diff --git a/src/codergpt/templates/python_code_comments.md b/src/codergpt/templates/python_code_comments.md new file mode 100644 index 0000000..4eea694 --- /dev/null +++ b/src/codergpt/templates/python_code_comments.md @@ -0,0 +1,146 @@ +```python +#!/usr/bin/env python3 +""" +Module docstring for the example Python script. + +This script provides an example of a Python module including various structures such as classes, functions, +decorators, and more, with appropriate docstrings and comments. +""" + +# Import statements +import os +import sys + +# Global variables +GLOBAL_CONSTANT = 42 + +def function_with_types_in_docstring(param1, param2): + """ + Example of a function with types specified in the :param: format. + + :param param1: The first parameter. + :type param1: int + :param param2: The second parameter. + :type param2: str + :return: The return value. True for success, False otherwise. + :rtype: bool + """ + return True + +def function_with_pep484_type_annotations(param1: int, param2: str) -> bool: + """ + Example of a function with PEP 484 type annotations. + + :param param1: The first parameter. + :param param2: The second parameter. + :return: The return value. True for success, False otherwise. + """ + return True + +class ExampleClass: + """ + This is an example class with a simple docstring. + + :ivar attr1: Description of `attr1`. + :vartype attr1: str + :ivar attr2: Description of `attr2`, defaults to 0. + :vartype attr2: int, optional + """ + + def __init__(self, attr1: str, attr2: int = 0): + """ + The constructor for ExampleClass. + + :param attr1: The first attribute. + :type attr1: str + :param attr2: The second attribute. Defaults to 0. + :type attr2: int, optional + """ + self.attr1 = attr1 + self.attr2 = attr2 + + def example_method(self, param1): + """ + An example method. + + :param param1: The first parameter of the method. + :type param1: str + :return: The return value. True for success, False otherwise. + :rtype: bool + """ + return True + + @staticmethod + def static_example_method(param1): + """ + An example of a static method. + + :param param1: The first parameter of the method. + :type param1: str + :return: The return value. True for success, False otherwise. + :rtype: bool + """ + return True + + @classmethod + def class_example_method(cls, param1): + """ + An example of a class method. + + :param param1: The first parameter of the method. + :type param1: str + :return: The return value. True for success, False otherwise. + :rtype: bool + """ + return True + + @property + def example_property(self): + """ + An example of a property. + + :return: The current value of `attr1`. + :rtype: str + """ + return self.attr1 + + @example_property.setter + def example_property(self, value): + """ + The setter for `example_property`. + + :param value: The new value for `attr1`. + :type value: str + """ + self.attr1 = value + +# Decorators +def decorator_function(original_function): + """ + A simple decorator function that wraps the input function. + + :param original_function: The function to decorate. + :type original_function: callable + :return: The wrapped function. + :rtype: callable + """ + def wrapper_function(*args, **kwargs): + # Do something before the original function is called. + result = original_function(*args, **kwargs) + # Do something after the original function is called. + return result + return wrapper_function + +@decorator_function +def function_to_decorate(): + """ + Example function that will be decorated. + """ + pass + +# Conditional execution +if __name__ == "__main__": + # Code to execute when the script is run directly + example_instance = ExampleClass("Hello", 123) + print(example_instance.example_method("World")) +``` \ No newline at end of file diff --git a/src/codergpt/templates/sphinx_style_document.md b/src/codergpt/templates/sphinx_style_document.md new file mode 100644 index 0000000..4f94b49 --- /dev/null +++ b/src/codergpt/templates/sphinx_style_document.md @@ -0,0 +1,234 @@ +```rst +.. _my-document: + +================================= +Your Project Name +================================= + +.. subtitle:: Subtitle (optional) + +Introduction +------------ + +Brief introduction about your project. + +Installation +------------ + +Steps to install your project: + +1. Step 1 +2. Step 2 +3. Step 3 + +Usage +----- + +Instructions on how to use your project: + +1. Step 1 +2. Step 2 +3. Step 3 + +API Documentation +----------------- + +Documentation for your project's API: + +.. autoclass:: your_module.YourClass + :members: + :undoc-members: + :show-inheritance: + :special-members: __init__ + +.. autofunction:: your_module.your_function + +.. automethod:: your_module.YourClass.your_method + +CLI Documentation +------------------ + +Documentation for your project's Command Line Interface (CLI): + +.. code-block:: console + + $ your_command --help + +Configuration +------------- + +Explanation of any configuration options: + +1. Option 1 +2. Option 2 +3. Option 3 + +Contributing +------------ + +Instructions on how to contribute to your project. + +1. Step 1 +2. Step 2 +3. Step 3 + +License +------- + +Your project's license information. + +Credits +------- + +Acknowledgments or credits for contributors, libraries used, etc. + +Custom Sections +--------------- + +.. rubric:: Custom Sections + +.. note:: This is a note. + +.. warning:: This is a warning. + +.. tip:: This is a tip. + +.. attention:: This is attention. + +.. versionadded:: 1.0.0 + +.. versionchanged:: 2.0.0 + +.. deprecated:: 3.0.0 + This feature will be removed in future releases. + +.. seealso:: :ref:`another-section` + +.. glossary:: + + term + Definition of the term. + +.. index:: + single: term + +Tables +------ + +.. csv-table:: Sample CSV Table + :header: Header 1, Header 2 + + Value 1, Value 2 + Value 3, Value 4 + +.. list-table:: Sample List Table + :widths: 20 30 + :header-rows: 1 + + * - Header 1 + - Header 2 + * - Value 1 + - Value 2 + * - Value 3 + - Value 4 + +Images and Figures +------------------ + +.. image:: image.png + :width: 400 + :height: 300 + :alt: Alternative text + :align: center + +Code Blocks +----------- + +.. code-block:: python + + print("Hello, world!") + +.. code-block:: rst + + .. This is a code block in reStructuredText. + +.. code-block:: none + + $ pip install your_package + +.. code-block:: bash + + $ python your_script.py + +.. code-block:: console + + # This is a console command + +.. code-block:: html + + + +.. code-block:: xml + + + +.. code-block:: json + + { + "key": "value" + } + +Raw Content +----------- + +.. raw:: html + +

This is raw HTML

+ +.. raw:: latex + + \section{This is raw LaTeX} + +Literal Text +------------ + +.. parsed-literal:: + + This is literal text. + It will not be interpreted for markup. + +Containers +---------- + +.. container:: centered + + This content will be centered. + +.. container:: + + This content has no special formatting. + +Table of Contents Tree +---------------------- + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + chapter1.rst + chapter2.rst + +Meta Information +---------------- + +:Author: Your Name +:Contact: your.email@example.com +:Revision: $Id$ +:Date: 2023-04-01 +:Copyright: Copyright © 2023 Your Company + +.. |replacement| replace:: Text to replace +``` + +Make sure to replace placeholders like `your_module.YourClass`, `your_module.your_function`, `your_command`, `image.png`, `chapter1.rst`, `chapter2.rst`, and others with actual names and paths relevant to your project. Customize meta information such as Author, Contact, etc., according to your needs. +``` \ No newline at end of file diff --git a/tests/test_documenter.py b/tests/test_documenter.py index 8b216c9..eb6eb81 100644 --- a/tests/test_documenter.py +++ b/tests/test_documenter.py @@ -52,9 +52,10 @@ def test_document_with_mock_chain(self, mock_open): filename = "example.py" outfile = "output.rst" self.mock_chain.invoke.return_value = Mock(content="Documented content") + code = "print('Hello, World!')" # Execute - self.documenter.document(filename, outfile) + self.documenter.document(filename=filename, outfile=outfile, code=code, language="Python") # Assert self.mock_chain.invoke.assert_called_once() @@ -74,11 +75,12 @@ def test_document_without_outfile(self, mock_open): :type mock_open: unittest.mock.MagicMock """ # Setup - filename = "example.py" + filename = "example" + code = "print('Hello, World!')" self.mock_chain.invoke.return_value = Mock(content="Documented content") # Execute - self.documenter.document(filename) + self.documenter.document(filename, code=code, language="Python") # Assert expected_path = DOCS_DIR / "example.rst" @@ -99,11 +101,12 @@ def test_document_with_pathlib_path(self): # Setup filename = Path("example.py") outfile = "output.rst" + code = "print('Hello, World!')" self.mock_chain.invoke.return_value = Mock(content="Documented content") # Patch and Spy with patch("builtins.open", unittest.mock.mock_open()) as mock_open: - self.documenter.document(filename, outfile) + self.documenter.document(filename, code, language=None, outfile=outfile) # Assert self.mock_chain.invoke.assert_called_once() From 18d210817c5dd370cab68fe549e5bcef223f93a4 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 22:58:29 -0600 Subject: [PATCH 04/10] typo --- src/codergpt/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codergpt/constants.py b/src/codergpt/constants.py index 10cfd49..9e51786 100644 --- a/src/codergpt/constants.py +++ b/src/codergpt/constants.py @@ -26,7 +26,7 @@ ] SPHINX_DOCUMENTATION_TEMPLATE = TEMPLATES_DIR / "sphinx_style_document.md" -PYTHON_CODE_COMMENT_TEMPLATE = TEMPLATES_DIR / "python_code_comment.md" +PYTHON_CODE_COMMENT_TEMPLATE = TEMPLATES_DIR / "python_code_comments.md" """ Templates for different languages and commands. From a7a1594da0113dd5fde753e1e01659e669f4ce85 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 23:01:44 -0600 Subject: [PATCH 05/10] Updated prompt --- src/codergpt/commenter/commenter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codergpt/commenter/commenter.py b/src/codergpt/commenter/commenter.py index 4eb88be..5d217f1 100644 --- a/src/codergpt/commenter/commenter.py +++ b/src/codergpt/commenter/commenter.py @@ -41,6 +41,7 @@ def comment(self, code: str, filename: str, overwrite: bool = False, language: O "input": f"Rewrite and return this {language} code with\ comments: \n{code}\n" f"Use template {comment_template} as reference to render the code comments." + "Remember, everything in the template are placeholders." "Return just the code block since all this will be a file." } else: From 423a13ffc00c9be10e9a92c9c9a3fe70aead38e2 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 23:08:42 -0600 Subject: [PATCH 06/10] Updated docstrings --- src/codergpt/commenter/commenter.py | 3 ++- src/codergpt/documenter/documenter.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/codergpt/commenter/commenter.py b/src/codergpt/commenter/commenter.py index 5d217f1..37d318d 100644 --- a/src/codergpt/commenter/commenter.py +++ b/src/codergpt/commenter/commenter.py @@ -26,6 +26,7 @@ def comment(self, code: str, filename: str, overwrite: bool = False, language: O :param code: The string containing the code to be commented. :param filename: The original filename of the code file. :param overwrite: A boolean indicating whether to overwrite the original file. Default is False. + :param language: Coding language of the file, defaults to None """ comment_template = None if language and language in TEMPLATES.keys(): @@ -41,7 +42,7 @@ def comment(self, code: str, filename: str, overwrite: bool = False, language: O "input": f"Rewrite and return this {language} code with\ comments: \n{code}\n" f"Use template {comment_template} as reference to render the code comments." - "Remember, everything in the template are placeholders." + "Everything in the template are placeholders." "Return just the code block since all this will be a file." } else: diff --git a/src/codergpt/documenter/documenter.py b/src/codergpt/documenter/documenter.py index b9dd3bb..4ae231f 100644 --- a/src/codergpt/documenter/documenter.py +++ b/src/codergpt/documenter/documenter.py @@ -28,9 +28,10 @@ def document( """ Document the contents of the code file by invoking the runnable chain. + :param filename: filename of the code file. :param code: The string containing the code to be documented. - :param function: The name of the function to document. Default is None. - :param classname: The name of the class to document + :param language: Coding language of the file, defaults to None + :param outfile: Destination filepath, defaults to None """ document_template = None if language and language in TEMPLATES.keys(): From c3b81cf058e3d7da938501d55ee5f3440ef0bb7c Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Tue, 13 Feb 2024 23:12:01 -0600 Subject: [PATCH 07/10] Updated prompt --- src/codergpt/commenter/commenter.py | 4 ++-- src/codergpt/documenter/documenter.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/codergpt/commenter/commenter.py b/src/codergpt/commenter/commenter.py index 37d318d..aea2e09 100644 --- a/src/codergpt/commenter/commenter.py +++ b/src/codergpt/commenter/commenter.py @@ -41,9 +41,9 @@ def comment(self, code: str, filename: str, overwrite: bool = False, language: O invoke_params = { "input": f"Rewrite and return this {language} code with\ comments: \n{code}\n" - f"Use template {comment_template} as reference to render the code comments." + f"Use template {comment_template} as a style reference to render the docstrings." "Everything in the template are placeholders." - "Return just the code block since all this will be a file." + "Return just the code block since all this will be saved in a file." } else: invoke_params = { diff --git a/src/codergpt/documenter/documenter.py b/src/codergpt/documenter/documenter.py index 4ae231f..d3c9644 100644 --- a/src/codergpt/documenter/documenter.py +++ b/src/codergpt/documenter/documenter.py @@ -44,7 +44,7 @@ def document( if document_template: invoke_params = { "input": f"Document the {language} code with the following: \n{code}\n" - f"Use template {document_template} as reference to render the code documentation." + f"Use template {document_template} as a style reference." "Everything in the template are placeholders. Return only the relevant documentation content." } else: From a1fa6aad851a2160a2290a233c8129f0e991b096 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Wed, 14 Feb 2024 08:22:21 -0600 Subject: [PATCH 08/10] Updated prompt --- src/codergpt/documenter/documenter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codergpt/documenter/documenter.py b/src/codergpt/documenter/documenter.py index d3c9644..fb0b079 100644 --- a/src/codergpt/documenter/documenter.py +++ b/src/codergpt/documenter/documenter.py @@ -44,7 +44,7 @@ def document( if document_template: invoke_params = { "input": f"Document the {language} code with the following: \n{code}\n" - f"Use template {document_template} as a style reference." + f"Use template {document_template} as a style reference for documentation." "Everything in the template are placeholders. Return only the relevant documentation content." } else: From 5b94eb14ddb2b55323cacc41a393533d15754e4a Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Thu, 15 Feb 2024 00:00:48 -0600 Subject: [PATCH 09/10] Updated prompt --- src/codergpt/documenter/documenter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/codergpt/documenter/documenter.py b/src/codergpt/documenter/documenter.py index fb0b079..af34c16 100644 --- a/src/codergpt/documenter/documenter.py +++ b/src/codergpt/documenter/documenter.py @@ -45,7 +45,8 @@ def document( invoke_params = { "input": f"Document the {language} code with the following: \n{code}\n" f"Use template {document_template} as a style reference for documentation." - "Everything in the template are placeholders. Return only the relevant documentation content." + "Everything in the template are placeholders. Be as detailed as possible." + "Return only the relevant documentation content." } else: invoke_params = { From 12c9519cd43d3e516989d1a9dec8162bed3c232a Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Mon, 26 Feb 2024 18:04:03 -0600 Subject: [PATCH 10/10] Anthropic works --- src/codergpt/explainer/explainer.py | 8 ++++++-- src/codergpt/main.py | 18 ++++++++++++------ tests/test_explainer.py | 9 +++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/codergpt/explainer/explainer.py b/src/codergpt/explainer/explainer.py index 9c35060..88595a7 100644 --- a/src/codergpt/explainer/explainer.py +++ b/src/codergpt/explainer/explainer.py @@ -27,11 +27,15 @@ def explain( :param classname: The name of the class to explain. Default is None. """ if function: - response = self.chain.invoke({"input": f"Explain the following {language} code: \n\n```\n{code}\n```"}) + response = self.chain.invoke( + {"input": f"Explain the function {function} in the following {language} code: \n\n```\n{code}\n```"} + ) # Pretty print the response print(f"Explanation for '{function}':\n{response.content}") elif classname: - response = self.chain.invoke({"input": f"Explain the following {language} code: \n\n```\n{code}\n```"}) + response = self.chain.invoke( + {"input": f"Explain the class {classname} in the following {language} code: \n\n```\n{code}\n```"} + ) # Pretty print the response print(f"Explanation for '{classname}':\n{response.content}") else: diff --git a/src/codergpt/main.py b/src/codergpt/main.py index caedfb4..8eb26d1 100644 --- a/src/codergpt/main.py +++ b/src/codergpt/main.py @@ -5,13 +5,14 @@ from typing import Optional, Union import yaml +from langchain_anthropic import ChatAnthropicMessages from langchain_core.prompts import ChatPromptTemplate from langchain_google_genai import ChatGoogleGenerativeAI from langchain_openai import ChatOpenAI from tabulate import tabulate from codergpt.commenter.commenter import CodeCommenter -from codergpt.constants import EXTENSION_MAP_FILE, GEMINI, GPT_4_TURBO, INSPECTION_HEADERS +from codergpt.constants import CLAUDE, EXTENSION_MAP_FILE, GEMINI, GPT_4_TURBO, INSPECTION_HEADERS from codergpt.documenter.documenter import CodeDocumenter from codergpt.explainer.explainer import CodeExplainer from codergpt.optimizer.optimizer import CodeOptimizer @@ -23,11 +24,16 @@ class CoderGPT: def __init__(self, model: str = GPT_4_TURBO): """Initialize the CoderGPT class.""" + temp = 0.3 if model is None or model.startswith("gpt-"): - self.llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"), temperature=0.3, model=model) - # elif model == CLAUDE: - # self.llm = ChatAnthropic() - # print("Coming Soon!") + self.llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY"), temperature=temp, model=model) + elif model == CLAUDE: + self.llm = ChatAnthropicMessages( + model_name=model, + anthropic_api_key=os.environ.get("ANTHROPIC_API_KEY"), + temperature=temp, + max_tokens=2048, + ) elif model == GEMINI: self.llm = ChatGoogleGenerativeAI(model=model, convert_system_message_to_human=True) else: @@ -115,7 +121,7 @@ def explainer(self, path: Union[str, Path], function: str = None, classname=None """ code_explainer = CodeExplainer(self.chain) code, language = self.get_code(filename=path, function_name=function, class_name=classname) - code_explainer.explain(code, language) + code_explainer.explain(code=code, function=function, classname=classname, language=language) def commenter(self, path: Union[str, Path], overwrite: bool = False): """ diff --git a/tests/test_explainer.py b/tests/test_explainer.py index 3ebb19c..bb3f72e 100644 --- a/tests/test_explainer.py +++ b/tests/test_explainer.py @@ -33,7 +33,10 @@ def test_explain_function(self): self.code_explainer.explain(code=sample_code, function=sample_function_name, language="python") # Verify that invoke was called once with the correct parameters - expected_invoke_input = {"input": f"Explain the following python code: \n\n```\n{sample_code}\n```"} + expected_invoke_input = { + "input": f"Explain the function {sample_function_name} " + f"in the following python code: \n\n```\n{sample_code}\n```" + } self.mock_chain.invoke.assert_called_once_with(expected_invoke_input) # Check if the expected explanation message is in the captured output @@ -51,7 +54,9 @@ def test_explain_class(self): self.code_explainer.explain(code=sample_code, classname=sample_class_name, language="python") # Verify that invoke was called once with the correct parameters - expected_invoke_input = {"input": f"Explain the following python code: \n\n```\n{sample_code}\n```"} + expected_invoke_input = { + "input": f"Explain the class {sample_class_name} in the following python code: \n\n```\n{sample_code}\n```" + } self.mock_chain.invoke.assert_called_once_with(expected_invoke_input) # Check if the expected explanation message is in the captured output