Open AI compatible API
This flow implements an API that is compatible with that of Open AI - see the related GitHub repository for more details.
Possible use cases could be:
- log any requests to the Open AI API - either for reporting reasons or just to learn how other scripts (like Auto-GPT or BabyAGI) use this API to reach their goals
- don't give your (secret!) Open AI API key to potentially dangerous scripts! Instead, add it to these flows only and configure your untrusted scripts to use these endpoints as a proxy;
- replace some (or all) requests to the Open AI API by your own implementations - e.g., based on other flows which use LLaMA, Stanford Alpaca, or GPT4All filtered or unfiltered or GPT4All-J models.
In any case, this proxy gives you much more control over Open AI API requests with respect to
- data privacy,
- safety and
- costs.
So far, I have already managed to instruct Auto-GPT to use my server instead of the official one - and BabyAGI will hopefully come next
[{"id":"155e2a4af3cf9013","type":"comment","z":"38c94c9449b1320c","name":"Open AI compatible API","info":"","x":120,"y":40,"wires":[]},{"id":"398d8e54dd61040a","type":"http in","z":"38c94c9449b1320c","name":"[get] /models","url":"/models","method":"get","upload":false,"swaggerDoc":"","x":90,"y":100,"wires":[["3cbe9350006a7907"]]},{"id":"e67c08aafcd630e5","type":"http in","z":"38c94c9449b1320c","name":"[get] /models/:model","url":"/models/:model","method":"get","upload":false,"swaggerDoc":"","x":110,"y":160,"wires":[["eae64d39de8bef36"]]},{"id":"56acef273fc149d4","type":"http in","z":"38c94c9449b1320c","name":"[post] /completions","url":"/completions","method":"post","upload":false,"swaggerDoc":"","x":110,"y":300,"wires":[["65c30bbdf12a6b6b"]]},{"id":"52e769513a7e095f","type":"http in","z":"38c94c9449b1320c","name":"[post] /chat/completions","url":"/chat/completions","method":"post","upload":false,"swaggerDoc":"","x":130,"y":360,"wires":[["9a119396466621e0"]]},{"id":"c569fb6b117049af","type":"http in","z":"38c94c9449b1320c","name":"[post] /edits","url":"/edits","method":"post","upload":false,"swaggerDoc":"","x":90,"y":420,"wires":[["0c4d971f34092ffe"]]},{"id":"844fad131ac7a626","type":"http in","z":"38c94c9449b1320c","name":"[post] /images/generations","url":"/images/generations","method":"post","upload":false,"swaggerDoc":"","x":130,"y":500,"wires":[["b30801229f7582a6"]]},{"id":"9417049fa7982328","type":"http in","z":"38c94c9449b1320c","name":"[post] /images/edits","url":"/images/edits","method":"post","upload":false,"swaggerDoc":"","x":110,"y":560,"wires":[["50344a11d8d13214"]]},{"id":"04790a33e11ab3c1","type":"http in","z":"38c94c9449b1320c","name":"[post] /images/variations","url":"/images/variations","method":"post","upload":false,"swaggerDoc":"","x":130,"y":620,"wires":[["b3e2a6a825918fcb"]]},{"id":"8ee81883ef4d48e6","type":"http in","z":"38c94c9449b1320c","name":"[post] /embeddings","url":"/embeddings","method":"post","upload":false,"swaggerDoc":"","x":110,"y":700,"wires":[["71ec73a472cc402d"]]},{"id":"6b095c2203c40e9a","type":"http in","z":"38c94c9449b1320c","name":"[post] /audio/transcriptions","url":"/audio/transcriptions","method":"post","upload":false,"swaggerDoc":"","x":130,"y":780,"wires":[["047813027a7531d0"]]},{"id":"2b2a976c74925255","type":"http in","z":"38c94c9449b1320c","name":"[post] /audio/translations","url":"/audio/translations","method":"post","upload":false,"swaggerDoc":"","x":130,"y":840,"wires":[["5387bd7dcf6ae9d1"]]},{"id":"1f98b646c255a3eb","type":"http in","z":"38c94c9449b1320c","name":"[get] /files","url":"/files","method":"get","upload":false,"swaggerDoc":"","x":740,"y":100,"wires":[["826fd2080bc51d0a"]]},{"id":"03f66f395fdd1bf7","type":"http in","z":"38c94c9449b1320c","name":"[post] /files","url":"/files","method":"post","upload":false,"swaggerDoc":"","x":740,"y":160,"wires":[["8ae4b50d65a34723"]]},{"id":"416f110765f776b0","type":"http in","z":"38c94c9449b1320c","name":"[delete] /files/:file_id","url":"/files/:file_id","method":"delete","upload":false,"swaggerDoc":"","x":770,"y":220,"wires":[["34d80b0e96522b94"]]},{"id":"747f66f784e80ad8","type":"http in","z":"38c94c9449b1320c","name":"[get] /files/:file_id","url":"/files/:file_id","method":"get","upload":false,"swaggerDoc":"","x":760,"y":280,"wires":[["d0c7a59ad7d8ed36"]]},{"id":"91258fd88750ddf3","type":"http in","z":"38c94c9449b1320c","name":"[get] /files/:file_id/content","url":"/files/:file_id/content","method":"get","upload":false,"swaggerDoc":"","x":790,"y":340,"wires":[["a6e0a23c52b3900d"]]},{"id":"fd3bc2bc5a744a05","type":"http in","z":"38c94c9449b1320c","name":"[post] /fine-tunes","url":"/fine-tunes","method":"post","upload":false,"swaggerDoc":"","x":760,"y":420,"wires":[["bae51e0ca27adba6"]]},{"id":"7bee5e0f444e3741","type":"http in","z":"38c94c9449b1320c","name":"[get] /fine-tunes","url":"/fine-tunes","method":"get","upload":false,"swaggerDoc":"","x":760,"y":480,"wires":[["d35091d6896d8404"]]},{"id":"f0d9b6059b55f14f","type":"http in","z":"38c94c9449b1320c","name":"[get] /fine-tunes/*","url":"/fine-tunes/:fine_tune_id","method":"get","upload":false,"swaggerDoc":"","x":760,"y":540,"wires":[["bee7aef07adc94cf"]]},{"id":"3ef9966e13cb0329","type":"http in","z":"38c94c9449b1320c","name":"[post] /fine-tunes/*/cancel","url":"/fine-tunes/:fine_tune_id/cancel","method":"post","upload":false,"swaggerDoc":"","x":790,"y":600,"wires":[["9bcf5bfc257dd8df"]]},{"id":"8f684174ce80a845","type":"http in","z":"38c94c9449b1320c","name":"[get] /fine-tunes/*/events","url":"/fine-tunes/:fine_tune_id/events","method":"get","upload":false,"swaggerDoc":"","x":790,"y":660,"wires":[["083b0d9e5fb3b56c"]]},{"id":"8f4b65a1f609683e","type":"http in","z":"38c94c9449b1320c","name":"[delete] /fine-tunes/*","url":"/fine-tunes/:fine_tune_id","method":"delete","upload":false,"swaggerDoc":"","x":770,"y":720,"wires":[["16930f1fd075cd31"]]},{"id":"07a55043a2b89139","type":"http in","z":"38c94c9449b1320c","name":"[post] /moderations","url":"/moderations","method":"post","upload":false,"swaggerDoc":"","x":770,"y":800,"wires":[["497a42326f08d9f7"]]},{"id":"bb62841fa9c886da","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":840,"wires":[]},{"id":"0877255fa26fbda4","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":780,"wires":[]},{"id":"b05cc5916c5d3fe4","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":700,"wires":[]},{"id":"13261e55fc5c2e33","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":620,"wires":[]},{"id":"0756d24483f97cb0","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":560,"wires":[]},{"id":"9b8ebbc8be5b5bfc","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":500,"wires":[]},{"id":"4bcb304551a75ee9","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":420,"wires":[]},{"id":"076c5defb823d6fc","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":360,"wires":[]},{"id":"52f2146f47ee1852","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":300,"wires":[]},{"id":"fa0d06be5c9cbfbb","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":160,"wires":[]},{"id":"8b21e62ef38def9d","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":100,"wires":[]},{"id":"868061a74a5d181c","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":800,"wires":[]},{"id":"29d5d9cb422a037e","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":720,"wires":[]},{"id":"69af2fcfece330f0","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":660,"wires":[]},{"id":"fba35018ec40e62f","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":600,"wires":[]},{"id":"d1a116227e948b2e","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":540,"wires":[]},{"id":"54e12e34945f55cd","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":480,"wires":[]},{"id":"2a2336a032d5a40b","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":420,"wires":[]},{"id":"e149b3adcfbbe045","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":340,"wires":[]},{"id":"bd315bf346a93fa4","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":280,"wires":[]},{"id":"092fed6d6fbaead5","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":220,"wires":[]},{"id":"dc965ef66bc83717","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":160,"wires":[]},{"id":"48641d00550f5a2d","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":1170,"y":100,"wires":[]},{"id":"645018581eb3f07a","type":"reusable-in","z":"38c94c9449b1320c","name":"not-implemented","info":"describe your reusable flow here","scope":"local","x":1430,"y":160,"wires":[["a6da72d9f4fc5261"]]},{"id":"a6da72d9f4fc5261","type":"function","z":"38c94c9449b1320c","name":"HTTP 501","func":"msg.payload = '501 not implemented'\nmsg.statusCode = 501\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"axios","module":"axios"}],"x":1620,"y":160,"wires":[["6adedc9247b4235f"]]},{"id":"6adedc9247b4235f","type":"reusable-out","z":"38c94c9449b1320c","name":"reusable out","position":1,"x":1790,"y":160,"wires":[]},{"id":"3cbe9350006a7907","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":100,"wires":[["8b21e62ef38def9d"]]},{"id":"eae64d39de8bef36","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":160,"wires":[["fa0d06be5c9cbfbb"]],"outputLabels":["reusable out"]},{"id":"65c30bbdf12a6b6b","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":300,"wires":[["52f2146f47ee1852"]],"outputLabels":["reusable out"]},{"id":"2547101badc937b0","type":"http in","z":"38c94c9449b1320c","name":"[delete] /models/:model","url":"/models/:model","method":"delete","upload":false,"swaggerDoc":"","x":120,"y":220,"wires":[["e76b8875b3e1bb14"]]},{"id":"244d8ba2701ed817","type":"http response","z":"38c94c9449b1320c","name":"","statusCode":"","headers":{},"x":510,"y":220,"wires":[]},{"id":"e76b8875b3e1bb14","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":220,"wires":[["244d8ba2701ed817"]],"outputLabels":["reusable out"]},{"id":"9a119396466621e0","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":360,"wires":[["076c5defb823d6fc"]],"outputLabels":["reusable out"]},{"id":"0c4d971f34092ffe","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":420,"wires":[["4bcb304551a75ee9"]],"outputLabels":["reusable out"]},{"id":"b30801229f7582a6","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":500,"wires":[["9b8ebbc8be5b5bfc"]],"outputLabels":["reusable out"]},{"id":"50344a11d8d13214","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":560,"wires":[["0756d24483f97cb0"]],"outputLabels":["reusable out"]},{"id":"b3e2a6a825918fcb","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":620,"wires":[["13261e55fc5c2e33"]],"outputLabels":["reusable out"]},{"id":"71ec73a472cc402d","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":700,"wires":[["b05cc5916c5d3fe4"]],"outputLabels":["reusable out"]},{"id":"047813027a7531d0","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":780,"wires":[["0877255fa26fbda4"]],"outputLabels":["reusable out"]},{"id":"5387bd7dcf6ae9d1","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":350,"y":840,"wires":[["bb62841fa9c886da"]],"outputLabels":["reusable out"]},{"id":"826fd2080bc51d0a","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":100,"wires":[["48641d00550f5a2d"]],"outputLabels":["reusable out"]},{"id":"8ae4b50d65a34723","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":160,"wires":[["dc965ef66bc83717"]],"outputLabels":["reusable out"]},{"id":"34d80b0e96522b94","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":220,"wires":[["092fed6d6fbaead5"]],"outputLabels":["reusable out"]},{"id":"d0c7a59ad7d8ed36","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":280,"wires":[["bd315bf346a93fa4"]],"outputLabels":["reusable out"]},{"id":"a6e0a23c52b3900d","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":340,"wires":[["e149b3adcfbbe045"]],"outputLabels":["reusable out"]},{"id":"bae51e0ca27adba6","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":420,"wires":[["2a2336a032d5a40b"]],"outputLabels":["reusable out"]},{"id":"d35091d6896d8404","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":480,"wires":[["54e12e34945f55cd"]],"outputLabels":["reusable out"]},{"id":"bee7aef07adc94cf","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":540,"wires":[["d1a116227e948b2e"]],"outputLabels":["reusable out"]},{"id":"9bcf5bfc257dd8df","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":600,"wires":[["fba35018ec40e62f"]],"outputLabels":["reusable out"]},{"id":"083b0d9e5fb3b56c","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":660,"wires":[["69af2fcfece330f0"]],"outputLabels":["reusable out"]},{"id":"16930f1fd075cd31","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":720,"wires":[["29d5d9cb422a037e"]],"outputLabels":["reusable out"]},{"id":"497a42326f08d9f7","type":"reusable","z":"38c94c9449b1320c","name":"","target":"ask open ai","outputs":1,"x":1010,"y":800,"wires":[["868061a74a5d181c"]],"outputLabels":["reusable out"]},{"id":"b8bf91ceb3124890","type":"comment","z":"38c94c9449b1320c","name":"pre-implemented request handlers","info":"","x":1480,"y":40,"wires":[]},{"id":"65836c9ee1c21078","type":"comment","z":"38c94c9449b1320c","name":"report any endpoint as \"not-implemented\" (Status Code 501)","info":"","x":1560,"y":100,"wires":[]},{"id":"18e0b9c3ebd10de0","type":"reusable-in","z":"38c94c9449b1320c","name":"ask Open AI","info":"describe your reusable flow here","scope":"local","x":1410,"y":300,"wires":[["29f1eed7352ed37e","70aa59bb2ea9a031"]]},{"id":"29f1eed7352ed37e","type":"function","z":"38c94c9449b1320c","name":"forward to Open AI","func":"let APIKey = global.get('OpenAI-API-Key')\n\nlet Authorization = (APIKey == null ? undefined : 'Bearer ' + APIKey)\nlet Organization = global.get('OpenAI-Organization')\n\naxios({\n method: msg.req.method,\n url: 'https://api.openai.com/v1' + msg.req.originalUrl,\n params: msg.req.query,\n headers:{\n 'Content-Type': msg.req.headers['content-type'],\n 'Authorization': Authorization || msg.req.headers['authorization'],\n 'OpenAI-Organization': Organization || msg.req.headers['openai-organization']\n },\n data: (msg.req.method === 'POST' ? msg.payload : undefined)\n}).then((Response) => {\n msg.statusCode = Response.status\n msg.status = Response.statusText\n \n msg.headers = {\n 'content-type': 'application/json',\n 'tasksolver-key': msg.req.headers['tasksolver-key']\n }\n msg.payload = Response.data\n \n node.send(msg)\n}).catch((Error) => {\n msg.headers = msg.headers = {\n 'tasksolver-key': msg.req.headers['tasksolver-key']\n }\n switch (true) {\n case (Error.response != null):\n msg.statusCode = Error.response.status\n msg.payload = '{' +\n '\"error\":{\"message\":\"' + Error.response.data + '\"}' +\n '}'\n break\n case (Error.request != null):\n default:\n msg.statusCode = 500\n msg.payload = '{' +\n '\"error\":{\"message\":\"' + Error.toString() + '\"}' +\n '\"data\":\"' + Error.toJSON() + '\"' +\n '}'\n }\n \n node.send(msg)\n})\nreturn null\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"axios","module":"axios"}],"x":1610,"y":300,"wires":[["f89db4f3d336529d"]]},{"id":"f89db4f3d336529d","type":"reusable-out","z":"38c94c9449b1320c","name":"reusable out","position":1,"x":1810,"y":300,"wires":[]},{"id":"ad9dda875dc36bdf","type":"comment","z":"38c94c9449b1320c","name":"forward any requests to the Open AI API","info":"","x":1500,"y":240,"wires":[]},{"id":"70aa59bb2ea9a031","type":"debug","z":"38c94c9449b1320c","name":"log API request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req.url & \"\\n\" & payload","targetType":"jsonata","statusVal":"","statusType":"auto","x":1600,"y":360,"wires":[]},{"id":"c832259eb801a1e3","type":"inject","z":"38c94c9449b1320c","name":"on Startup","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1410,"y":420,"wires":[["a5cb9e6e289cac86"]]},{"id":"a5cb9e6e289cac86","type":"function","z":"38c94c9449b1320c","name":"configure Open AI API access","func":"//global.set('OpenAI-API-Key','')\n//global.set('OpenAI-Organization','')\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1650,"y":420,"wires":[[]]}]