{"time": "2023-03-18T15:04:06.399264", "url": "https://dashboard.scale.com/spellbook/api/v2/deploy/", "input": "\n initial commit\n\ndiff --git a/lm/__init__.py b/lm/__init__.py\nnew file mode 100644\n--- /dev/null\n+++ b/lm/__init__.py\ndiff --git a/lm/__main__.py b/lm/__main__.py\nnew file mode 100644\n--- /dev/null\n+++ b/lm/__main__.py\n@@ -0,0 +1,44 @@\n+from .lm_spellbook import spellbook\n+\n+import argparse\n+import asyncio\n+import datetime\n+import json\n+import os\n+import sys\n+\n+async def main():\n+ timestamp = datetime.datetime.now().isoformat()\n+ parser = argparse.ArgumentParser()\n+ parser.add_argument('-l', '--logfile', type=argparse.FileType('w'), default=f'{timestamp}.json', help='Log file')\n+ parser.add_argument('-o', '--output', type=argparse.FileType('w'), default=sys.stdout, help='Output file')\n+ parser.add_argument('input_data', nargs='*', help='Input data or filename')\n+ args = parser.parse_args()\n+\n+ if len(args.input_data) == 1 and os.path.exists(args.input_data[0]):\n+ with open(args.input_data[1], 'r') as f:\n+ input_data = f.read()\n+ log_input(input_data, args.output)\n+ elif args.input_data:\n+ input_data = ' '.join(args.input_data)\n+ else:\n+ input_data = sys.stdin.read()\n+\n+ api = spellbook(\n+ api_key = 'clfcfnj7m003xti1a7hxt1739',\n+ app_id = 'sm43s5r'\n+ )\n+ async with api:\n+ response = await api(input_data)\n+\n+ json.dump({\n+ 'time': timestamp,\n+ 'url': api.url,\n+ 'input': input_data,\n+ 'output': response,\n+ }, args.logfile)\n+\n+ args.output.write(response)\n+\n+if __name__ == \"__main__\":\n+ asyncio.run(main())\ndiff --git a/lm/lm_spellbook.py b/lm/lm_spellbook.py\nnew file mode 100644\n--- /dev/null\n+++ b/lm/lm_spellbook.py\n@@ -0,0 +1,23 @@\n+import aiohttp\n+import json\n+import urllib.parse\n+\n+class spellbook(aiohttp.ClientSession):\n+ def __init__(self, api_key = 'clfcfnj7m003xti1a7hxt1739', app_id = 'sm43s5r', url = 'https://dashboard.scale.com/spellbook/api/v2/deploy/'):\n+ super().__init__()\n+ self.api_key = api_key\n+ self.app_id = app_id\n+ self.url = url\n+ async def __call__(self, input, **kwparams):\n+ kwparams['input'] = input\n+ headers = {\n+ 'Authorization': 'Basic ' + self.api_key,\n+ 'Content-Type': 'application/json',\n+ }\n+ data = {\n+ 'input': kwparams\n+ }\n+ url = urllib.parse.urljoin(self.url, self.app_id)\n+ async with self.post(url, data=json.dumps(data), headers=headers) as response:\n+ response_json = await response.json()\n+ return response_json.get('output', response_json)\ndiff --git a/setup.py b/setup.py\nnew file mode 100644\n--- /dev/null\n+++ b/setup.py\n@@ -0,0 +1,19 @@\n+from setuptools import setup, find_packages\n+\n+setup(\n+ name=\"lm\",\n+ version=\"0.0.1\",\n+ packages=find_packages(),\n+ install_requires=[],\n+ author=\"Your Name\",\n+ author_email=\"your.email@example.com\",\n+ description=\"lm\",\n+ long_description=open(\"README.md\").read(),\n+ long_description_content_type=\"text/markdown\",\n+ url=\"https://github.com/yourusername/lm\",\n+ classifiers=[\n+ \"Development Status :: 3 - Alpha\",\n+ \"License :: OSI Approved :: GNU Affero General Public License v3\",\n+ \"Programming Language :: Python :: 3\",\n+ ],\n+)\n\n factored logging into log_jsonfiles.py\n\ndiff --git a/lm/__main__.py b/lm/__main__.py\n--- a/lm/__main__.py\n+++ b/lm/__main__.py\n@@ -1,4 +1,5 @@\n from .lm_spellbook import spellbook\n+from .log_jsonfiles import jsonfiles\n \n import argparse\n import asyncio\n@@ -10,7 +11,6 @@ import sys\n async def main():\n timestamp = datetime.datetime.now().isoformat()\n parser = argparse.ArgumentParser()\n- parser.add_argument('-l', '--logfile', type=argparse.FileType('w'), default=f'{timestamp}.json', help='Log file')\n parser.add_argument('-o', '--output', type=argparse.FileType('w'), default=sys.stdout, help='Output file')\n parser.add_argument('input_data', nargs='*', help='Input data or filename')\n args = parser.parse_args()\n@@ -28,15 +28,16 @@ async def main():\n api_key = 'clfcfnj7m003xti1a7hxt1739',\n app_id = 'sm43s5r'\n )\n- async with api:\n+ log = jsonfiles(prefix = 'gpt4-')\n+ \n+ async with api, log:\n response = await api(input_data)\n-\n- json.dump({\n- 'time': timestamp,\n- 'url': api.url,\n- 'input': input_data,\n- 'output': response,\n- }, args.logfile)\n+ await log(\n+ time = timestamp,\n+ url = api.url,\n+ input = input_data,\n+ output = response,\n+ )\n \n args.output.write(response)\n \ndiff --git a/lm/log_jsonfiles.py b/lm/log_jsonfiles.py\nnew file mode 100644\n--- /dev/null\n+++ b/lm/log_jsonfiles.py\n@@ -0,0 +1,21 @@\n+import aiofiles\n+import datetime\n+import json\n+import os\n+\n+class jsonfiles:\n+ def __init__(self, path = os.path.abspath(os.curdir), prefix = '', suffix = ''):\n+ self.path = path\n+ self.prefix = prefix\n+ self.suffix = suffix\n+ async def __aenter__(self):\n+ self.timestamp = datetime.datetime.now().isoformat()\n+ fn = os.path.join(self.path, f'{self.prefix}{self.timestamp}{self.suffix}.json')\n+ self.filectx = aiofiles.open(fn, 'w')\n+ self.file = await self.filectx.__aenter__()\n+ async def __aexit__(self, *params, **kwparams):\n+ await self.filectx.__aexit__(*params, **kwparams)\n+ async def __call__(self, **kwparams):\n+ await self.file.write(\n+ json.dumps(kwparams)\n+ )\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -16,4 +16,7 @@ setup(\n \"License :: OSI Approved :: GNU Affero General Public License v3\",\n \"Programming Language :: Python :: 3\",\n ],\n+ install_requires=[\n+ \"aiofiles==0.6.0\",\n+ ],\n )\n\n added temp utility scripts\n\ndiff --git a/quickscripts/append.sh b/quickscripts/append.sh\nnew file mode 100755\n--- /dev/null\n+++ b/quickscripts/append.sh\n@@ -0,0 +1,5 @@\n+#!/usr/bim/env sh\n+git log --patch --reverse | grep -v ^commit | grep -v ^Date: | grep -v ^index | grep -v ^Author:\n+echo\n+echo \" $*\"\n+echo\ndiff --git a/quickscripts/patchfix.py b/quickscripts/patchfix.py\nnew file mode 100644\n--- /dev/null\n+++ b/quickscripts/patchfix.py\n@@ -0,0 +1,28 @@\n+import patch_ng as patch\n+\n+def parse(stream):\n+ ps = patch.PatchSet()\n+ status = ps.parse(stream)\n+ for file in ps.items:\n+ lines = list(open(file.source))\n+ offsettgt = 0\n+ for hunk in file.hunks:\n+ tgt = [line[1:].decode() for line in hunk.text if not line.startswith(b'-')]\n+ hunk.linestgt = len(tgt)\n+ src = [line[1:].decode() for line in hunk.text if not line.startswith(b'+')]\n+ hunk.linessrc = len(src)\n+ lns = [ln for offset in range(hunk.startsrc) for ln in (hunk.startsrc - offset, hunk.startsrc - offset)]\n+ for ln in lns:\n+ if lines[ln-1:ln-1+len(src)] == src:\n+ hunk.startsrc = ln\n+ break\n+ hunk.starttgt = hunk.startsrc + offsettgt\n+ offsettgt += hunk.linestgt - hunk.linessrc\n+ return ps\n+\n+if __name__ == '__main__':\n+ import sys\n+ #with open('setup.diff', 'rb') as f:\n+ # ps = parse(f)\n+ ps = parse(sys.stdin.buffer)\n+ ps.dump()\n\n let the main script be launchded with an 'lm' shell command\n\n", "output": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -16,4 +16,7 @@ setup(\n \"License :: OSI Approved :: GNU Affero General Public License v3\",\n \"Programming Language :: Python :: 3\",\n ],\n+ install_requires=[\n+ \"aiofiles==0.6.0\",\n+ ],\n+ entry_points={\n+ \"console_scripts\": [\n+ \"lm=lm.__main__:main\",\n+ ],\n+ },\n )"}