From 83cd28f550decbc9416d2e698b068060e86f8654 Mon Sep 17 00:00:00 2001 From: Magniquick <67406856+Magniquick@users.noreply.github.com> Date: Wed, 22 Oct 2025 08:46:02 +0530 Subject: [PATCH 1/4] feat: enable modern packaging via pyproject.toml uvx --from (...) chatmock should just work ! --- chatmock/prompt.md | 1 + chatmock/prompt_gpt5_codex.md | 1 + pyproject.toml | 29 +++++ uv.lock | 227 ++++++++++++++++++++++++++++++++++ 4 files changed, 258 insertions(+) create mode 120000 chatmock/prompt.md create mode 120000 chatmock/prompt_gpt5_codex.md create mode 100644 pyproject.toml create mode 100644 uv.lock diff --git a/chatmock/prompt.md b/chatmock/prompt.md new file mode 120000 index 0000000..7783dbd --- /dev/null +++ b/chatmock/prompt.md @@ -0,0 +1 @@ +../prompt.md \ No newline at end of file diff --git a/chatmock/prompt_gpt5_codex.md b/chatmock/prompt_gpt5_codex.md new file mode 120000 index 0000000..04aa304 --- /dev/null +++ b/chatmock/prompt_gpt5_codex.md @@ -0,0 +1 @@ +../prompt_gpt5_codex.md \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1986a8a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" + +[project] +name = "chatmock" +version = "0.1.0" +requires-python = ">=3.13" +dependencies = [ + "certifi==2025.8.3", + "click==8.2.1", + "flask==3.1.1", + "idna==3.10", + "itsdangerous==2.2.0", + "jinja2==3.1.6", + "markupsafe==3.0.2", + "requests==2.32.5", + "urllib3==2.5.0", + "werkzeug==3.1.3", +] + +[project.scripts] +chatmock = "chatmock.cli:main" + +[tool.setuptools.packages.find] +include = ["chatmock*"] + +[tool.setuptools.package-data] +chatmock = ["prompt.md", "prompt_gpt5_codex.md"] diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..00affdc --- /dev/null +++ b/uv.lock @@ -0,0 +1,227 @@ +version = 1 +revision = 3 +requires-python = ">=3.13" + +[[package]] +name = "blinker" +version = "1.9.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/21/28/9b3f50ce0e048515135495f198351908d99540d69bfdc8c1d15b73dc55ce/blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf", size = 22460, upload-time = "2024-11-08T17:25:47.436Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl", hash = "sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc", size = 8458, upload-time = "2024-11-08T17:25:46.184Z" }, +] + +[[package]] +name = "certifi" +version = "2025.8.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/dc/67/960ebe6bf230a96cda2e0abcf73af550ec4f090005363542f0765df162e0/certifi-2025.8.3.tar.gz", hash = "sha256:e564105f78ded564e3ae7c923924435e1daa7463faeab5bb932bc53ffae63407", size = 162386, upload-time = "2025-08-03T03:07:47.08Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl", hash = "sha256:f6c12493cfb1b06ba2ff328595af9350c65d6644968e5d3a2ffd78699af217a5", size = 161216, upload-time = "2025-08-03T03:07:45.777Z" }, +] + +[[package]] +name = "charset-normalizer" +version = "3.4.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/13/69/33ddede1939fdd074bce5434295f38fae7136463422fe4fd3e0e89b98062/charset_normalizer-3.4.4.tar.gz", hash = "sha256:94537985111c35f28720e43603b8e7b43a6ecfb2ce1d3058bbe955b73404e21a", size = 129418, upload-time = "2025-10-14T04:42:32.879Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/97/45/4b3a1239bbacd321068ea6e7ac28875b03ab8bc0aa0966452db17cd36714/charset_normalizer-3.4.4-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:e1f185f86a6f3403aa2420e815904c67b2f9ebc443f045edd0de921108345794", size = 208091, upload-time = "2025-10-14T04:41:13.346Z" }, + { url = "https://files.pythonhosted.org/packages/7d/62/73a6d7450829655a35bb88a88fca7d736f9882a27eacdca2c6d505b57e2e/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b39f987ae8ccdf0d2642338faf2abb1862340facc796048b604ef14919e55ed", size = 147936, upload-time = "2025-10-14T04:41:14.461Z" }, + { url = "https://files.pythonhosted.org/packages/89/c5/adb8c8b3d6625bef6d88b251bbb0d95f8205831b987631ab0c8bb5d937c2/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:3162d5d8ce1bb98dd51af660f2121c55d0fa541b46dff7bb9b9f86ea1d87de72", size = 144180, upload-time = "2025-10-14T04:41:15.588Z" }, + { url = "https://files.pythonhosted.org/packages/91/ed/9706e4070682d1cc219050b6048bfd293ccf67b3d4f5a4f39207453d4b99/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:81d5eb2a312700f4ecaa977a8235b634ce853200e828fbadf3a9c50bab278328", size = 161346, upload-time = "2025-10-14T04:41:16.738Z" }, + { url = "https://files.pythonhosted.org/packages/d5/0d/031f0d95e4972901a2f6f09ef055751805ff541511dc1252ba3ca1f80cf5/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5bd2293095d766545ec1a8f612559f6b40abc0eb18bb2f5d1171872d34036ede", size = 158874, upload-time = "2025-10-14T04:41:17.923Z" }, + { url = "https://files.pythonhosted.org/packages/f5/83/6ab5883f57c9c801ce5e5677242328aa45592be8a00644310a008d04f922/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a8a8b89589086a25749f471e6a900d3f662d1d3b6e2e59dcecf787b1cc3a1894", size = 153076, upload-time = "2025-10-14T04:41:19.106Z" }, + { url = "https://files.pythonhosted.org/packages/75/1e/5ff781ddf5260e387d6419959ee89ef13878229732732ee73cdae01800f2/charset_normalizer-3.4.4-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:bc7637e2f80d8530ee4a78e878bce464f70087ce73cf7c1caf142416923b98f1", size = 150601, upload-time = "2025-10-14T04:41:20.245Z" }, + { url = "https://files.pythonhosted.org/packages/d7/57/71be810965493d3510a6ca79b90c19e48696fb1ff964da319334b12677f0/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f8bf04158c6b607d747e93949aa60618b61312fe647a6369f88ce2ff16043490", size = 150376, upload-time = "2025-10-14T04:41:21.398Z" }, + { url = "https://files.pythonhosted.org/packages/e5/d5/c3d057a78c181d007014feb7e9f2e65905a6c4ef182c0ddf0de2924edd65/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:554af85e960429cf30784dd47447d5125aaa3b99a6f0683589dbd27e2f45da44", size = 144825, upload-time = "2025-10-14T04:41:22.583Z" }, + { url = "https://files.pythonhosted.org/packages/e6/8c/d0406294828d4976f275ffbe66f00266c4b3136b7506941d87c00cab5272/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:74018750915ee7ad843a774364e13a3db91682f26142baddf775342c3f5b1133", size = 162583, upload-time = "2025-10-14T04:41:23.754Z" }, + { url = "https://files.pythonhosted.org/packages/d7/24/e2aa1f18c8f15c4c0e932d9287b8609dd30ad56dbe41d926bd846e22fb8d/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:c0463276121fdee9c49b98908b3a89c39be45d86d1dbaa22957e38f6321d4ce3", size = 150366, upload-time = "2025-10-14T04:41:25.27Z" }, + { url = "https://files.pythonhosted.org/packages/e4/5b/1e6160c7739aad1e2df054300cc618b06bf784a7a164b0f238360721ab86/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:362d61fd13843997c1c446760ef36f240cf81d3ebf74ac62652aebaf7838561e", size = 160300, upload-time = "2025-10-14T04:41:26.725Z" }, + { url = "https://files.pythonhosted.org/packages/7a/10/f882167cd207fbdd743e55534d5d9620e095089d176d55cb22d5322f2afd/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:9a26f18905b8dd5d685d6d07b0cdf98a79f3c7a918906af7cc143ea2e164c8bc", size = 154465, upload-time = "2025-10-14T04:41:28.322Z" }, + { url = "https://files.pythonhosted.org/packages/89/66/c7a9e1b7429be72123441bfdbaf2bc13faab3f90b933f664db506dea5915/charset_normalizer-3.4.4-cp313-cp313-win32.whl", hash = "sha256:9b35f4c90079ff2e2edc5b26c0c77925e5d2d255c42c74fdb70fb49b172726ac", size = 99404, upload-time = "2025-10-14T04:41:29.95Z" }, + { url = "https://files.pythonhosted.org/packages/c4/26/b9924fa27db384bdcd97ab83b4f0a8058d96ad9626ead570674d5e737d90/charset_normalizer-3.4.4-cp313-cp313-win_amd64.whl", hash = "sha256:b435cba5f4f750aa6c0a0d92c541fb79f69a387c91e61f1795227e4ed9cece14", size = 107092, upload-time = "2025-10-14T04:41:31.188Z" }, + { url = "https://files.pythonhosted.org/packages/af/8f/3ed4bfa0c0c72a7ca17f0380cd9e4dd842b09f664e780c13cff1dcf2ef1b/charset_normalizer-3.4.4-cp313-cp313-win_arm64.whl", hash = "sha256:542d2cee80be6f80247095cc36c418f7bddd14f4a6de45af91dfad36d817bba2", size = 100408, upload-time = "2025-10-14T04:41:32.624Z" }, + { url = "https://files.pythonhosted.org/packages/2a/35/7051599bd493e62411d6ede36fd5af83a38f37c4767b92884df7301db25d/charset_normalizer-3.4.4-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:da3326d9e65ef63a817ecbcc0df6e94463713b754fe293eaa03da99befb9a5bd", size = 207746, upload-time = "2025-10-14T04:41:33.773Z" }, + { url = "https://files.pythonhosted.org/packages/10/9a/97c8d48ef10d6cd4fcead2415523221624bf58bcf68a802721a6bc807c8f/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8af65f14dc14a79b924524b1e7fffe304517b2bff5a58bf64f30b98bbc5079eb", size = 147889, upload-time = "2025-10-14T04:41:34.897Z" }, + { url = "https://files.pythonhosted.org/packages/10/bf/979224a919a1b606c82bd2c5fa49b5c6d5727aa47b4312bb27b1734f53cd/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:74664978bb272435107de04e36db5a9735e78232b85b77d45cfb38f758efd33e", size = 143641, upload-time = "2025-10-14T04:41:36.116Z" }, + { url = "https://files.pythonhosted.org/packages/ba/33/0ad65587441fc730dc7bd90e9716b30b4702dc7b617e6ba4997dc8651495/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:752944c7ffbfdd10c074dc58ec2d5a8a4cd9493b314d367c14d24c17684ddd14", size = 160779, upload-time = "2025-10-14T04:41:37.229Z" }, + { url = "https://files.pythonhosted.org/packages/67/ed/331d6b249259ee71ddea93f6f2f0a56cfebd46938bde6fcc6f7b9a3d0e09/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d1f13550535ad8cff21b8d757a3257963e951d96e20ec82ab44bc64aeb62a191", size = 159035, upload-time = "2025-10-14T04:41:38.368Z" }, + { url = "https://files.pythonhosted.org/packages/67/ff/f6b948ca32e4f2a4576aa129d8bed61f2e0543bf9f5f2b7fc3758ed005c9/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ecaae4149d99b1c9e7b88bb03e3221956f68fd6d50be2ef061b2381b61d20838", size = 152542, upload-time = "2025-10-14T04:41:39.862Z" }, + { url = "https://files.pythonhosted.org/packages/16/85/276033dcbcc369eb176594de22728541a925b2632f9716428c851b149e83/charset_normalizer-3.4.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cb6254dc36b47a990e59e1068afacdcd02958bdcce30bb50cc1700a8b9d624a6", size = 149524, upload-time = "2025-10-14T04:41:41.319Z" }, + { url = "https://files.pythonhosted.org/packages/9e/f2/6a2a1f722b6aba37050e626530a46a68f74e63683947a8acff92569f979a/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c8ae8a0f02f57a6e61203a31428fa1d677cbe50c93622b4149d5c0f319c1d19e", size = 150395, upload-time = "2025-10-14T04:41:42.539Z" }, + { url = "https://files.pythonhosted.org/packages/60/bb/2186cb2f2bbaea6338cad15ce23a67f9b0672929744381e28b0592676824/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:47cc91b2f4dd2833fddaedd2893006b0106129d4b94fdb6af1f4ce5a9965577c", size = 143680, upload-time = "2025-10-14T04:41:43.661Z" }, + { url = "https://files.pythonhosted.org/packages/7d/a5/bf6f13b772fbb2a90360eb620d52ed8f796f3c5caee8398c3b2eb7b1c60d/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:82004af6c302b5d3ab2cfc4cc5f29db16123b1a8417f2e25f9066f91d4411090", size = 162045, upload-time = "2025-10-14T04:41:44.821Z" }, + { url = "https://files.pythonhosted.org/packages/df/c5/d1be898bf0dc3ef9030c3825e5d3b83f2c528d207d246cbabe245966808d/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:2b7d8f6c26245217bd2ad053761201e9f9680f8ce52f0fcd8d0755aeae5b2152", size = 149687, upload-time = "2025-10-14T04:41:46.442Z" }, + { url = "https://files.pythonhosted.org/packages/a5/42/90c1f7b9341eef50c8a1cb3f098ac43b0508413f33affd762855f67a410e/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:799a7a5e4fb2d5898c60b640fd4981d6a25f1c11790935a44ce38c54e985f828", size = 160014, upload-time = "2025-10-14T04:41:47.631Z" }, + { url = "https://files.pythonhosted.org/packages/76/be/4d3ee471e8145d12795ab655ece37baed0929462a86e72372fd25859047c/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:99ae2cffebb06e6c22bdc25801d7b30f503cc87dbd283479e7b606f70aff57ec", size = 154044, upload-time = "2025-10-14T04:41:48.81Z" }, + { url = "https://files.pythonhosted.org/packages/b0/6f/8f7af07237c34a1defe7defc565a9bc1807762f672c0fde711a4b22bf9c0/charset_normalizer-3.4.4-cp314-cp314-win32.whl", hash = "sha256:f9d332f8c2a2fcbffe1378594431458ddbef721c1769d78e2cbc06280d8155f9", size = 99940, upload-time = "2025-10-14T04:41:49.946Z" }, + { url = "https://files.pythonhosted.org/packages/4b/51/8ade005e5ca5b0d80fb4aff72a3775b325bdc3d27408c8113811a7cbe640/charset_normalizer-3.4.4-cp314-cp314-win_amd64.whl", hash = "sha256:8a6562c3700cce886c5be75ade4a5db4214fda19fede41d9792d100288d8f94c", size = 107104, upload-time = "2025-10-14T04:41:51.051Z" }, + { url = "https://files.pythonhosted.org/packages/da/5f/6b8f83a55bb8278772c5ae54a577f3099025f9ade59d0136ac24a0df4bde/charset_normalizer-3.4.4-cp314-cp314-win_arm64.whl", hash = "sha256:de00632ca48df9daf77a2c65a484531649261ec9f25489917f09e455cb09ddb2", size = 100743, upload-time = "2025-10-14T04:41:52.122Z" }, + { url = "https://files.pythonhosted.org/packages/0a/4c/925909008ed5a988ccbb72dcc897407e5d6d3bd72410d69e051fc0c14647/charset_normalizer-3.4.4-py3-none-any.whl", hash = "sha256:7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f", size = 53402, upload-time = "2025-10-14T04:42:31.76Z" }, +] + +[[package]] +name = "chatmock" +version = "0.1.6" +source = { editable = "." } +dependencies = [ + { name = "blinker" }, + { name = "certifi" }, + { name = "click" }, + { name = "flask" }, + { name = "idna" }, + { name = "itsdangerous" }, + { name = "jinja2" }, + { name = "markupsafe" }, + { name = "requests" }, + { name = "urllib3" }, + { name = "werkzeug" }, +] + +[package.metadata] +requires-dist = [ + { name = "blinker", specifier = "==1.9.0" }, + { name = "certifi", specifier = "==2025.8.3" }, + { name = "click", specifier = "==8.2.1" }, + { name = "flask", specifier = "==3.1.1" }, + { name = "idna", specifier = "==3.10" }, + { name = "itsdangerous", specifier = "==2.2.0" }, + { name = "jinja2", specifier = "==3.1.6" }, + { name = "markupsafe", specifier = "==3.0.2" }, + { name = "requests", specifier = "==2.32.5" }, + { name = "urllib3", specifier = "==2.5.0" }, + { name = "werkzeug", specifier = "==3.1.3" }, +] + +[[package]] +name = "click" +version = "8.2.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/60/6c/8ca2efa64cf75a977a0d7fac081354553ebe483345c734fb6b6515d96bbc/click-8.2.1.tar.gz", hash = "sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202", size = 286342, upload-time = "2025-05-20T23:19:49.832Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl", hash = "sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b", size = 102215, upload-time = "2025-05-20T23:19:47.796Z" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "flask" +version = "3.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "blinker" }, + { name = "click" }, + { name = "itsdangerous" }, + { name = "jinja2" }, + { name = "markupsafe" }, + { name = "werkzeug" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c0/de/e47735752347f4128bcf354e0da07ef311a78244eba9e3dc1d4a5ab21a98/flask-3.1.1.tar.gz", hash = "sha256:284c7b8f2f58cb737f0cf1c30fd7eaf0ccfcde196099d24ecede3fc2005aa59e", size = 753440, upload-time = "2025-05-13T15:01:17.447Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/3d/68/9d4508e893976286d2ead7f8f571314af6c2037af34853a30fd769c02e9d/flask-3.1.1-py3-none-any.whl", hash = "sha256:07aae2bb5eaf77993ef57e357491839f5fd9f4dc281593a81a9e4d79a24f295c", size = 103305, upload-time = "2025-05-13T15:01:15.591Z" }, +] + +[[package]] +name = "idna" +version = "3.10" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f1/70/7703c29685631f5a7590aa73f1f1d3fa9a380e654b86af429e0934a32f7d/idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", size = 190490, upload-time = "2024-09-15T18:07:39.745Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442, upload-time = "2024-09-15T18:07:37.964Z" }, +] + +[[package]] +name = "itsdangerous" +version = "2.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9c/cb/8ac0172223afbccb63986cc25049b154ecfb5e85932587206f42317be31d/itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173", size = 54410, upload-time = "2024-04-16T21:28:15.614Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef", size = 16234, upload-time = "2024-04-16T21:28:14.499Z" }, +] + +[[package]] +name = "jinja2" +version = "3.1.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" }, +] + +[[package]] +name = "markupsafe" +version = "3.0.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b2/97/5d42485e71dfc078108a86d6de8fa46db44a1a9295e89c5d6d4a06e23a62/markupsafe-3.0.2.tar.gz", hash = "sha256:ee55d3edf80167e48ea11a923c7386f4669df67d7994554387f84e7d8b0a2bf0", size = 20537, upload-time = "2024-10-18T15:21:54.129Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/83/0e/67eb10a7ecc77a0c2bbe2b0235765b98d164d81600746914bebada795e97/MarkupSafe-3.0.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:ba9527cdd4c926ed0760bc301f6728ef34d841f405abf9d4f959c478421e4efd", size = 14274, upload-time = "2024-10-18T15:21:24.577Z" }, + { url = "https://files.pythonhosted.org/packages/2b/6d/9409f3684d3335375d04e5f05744dfe7e9f120062c9857df4ab490a1031a/MarkupSafe-3.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f8b3d067f2e40fe93e1ccdd6b2e1d16c43140e76f02fb1319a05cf2b79d99430", size = 12352, upload-time = "2024-10-18T15:21:25.382Z" }, + { url = "https://files.pythonhosted.org/packages/d2/f5/6eadfcd3885ea85fe2a7c128315cc1bb7241e1987443d78c8fe712d03091/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:569511d3b58c8791ab4c2e1285575265991e6d8f8700c7be0e88f86cb0672094", size = 24122, upload-time = "2024-10-18T15:21:26.199Z" }, + { url = "https://files.pythonhosted.org/packages/0c/91/96cf928db8236f1bfab6ce15ad070dfdd02ed88261c2afafd4b43575e9e9/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:15ab75ef81add55874e7ab7055e9c397312385bd9ced94920f2802310c930396", size = 23085, upload-time = "2024-10-18T15:21:27.029Z" }, + { url = "https://files.pythonhosted.org/packages/c2/cf/c9d56af24d56ea04daae7ac0940232d31d5a8354f2b457c6d856b2057d69/MarkupSafe-3.0.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f3818cb119498c0678015754eba762e0d61e5b52d34c8b13d770f0719f7b1d79", size = 22978, upload-time = "2024-10-18T15:21:27.846Z" }, + { url = "https://files.pythonhosted.org/packages/2a/9f/8619835cd6a711d6272d62abb78c033bda638fdc54c4e7f4272cf1c0962b/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:cdb82a876c47801bb54a690c5ae105a46b392ac6099881cdfb9f6e95e4014c6a", size = 24208, upload-time = "2024-10-18T15:21:28.744Z" }, + { url = "https://files.pythonhosted.org/packages/f9/bf/176950a1792b2cd2102b8ffeb5133e1ed984547b75db47c25a67d3359f77/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:cabc348d87e913db6ab4aa100f01b08f481097838bdddf7c7a84b7575b7309ca", size = 23357, upload-time = "2024-10-18T15:21:29.545Z" }, + { url = "https://files.pythonhosted.org/packages/ce/4f/9a02c1d335caabe5c4efb90e1b6e8ee944aa245c1aaaab8e8a618987d816/MarkupSafe-3.0.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:444dcda765c8a838eaae23112db52f1efaf750daddb2d9ca300bcae1039adc5c", size = 23344, upload-time = "2024-10-18T15:21:30.366Z" }, + { url = "https://files.pythonhosted.org/packages/ee/55/c271b57db36f748f0e04a759ace9f8f759ccf22b4960c270c78a394f58be/MarkupSafe-3.0.2-cp313-cp313-win32.whl", hash = "sha256:bcf3e58998965654fdaff38e58584d8937aa3096ab5354d493c77d1fdd66d7a1", size = 15101, upload-time = "2024-10-18T15:21:31.207Z" }, + { url = "https://files.pythonhosted.org/packages/29/88/07df22d2dd4df40aba9f3e402e6dc1b8ee86297dddbad4872bd5e7b0094f/MarkupSafe-3.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:e6a2a455bd412959b57a172ce6328d2dd1f01cb2135efda2e4576e8a23fa3b0f", size = 15603, upload-time = "2024-10-18T15:21:32.032Z" }, + { url = "https://files.pythonhosted.org/packages/62/6a/8b89d24db2d32d433dffcd6a8779159da109842434f1dd2f6e71f32f738c/MarkupSafe-3.0.2-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:b5a6b3ada725cea8a5e634536b1b01c30bcdcd7f9c6fff4151548d5bf6b3a36c", size = 14510, upload-time = "2024-10-18T15:21:33.625Z" }, + { url = "https://files.pythonhosted.org/packages/7a/06/a10f955f70a2e5a9bf78d11a161029d278eeacbd35ef806c3fd17b13060d/MarkupSafe-3.0.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:a904af0a6162c73e3edcb969eeeb53a63ceeb5d8cf642fade7d39e7963a22ddb", size = 12486, upload-time = "2024-10-18T15:21:34.611Z" }, + { url = "https://files.pythonhosted.org/packages/34/cf/65d4a571869a1a9078198ca28f39fba5fbb910f952f9dbc5220afff9f5e6/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4aa4e5faecf353ed117801a068ebab7b7e09ffb6e1d5e412dc852e0da018126c", size = 25480, upload-time = "2024-10-18T15:21:35.398Z" }, + { url = "https://files.pythonhosted.org/packages/0c/e3/90e9651924c430b885468b56b3d597cabf6d72be4b24a0acd1fa0e12af67/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c0ef13eaeee5b615fb07c9a7dadb38eac06a0608b41570d8ade51c56539e509d", size = 23914, upload-time = "2024-10-18T15:21:36.231Z" }, + { url = "https://files.pythonhosted.org/packages/66/8c/6c7cf61f95d63bb866db39085150df1f2a5bd3335298f14a66b48e92659c/MarkupSafe-3.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d16a81a06776313e817c951135cf7340a3e91e8c1ff2fac444cfd75fffa04afe", size = 23796, upload-time = "2024-10-18T15:21:37.073Z" }, + { url = "https://files.pythonhosted.org/packages/bb/35/cbe9238ec3f47ac9a7c8b3df7a808e7cb50fe149dc7039f5f454b3fba218/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:6381026f158fdb7c72a168278597a5e3a5222e83ea18f543112b2662a9b699c5", size = 25473, upload-time = "2024-10-18T15:21:37.932Z" }, + { url = "https://files.pythonhosted.org/packages/e6/32/7621a4382488aa283cc05e8984a9c219abad3bca087be9ec77e89939ded9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:3d79d162e7be8f996986c064d1c7c817f6df3a77fe3d6859f6f9e7be4b8c213a", size = 24114, upload-time = "2024-10-18T15:21:39.799Z" }, + { url = "https://files.pythonhosted.org/packages/0d/80/0985960e4b89922cb5a0bac0ed39c5b96cbc1a536a99f30e8c220a996ed9/MarkupSafe-3.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:131a3c7689c85f5ad20f9f6fb1b866f402c445b220c19fe4308c0b147ccd2ad9", size = 24098, upload-time = "2024-10-18T15:21:40.813Z" }, + { url = "https://files.pythonhosted.org/packages/82/78/fedb03c7d5380df2427038ec8d973587e90561b2d90cd472ce9254cf348b/MarkupSafe-3.0.2-cp313-cp313t-win32.whl", hash = "sha256:ba8062ed2cf21c07a9e295d5b8a2a5ce678b913b45fdf68c32d95d6c1291e0b6", size = 15208, upload-time = "2024-10-18T15:21:41.814Z" }, + { url = "https://files.pythonhosted.org/packages/4f/65/6079a46068dfceaeabb5dcad6d674f5f5c61a6fa5673746f42a9f4c233b3/MarkupSafe-3.0.2-cp313-cp313t-win_amd64.whl", hash = "sha256:e444a31f8db13eb18ada366ab3cf45fd4b31e4db1236a4448f68778c1d1a5a2f", size = 15739, upload-time = "2024-10-18T15:21:42.784Z" }, +] + +[[package]] +name = "requests" +version = "2.32.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c9/74/b3ff8e6c8446842c3f5c837e9c3dfcfe2018ea6ecef224c710c85ef728f4/requests-2.32.5.tar.gz", hash = "sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf", size = 134517, upload-time = "2025-08-18T20:46:02.573Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl", hash = "sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6", size = 64738, upload-time = "2025-08-18T20:46:00.542Z" }, +] + +[[package]] +name = "urllib3" +version = "2.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/15/22/9ee70a2574a4f4599c47dd506532914ce044817c7752a79b6a51286319bc/urllib3-2.5.0.tar.gz", hash = "sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760", size = 393185, upload-time = "2025-06-18T14:07:41.644Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl", hash = "sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc", size = 129795, upload-time = "2025-06-18T14:07:40.39Z" }, +] + +[[package]] +name = "werkzeug" +version = "3.1.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9f/69/83029f1f6300c5fb2471d621ab06f6ec6b3324685a2ce0f9777fd4a8b71e/werkzeug-3.1.3.tar.gz", hash = "sha256:60723ce945c19328679790e3282cc758aa4a6040e4bb330f53d30fa546d44746", size = 806925, upload-time = "2024-11-08T15:52:18.093Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl", hash = "sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e", size = 224498, upload-time = "2024-11-08T15:52:16.132Z" }, +] From df9727455549bee7838ecf9485e5cae8c4be9cae Mon Sep 17 00:00:00 2001 From: Magniquick <67406856+Magniquick@users.noreply.github.com> Date: Wed, 12 Nov 2025 20:11:41 +0530 Subject: [PATCH 2/4] feat(ollama): add version endpoint --- chatmock/routes_ollama.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/chatmock/routes_ollama.py b/chatmock/routes_ollama.py index 2772877..d6889dd 100644 --- a/chatmock/routes_ollama.py +++ b/chatmock/routes_ollama.py @@ -19,6 +19,19 @@ ollama_bp = Blueprint("ollama", __name__) +@ollama_bp.route("/api/version", methods=["GET"]) +def ollama_version() -> Response: + if bool(current_app.config.get("VERBOSE")): + print("IN GET /api/version") + version = current_app.config.get("OLLAMA_VERSION", "0.12.10") + if not isinstance(version, str) or not version.strip(): + version = "0.12.10" + resp = make_response(jsonify({"version": version}), 200) + for k, v in build_cors_headers().items(): + resp.headers.setdefault(k, v) + return resp + + def _instructions_for_model(model: str) -> str: base = current_app.config.get("BASE_INSTRUCTIONS", BASE_INSTRUCTIONS) if model == "gpt-5-codex": From 7a41cfdbcf0e63a74c843a43fc72c8dd7247b320 Mon Sep 17 00:00:00 2001 From: Magniquick <67406856+Magniquick@users.noreply.github.com> Date: Wed, 12 Nov 2025 20:14:06 +0530 Subject: [PATCH 3/4] feat(logging): improve verbose diagnostics --- chatmock/app.py | 2 + chatmock/cli.py | 8 ++ chatmock/routes_ollama.py | 118 +++++++++++++++++++----- chatmock/routes_openai.py | 188 ++++++++++++++++++++++++++------------ chatmock/upstream.py | 20 +++- docker/entrypoint.sh | 4 +- 6 files changed, 258 insertions(+), 82 deletions(-) diff --git a/chatmock/app.py b/chatmock/app.py index d9e2383..9727b5a 100644 --- a/chatmock/app.py +++ b/chatmock/app.py @@ -10,6 +10,7 @@ def create_app( verbose: bool = False, + verbose_obfuscation: bool = False, reasoning_effort: str = "medium", reasoning_summary: str = "auto", reasoning_compat: str = "think-tags", @@ -21,6 +22,7 @@ def create_app( app.config.update( VERBOSE=bool(verbose), + VERBOSE_OBFUSCATION=bool(verbose_obfuscation), REASONING_EFFORT=reasoning_effort, REASONING_SUMMARY=reasoning_summary, REASONING_COMPAT=reasoning_compat, diff --git a/chatmock/cli.py b/chatmock/cli.py index 2d95ecd..2c9df30 100644 --- a/chatmock/cli.py +++ b/chatmock/cli.py @@ -263,6 +263,7 @@ def cmd_serve( host: str, port: int, verbose: bool, + verbose_obfuscation: bool, reasoning_effort: str, reasoning_summary: str, reasoning_compat: str, @@ -272,6 +273,7 @@ def cmd_serve( ) -> int: app = create_app( verbose=verbose, + verbose_obfuscation=verbose_obfuscation, reasoning_effort=reasoning_effort, reasoning_summary=reasoning_summary, reasoning_compat=reasoning_compat, @@ -296,6 +298,11 @@ def main() -> None: p_serve.add_argument("--host", default="127.0.0.1") p_serve.add_argument("--port", type=int, default=8000) p_serve.add_argument("--verbose", action="store_true", help="Enable verbose logging") + p_serve.add_argument( + "--verbose-obfuscation", + action="store_true", + help="Also dump raw SSE/obfuscation events (in addition to --verbose request/response logs).", + ) p_serve.add_argument( "--debug-model", dest="debug_model", @@ -355,6 +362,7 @@ def main() -> None: host=args.host, port=args.port, verbose=args.verbose, + verbose_obfuscation=args.verbose_obfuscation, reasoning_effort=args.reasoning_effort, reasoning_summary=args.reasoning_summary, reasoning_compat=args.reasoning_compat, diff --git a/chatmock/routes_ollama.py b/chatmock/routes_ollama.py index d6889dd..848b4b5 100644 --- a/chatmock/routes_ollama.py +++ b/chatmock/routes_ollama.py @@ -19,6 +19,36 @@ ollama_bp = Blueprint("ollama", __name__) +def _log_json(prefix: str, payload: Any) -> None: + try: + print(f"{prefix}\n{json.dumps(payload, indent=2, ensure_ascii=False)}") + except Exception: + try: + print(f"{prefix}\n{payload}") + except Exception: + pass + + +def _wrap_stream_logging(label: str, iterator, enabled: bool): + if not enabled: + return iterator + + def _gen(): + for chunk in iterator: + try: + text = ( + chunk.decode("utf-8", errors="replace") + if isinstance(chunk, (bytes, bytearray)) + else str(chunk) + ) + print(f"{label}\n{text}") + except Exception: + pass + yield chunk + + return _gen() + + @ollama_bp.route("/api/version", methods=["GET"]) def ollama_version() -> Response: if bool(current_app.config.get("VERBOSE")): @@ -26,9 +56,12 @@ def ollama_version() -> Response: version = current_app.config.get("OLLAMA_VERSION", "0.12.10") if not isinstance(version, str) or not version.strip(): version = "0.12.10" - resp = make_response(jsonify({"version": version}), 200) + payload = {"version": version} + resp = make_response(jsonify(payload), 200) for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) + if bool(current_app.config.get("VERBOSE")): + _log_json("OUT GET /api/version", payload) return resp @@ -88,28 +121,34 @@ def ollama_tags() -> Response: }, } ) - resp = make_response(jsonify({"models": models}), 200) + payload = {"models": models} + resp = make_response(jsonify(payload), 200) for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) + if bool(current_app.config.get("VERBOSE")): + _log_json("OUT GET /api/tags", payload) return resp @ollama_bp.route("/api/show", methods=["POST"]) def ollama_show() -> Response: verbose = bool(current_app.config.get("VERBOSE")) + raw_body = request.get_data(cache=True, as_text=True) or "" + if verbose: + try: + print("IN POST /api/show\n" + raw_body) + except Exception: + pass try: - if verbose: - body_preview = (request.get_data(cache=True, as_text=True) or "")[:2000] - print("IN POST /api/show\n" + body_preview) + payload = json.loads(raw_body) if raw_body else (request.get_json(silent=True) or {}) except Exception: - pass - try: payload = request.get_json(silent=True) or {} - except Exception: - payload = {} model = payload.get("model") if not isinstance(model, str) or not model.strip(): - return jsonify({"error": "Model not found"}), 400 + err = {"error": "Model not found"} + if verbose: + _log_json("OUT POST /api/show", err) + return jsonify(err), 400 v1_show_response = { "modelfile": "# Modelfile generated by \"ollama show\"\n# To build a new Modelfile based on this one, replace the FROM line with:\n# FROM llava:latest\n\nFROM /models/blobs/sha256:placeholder\nTEMPLATE \"\"\"{{ .System }}\nUSER: {{ .Prompt }}\nASSISTANT: \"\"\"\nPARAMETER num_ctx 100000\nPARAMETER stop \"\"\nPARAMETER stop \"USER:\"\nPARAMETER stop \"ASSISTANT:\"", "parameters": "num_keep 24\nstop \"<|start_header_id|>\"\nstop \"<|end_header_id|>\"\nstop \"<|eot_id|>\"", @@ -129,6 +168,8 @@ def ollama_show() -> Response: }, "capabilities": ["completion", "vision", "tools", "thinking"], } + if verbose: + _log_json("OUT POST /api/show", v1_show_response) resp = make_response(jsonify(v1_show_response), 200) for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) @@ -145,10 +186,13 @@ def ollama_chat() -> Response: try: raw = request.get_data(cache=True, as_text=True) or "" if verbose: - print("IN POST /api/chat\n" + (raw[:2000] if isinstance(raw, str) else "")) + print("IN POST /api/chat\n" + (raw if isinstance(raw, str) else "")) payload = json.loads(raw) if raw else {} except Exception: - return jsonify({"error": "Invalid JSON body"}), 400 + err = {"error": "Invalid JSON body"} + if verbose: + _log_json("OUT POST /api/chat", err) + return jsonify(err), 400 model = payload.get("model") raw_messages = payload.get("messages") @@ -179,7 +223,10 @@ def ollama_chat() -> Response: if not (isinstance(_t, dict) and isinstance(_t.get("type"), str)): continue if _t.get("type") not in ("web_search", "web_search_preview"): - return jsonify({"error": "Only web_search/web_search_preview are supported in responses_tools"}), 400 + err = {"error": "Only web_search/web_search_preview are supported in responses_tools"} + if verbose: + _log_json("OUT POST /api/chat", err) + return jsonify(err), 400 extra_tools.append(_t) if not extra_tools and bool(current_app.config.get("DEFAULT_WEB_SEARCH")): rtc = payload.get("responses_tool_choice") @@ -193,7 +240,10 @@ def ollama_chat() -> Response: except Exception: size = 0 if size > MAX_TOOLS_BYTES: - return jsonify({"error": "responses_tools too large"}), 400 + err = {"error": "responses_tools too large"} + if verbose: + _log_json("OUT POST /api/chat", err) + return jsonify(err), 400 had_responses_tools = True tools_responses = (tools_responses or []) + extra_tools @@ -202,7 +252,10 @@ def ollama_chat() -> Response: tool_choice = rtc if not isinstance(model, str) or not isinstance(messages, list) or not messages: - return jsonify({"error": "Invalid request format"}), 400 + err = {"error": "Invalid request format"} + if verbose: + _log_json("OUT POST /api/chat", err) + return jsonify(err), 400 input_items = convert_chat_messages_to_responses_input(messages) @@ -218,6 +271,17 @@ def ollama_chat() -> Response: reasoning_param=build_reasoning_param(reasoning_effort, reasoning_summary, model_reasoning), ) if error_resp is not None: + if verbose: + try: + body = error_resp.get_data(as_text=True) + if body: + try: + parsed = json.loads(body) + except Exception: + parsed = body + _log_json("OUT POST /api/chat", parsed) + except Exception: + pass return error_resp record_rate_limits_from_response(upstream) @@ -245,17 +309,17 @@ def ollama_chat() -> Response: if err2 is None and upstream2 is not None and upstream2.status_code < 400: upstream = upstream2 else: - return ( - jsonify({"error": {"message": (err_body.get("error", {}) or {}).get("message", "Upstream error"), "code": "RESPONSES_TOOLS_REJECTED"}}), - (upstream2.status_code if upstream2 is not None else upstream.status_code), - ) + err = {"error": {"message": (err_body.get("error", {}) or {}).get("message", "Upstream error"), "code": "RESPONSES_TOOLS_REJECTED"}} + if verbose: + _log_json("OUT POST /api/chat", err) + return jsonify(err), (upstream2.status_code if upstream2 is not None else upstream.status_code) else: if verbose: print("/api/chat upstream error status=", upstream.status_code, " body:", json.dumps(err_body)[:2000]) - return ( - jsonify({"error": (err_body.get("error", {}) or {}).get("message", "Upstream error")}), - upstream.status_code, - ) + err = {"error": (err_body.get("error", {}) or {}).get("message", "Upstream error")} + if verbose: + _log_json("OUT POST /api/chat", err) + return jsonify(err), upstream.status_code created_at = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") model_out = model if isinstance(model, str) and model.strip() else normalized_model @@ -421,8 +485,12 @@ def _gen(): } done_obj.update(_OLLAMA_FAKE_EVAL) yield json.dumps(done_obj) + "\n" + if verbose: + print("OUT POST /api/chat (streaming response)") + stream_iter = stream_with_context(_gen()) + stream_iter = _wrap_stream_logging("STREAM OUT /api/chat", stream_iter, verbose) resp = current_app.response_class( - stream_with_context(_gen()), + stream_iter, status=200, mimetype="application/x-ndjson", ) @@ -494,6 +562,8 @@ def _gen(): "done_reason": "stop", } out_json.update(_OLLAMA_FAKE_EVAL) + if verbose: + _log_json("OUT POST /api/chat", out_json) resp = make_response(jsonify(out_json), 200) for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) diff --git a/chatmock/routes_openai.py b/chatmock/routes_openai.py index 13dc314..3555826 100644 --- a/chatmock/routes_openai.py +++ b/chatmock/routes_openai.py @@ -22,6 +22,36 @@ openai_bp = Blueprint("openai", __name__) +def _log_json(prefix: str, payload: Any) -> None: + try: + print(f"{prefix}\n{json.dumps(payload, indent=2, ensure_ascii=False)}") + except Exception: + try: + print(f"{prefix}\n{payload}") + except Exception: + pass + + +def _wrap_stream_logging(label: str, iterator, enabled: bool): + if not enabled: + return iterator + + def _gen(): + for chunk in iterator: + try: + text = ( + chunk.decode("utf-8", errors="replace") + if isinstance(chunk, (bytes, bytearray)) + else str(chunk) + ) + print(f"{label}\n{text}") + except Exception: + pass + yield chunk + + return _gen() + + def _instructions_for_model(model: str) -> str: base = current_app.config.get("BASE_INSTRUCTIONS", BASE_INSTRUCTIONS) if model == "gpt-5-codex": @@ -34,26 +64,28 @@ def _instructions_for_model(model: str) -> str: @openai_bp.route("/v1/chat/completions", methods=["POST"]) def chat_completions() -> Response: verbose = bool(current_app.config.get("VERBOSE")) + verbose_obfuscation = bool(current_app.config.get("VERBOSE_OBFUSCATION")) reasoning_effort = current_app.config.get("REASONING_EFFORT", "medium") reasoning_summary = current_app.config.get("REASONING_SUMMARY", "auto") reasoning_compat = current_app.config.get("REASONING_COMPAT", "think-tags") debug_model = current_app.config.get("DEBUG_MODEL") + raw = request.get_data(cache=True, as_text=True) or "" if verbose: try: - body_preview = (request.get_data(cache=True, as_text=True) or "")[:2000] - print("IN POST /v1/chat/completions\n" + body_preview) + print("IN POST /v1/chat/completions\n" + raw) except Exception: pass - - raw = request.get_data(cache=True, as_text=True) or "" try: payload = json.loads(raw) if raw else {} except Exception: try: payload = json.loads(raw.replace("\r", "").replace("\n", "")) except Exception: - return jsonify({"error": {"message": "Invalid JSON body"}}), 400 + err = {"error": {"message": "Invalid JSON body"}} + if verbose: + _log_json("OUT POST /v1/chat/completions", err) + return jsonify(err), 400 requested_model = payload.get("model") model = normalize_model_name(requested_model, debug_model) @@ -65,7 +97,10 @@ def chat_completions() -> Response: if messages is None: messages = [] if not isinstance(messages, list): - return jsonify({"error": {"message": "Request must include messages: []"}}), 400 + err = {"error": {"message": "Request must include messages: []"}} + if verbose: + _log_json("OUT POST /v1/chat/completions", err) + return jsonify(err), 400 if isinstance(messages, list): sys_idx = next((i for i, m in enumerate(messages) if isinstance(m, dict) and m.get("role") == "system"), None) @@ -88,17 +123,15 @@ def chat_completions() -> Response: if not (isinstance(_t, dict) and isinstance(_t.get("type"), str)): continue if _t.get("type") not in ("web_search", "web_search_preview"): - return ( - jsonify( - { - "error": { - "message": "Only web_search/web_search_preview are supported in responses_tools", - "code": "RESPONSES_TOOL_UNSUPPORTED", - } - } - ), - 400, - ) + err = { + "error": { + "message": "Only web_search/web_search_preview are supported in responses_tools", + "code": "RESPONSES_TOOL_UNSUPPORTED", + } + } + if verbose: + _log_json("OUT POST /v1/chat/completions", err) + return jsonify(err), 400 extra_tools.append(_t) if not extra_tools and bool(current_app.config.get("DEFAULT_WEB_SEARCH")): @@ -114,7 +147,10 @@ def chat_completions() -> Response: except Exception: size = 0 if size > MAX_TOOLS_BYTES: - return jsonify({"error": {"message": "responses_tools too large", "code": "RESPONSES_TOOLS_TOO_LARGE"}}), 400 + err = {"error": {"message": "responses_tools too large", "code": "RESPONSES_TOOLS_TOO_LARGE"}} + if verbose: + _log_json("OUT POST /v1/chat/completions", err) + return jsonify(err), 400 had_responses_tools = True tools_responses = (tools_responses or []) + extra_tools @@ -142,6 +178,17 @@ def chat_completions() -> Response: reasoning_param=reasoning_param, ) if error_resp is not None: + if verbose: + try: + body = error_resp.get_data(as_text=True) + if body: + try: + parsed = json.loads(body) + except Exception: + parsed = body + _log_json("OUT POST /v1/chat/completions", parsed) + except Exception: + pass return error_resp record_rate_limits_from_response(upstream) @@ -171,36 +218,38 @@ def chat_completions() -> Response: if err2 is None and upstream2 is not None and upstream2.status_code < 400: upstream = upstream2 else: - return ( - jsonify( - { - "error": { - "message": (err_body.get("error", {}) or {}).get("message", "Upstream error"), - "code": "RESPONSES_TOOLS_REJECTED", - } - } - ), - (upstream2.status_code if upstream2 is not None else upstream.status_code), - ) + err = { + "error": { + "message": (err_body.get("error", {}) or {}).get("message", "Upstream error"), + "code": "RESPONSES_TOOLS_REJECTED", + } + } + if verbose: + _log_json("OUT POST /v1/chat/completions", err) + return jsonify(err), (upstream2.status_code if upstream2 is not None else upstream.status_code) else: if verbose: print("Upstream error status=", upstream.status_code) - return ( - jsonify({"error": {"message": (err_body.get("error", {}) or {}).get("message", "Upstream error")}}), - upstream.status_code, - ) + err = {"error": {"message": (err_body.get("error", {}) or {}).get("message", "Upstream error")}} + if verbose: + _log_json("OUT POST /v1/chat/completions", err) + return jsonify(err), upstream.status_code if is_stream: + if verbose: + print("OUT POST /v1/chat/completions (streaming response)") + stream_iter = sse_translate_chat( + upstream, + requested_model or model, + created, + verbose=verbose_obfuscation, + vlog=print if verbose_obfuscation else None, + reasoning_compat=reasoning_compat, + include_usage=include_usage, + ) + stream_iter = _wrap_stream_logging("STREAM OUT /v1/chat/completions", stream_iter, verbose) resp = Response( - sse_translate_chat( - upstream, - requested_model or model, - created, - verbose=verbose, - vlog=print if verbose else None, - reasoning_compat=reasoning_compat, - include_usage=include_usage, - ), + stream_iter, status=upstream.status_code, mimetype="text/event-stream", headers={"Cache-Control": "no-cache", "Connection": "keep-alive"}, @@ -301,6 +350,8 @@ def _extract_usage(evt: Dict[str, Any]) -> Dict[str, int] | None: ], **({"usage": usage_obj} if usage_obj else {}), } + if verbose: + _log_json("OUT POST /v1/chat/completions", completion) resp = make_response(jsonify(completion), upstream.status_code) for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) @@ -310,15 +361,24 @@ def _extract_usage(evt: Dict[str, Any]) -> Dict[str, int] | None: @openai_bp.route("/v1/completions", methods=["POST"]) def completions() -> Response: verbose = bool(current_app.config.get("VERBOSE")) + verbose_obfuscation = bool(current_app.config.get("VERBOSE_OBFUSCATION")) debug_model = current_app.config.get("DEBUG_MODEL") reasoning_effort = current_app.config.get("REASONING_EFFORT", "medium") reasoning_summary = current_app.config.get("REASONING_SUMMARY", "auto") raw = request.get_data(cache=True, as_text=True) or "" + if verbose: + try: + print("IN POST /v1/completions\n" + raw) + except Exception: + pass try: payload = json.loads(raw) if raw else {} except Exception: - return jsonify({"error": {"message": "Invalid JSON body"}}), 400 + err = {"error": {"message": "Invalid JSON body"}} + if verbose: + _log_json("OUT POST /v1/completions", err) + return jsonify(err), 400 requested_model = payload.get("model") model = normalize_model_name(requested_model, debug_model) @@ -344,6 +404,17 @@ def completions() -> Response: reasoning_param=reasoning_param, ) if error_resp is not None: + if verbose: + try: + body = error_resp.get_data(as_text=True) + if body: + try: + parsed = json.loads(body) + except Exception: + parsed = body + _log_json("OUT POST /v1/completions", parsed) + except Exception: + pass return error_resp record_rate_limits_from_response(upstream) @@ -354,21 +425,25 @@ def completions() -> Response: err_body = json.loads(upstream.content.decode("utf-8", errors="ignore")) if upstream.content else {"raw": upstream.text} except Exception: err_body = {"raw": upstream.text} - return ( - jsonify({"error": {"message": (err_body.get("error", {}) or {}).get("message", "Upstream error")}}), - upstream.status_code, - ) + err = {"error": {"message": (err_body.get("error", {}) or {}).get("message", "Upstream error")}} + if verbose: + _log_json("OUT POST /v1/completions", err) + return jsonify(err), upstream.status_code if stream_req: + if verbose: + print("OUT POST /v1/completions (streaming response)") + stream_iter = sse_translate_text( + upstream, + requested_model or model, + created, + verbose=verbose_obfuscation, + vlog=(print if verbose_obfuscation else None), + include_usage=include_usage, + ) + stream_iter = _wrap_stream_logging("STREAM OUT /v1/completions", stream_iter, verbose) resp = Response( - sse_translate_text( - upstream, - requested_model or model, - created, - verbose=verbose, - vlog=(print if verbose else None), - include_usage=include_usage, - ), + stream_iter, status=upstream.status_code, mimetype="text/event-stream", headers={"Cache-Control": "no-cache", "Connection": "keep-alive"}, @@ -430,6 +505,8 @@ def _extract_usage(evt: Dict[str, Any]) -> Dict[str, int] | None: ], **({"usage": usage_obj} if usage_obj else {}), } + if verbose: + _log_json("OUT POST /v1/completions", completion) resp = make_response(jsonify(completion), upstream.status_code) for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) @@ -455,4 +532,3 @@ def list_models() -> Response: for k, v in build_cors_headers().items(): resp.headers.setdefault(k, v) return resp - diff --git a/chatmock/upstream.py b/chatmock/upstream.py index 56c9739..8938c7b 100644 --- a/chatmock/upstream.py +++ b/chatmock/upstream.py @@ -5,7 +5,7 @@ from typing import Any, Dict, List, Tuple import requests -from flask import Response, jsonify, make_response +from flask import Response, current_app, jsonify, make_response from .config import CHATGPT_RESPONSES_URL from .http import build_cors_headers @@ -14,6 +14,16 @@ from .utils import get_effective_chatgpt_auth +def _log_json(prefix: str, payload: Any) -> None: + try: + print(f"{prefix}\n{json.dumps(payload, indent=2, ensure_ascii=False)}") + except Exception: + try: + print(f"{prefix}\n{payload}") + except Exception: + pass + + def normalize_model_name(name: str | None, debug_model: str | None = None) -> str: if isinstance(debug_model, str) and debug_model.strip(): return debug_model.strip() @@ -99,6 +109,14 @@ def start_upstream_request( if reasoning_param is not None: responses_payload["reasoning"] = reasoning_param + verbose = False + try: + verbose = bool(current_app.config.get("VERBOSE")) + except Exception: + verbose = False + if verbose: + _log_json("OUTBOUND >> ChatGPT Responses API payload", responses_payload) + headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 2e04b4d..ddcec35 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -20,6 +20,9 @@ if [[ "$cmd" == "serve" ]]; then if bool "${VERBOSE:-}" || bool "${CHATGPT_LOCAL_VERBOSE:-}"; then ARGS+=(--verbose) fi + if bool "${VERBOSE_OBFUSCATION:-}" || bool "${CHATGPT_LOCAL_VERBOSE_OBFUSCATION:-}"; then + ARGS+=(--verbose-obfuscation) + fi if [[ "$#" -gt 0 ]]; then ARGS+=("$@") @@ -36,4 +39,3 @@ elif [[ "$cmd" == "login" ]]; then else exec "$cmd" "$@" fi - From 0d43459a35c94bf7cdd7a899d1d5db99141b0f07 Mon Sep 17 00:00:00 2001 From: Magniquick <67406856+Magniquick@users.noreply.github.com> Date: Wed, 12 Nov 2025 20:14:24 +0530 Subject: [PATCH 4/4] fix(stream): always send stop chunk --- chatmock/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/chatmock/utils.py b/chatmock/utils.py index 96af375..a32144b 100644 --- a/chatmock/utils.py +++ b/chatmock/utils.py @@ -389,6 +389,7 @@ def sse_translate_chat( think_open = False think_closed = False saw_output = False + sent_stop_chunk = False saw_any_summary = False pending_summary_paragraph = False upstream_usage = None @@ -738,6 +739,7 @@ def _merge_from(src): "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}], } yield f"data: {json.dumps(chunk)}\n\n".encode("utf-8") + sent_stop_chunk = True elif kind == "response.failed": err = evt.get("response", {}).get("error", {}).get("message", "response.failed") chunk = {"error": {"message": err}} @@ -757,6 +759,17 @@ def _merge_from(src): yield f"data: {json.dumps(close_chunk)}\n\n".encode("utf-8") think_open = False think_closed = True + if not sent_stop_chunk: + chunk = { + "id": response_id, + "object": "chat.completion.chunk", + "created": created, + "model": model, + "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}], + } + yield f"data: {json.dumps(chunk)}\n\n".encode("utf-8") + sent_stop_chunk = True + if include_usage and upstream_usage: try: usage_chunk = {