{"time": "2023-03-19T06:52:35.181375", "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 +1 @@\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 +1 @@\n from .lm_spellbook import spellbook\n+from .log_jsonfiles import jsonfiles\n \n import argparse\n import asyncio\n@@ -10 +11 @@ 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 +28 @@ 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 +8 @@ 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 +41 @@ 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 +1 @@\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 +1 @@\n from .lm.spellbook import spellbook\n+from .lm.openai import openai\n from .log.jsonfiles import jsonfiles\n \n import argparse\n@@ -24 +25 @@ 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 concatenate in content from filenames\n\ndiff --git a/lm/__main__.py b/lm/__main__.py\n--- a/lm/__main__.py\n+++ b/lm/__main__.py\n@@ -16 +16 @@ async def amain():\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+ input_data = []\n+ for item in args.input_data:\n+ if os.path.exists(item):\n+ with open(item, 'r') as f:\n+ input_data.append(f.read())\n+ else:\n+ input_data.append(item)\n+\n+ if input_data:\n+ input_data = ' '.join(input_data)\n else:\n input_data = sys.stdin.read()\n \n\n ensured newlines are used between input data where one is filecontent, whereas spaces still used between items where neither is filecontent\n\n", "output": "diff --git a/lm/__main__.py b/lm/__main__.py\n--- a/lm/__main__.py\n+++ b/lm/__main__.py\n@@ -16 +16 @@ async def amain():\n parser.add_argument('input_data', nargs='*', help='Input data or filename')\n args = parser.parse_args()\n \n- input_data = []\n+ input_data = [] # Initialize input_data as an empty list\n for item in args.input_data:\n if os.path.exists(item):\n with open(item, 'r') as f:\n input_data.append(f.read())\n+ input_data.append('\\n') # Add a newline between file contents\n else:\n input_data.append(item)\n+ input_data.append(' ') # Add a space between non-file items\n \n- if input_data:\n- input_data = ' '.join(input_data)\n+ input_data = ''.join(input_data).strip() # Join the input_data list and remove leading/trailing whitespace\n else:\n input_data = sys.stdin.read()\n"}