From 9a9165484682105a152af6405c8f90869d1db09a Mon Sep 17 00:00:00 2001 From: Elliot Corvinova Date: Wed, 27 Mar 2024 19:45:42 -0700 Subject: [PATCH 1/2] Update repo to modern ooba OpenAI API streaming standards --- README.md | 12 ++-- browser_example.html | 2 +- node_example.mjs | 14 ++++- oobapi-ws.mjs | 132 ++++++++++++++++++++++++++++--------------- package-lock.json | 4 +- 5 files changed, 106 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 6039e80..cb49afa 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # oobapi-ws -[oobabooga/text-generation-webui](https://github.com/oobabooga/text-generation-webui) websocket api wrapper +[oobabooga/text-generation-webui](https://github.com/oobabooga/text-generation-webui) ~websocket~ streaming api wrapper - This is a simple isomorphic wrapper for the oobabooga websocket api (must be enabled when [launching ooba](https://github.com/oobabooga/text-generation-webui#api) with `--api`) + This is a simple isomorphic wrapper for the oobabooga ~websocket~ streaming api (must be enabled when [launching ooba](https://github.com/oobabooga/text-generation-webui#api) with `--api`) ## Usage - As this wrapper is meant to function the same in the browser as well as in node it must be passed a `WebSocket` object when instantiated. This can be either the browser context `WebSocket` or one from the [`ws` module](https://github.com/websockets/ws). See `node_example.mjs` and `browser_example.html` for more details. + ~~As this wrapper is meant to function the same in the browser as well as in node it must be passed a `WebSocket` object when instantiated. This can be either the browser context `WebSocket` or one from the [`ws` module](https://github.com/websockets/ws). See `node_example.mjs` and `browser_example.html` for more details.~~ No longer uses websockets. When instantiating the api you can specify a host and a port, as well as default generation options. ```js @@ -13,13 +13,13 @@ const generation_options = {max_new_tokens: 1000} const host = 'remote.host.net' const port = 1337 - const api = await ooba(WebSocket)({host,port}, generation_options) + const api = ooba({host,port}, generation_options) ``` or if you're running ooba locally and you want to use the default options you can omit both ```js - const api = await ooba(WebSocket)() + const api = ooba() ``` - this promise will return once a websocket connection to `localhost:5005` is established + this will return an api object that is ready to make streaming requests. in order to generate text simply call `api.generate()` with a prompt ```js diff --git a/browser_example.html b/browser_example.html index a6cef0c..1398977 100644 --- a/browser_example.html +++ b/browser_example.html @@ -13,7 +13,7 @@