{"time": "2023-03-18T20:24:30.060298", "lm": "spellbook", "url": "https://dashboard.scale.com/spellbook/api/v2/deploy/", "input": "\n initial commit\n\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())\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 \n\n install console script; fix duplicate entry\n\ndiff --git a/lm/__main__.py b/lm/__main__.py\n--- a/lm/__main__.py\n+++ b/lm/__main__.py\n@@ -8,7 +8,7 @@ import json\n import os\n import sys\n \n-async def main():\n+async def amain():\n timestamp = datetime.datetime.now().isoformat()\n parser = argparse.ArgumentParser()\n parser.add_argument('-o', '--output', type=argparse.FileType('w'), default=sys.stdout, help='Output file')\n@@ -41,5 +41,8 @@ async def main():\n \n args.output.write(response)\n \n+def main():\n+ asyncio.run(amain())\n+\n if __name__ == \"__main__\":\n- asyncio.run(main())\n+ main()\n\n lm/lm and lm/log subpackages\n\ndiff --git a/lm/__main__.py b/lm/__main__.py\n--- a/lm/__main__.py\n+++ b/lm/__main__.py\n@@ -1,5 +1,5 @@\n-from .lm_spellbook import spellbook\n-from .log_jsonfiles import jsonfiles\n+from .lm.spellbook import spellbook\n+from .log.jsonfiles import jsonfiles\n \n import argparse\n import asyncio\n\n added openai api, untested\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 .lm.openai import openai\n from .log.jsonfiles import jsonfiles\n \n import argparse\n@@ -24,17 +25,14 @@ async def amain():\n else:\n input_data = sys.stdin.read()\n \n- api = spellbook(\n- api_key = 'clfcfnj7m003xti1a7hxt1739',\n- app_id = 'sm43s5r'\n- )\n+ api = spellbook()\n log = jsonfiles(prefix = 'gpt4-')\n \n async with api, log:\n response = await api(input_data)\n await log(\n time = timestamp,\n- url = api.url,\n+ **api.metadata,\n input = input_data,\n output = response,\n )\n\n positional params that are files are opened and their contents concatenated in\n", "output": "order\n\ndiff --git a/lm/__main__.py b/lm/__main__.py\n--- a/lm/__main__.py\n+++ b/lm/__main__.py\n@@ -12,14 +12,18 @@ async def amain():\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+ input_data = []\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+ for arg in args.input_data:\n+ if os.path.exists(arg):\n+ with open(arg, 'r') as f:\n+ input_data.append(f.read())\n+ else:\n+ input_data.append(arg)\n+\n+ input_data = ' '.join(input_data)\n else:\n input_data = sys.stdin.read()\n \n"}