diff --git a/.github/workflows/canary.yaml b/.github/workflows/canary.yaml index 9c11cd76..3c19cf66 100644 --- a/.github/workflows/canary.yaml +++ b/.github/workflows/canary.yaml @@ -172,6 +172,27 @@ jobs: - name: Test run: wing test working-directory: ngrok + canary-openai: + name: Test openai + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + sparse-checkout: openai + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: https://registry.npmjs.org + - name: Install winglang + run: npm i -g winglang + - name: Install dependencies + run: npm install --include=dev + working-directory: openai + - name: Test + run: wing test + working-directory: openai canary-postgres: name: Test postgres runs-on: ubuntu-latest diff --git a/.github/workflows/openai-pull.yaml b/.github/workflows/openai-pull.yaml new file mode 100644 index 00000000..ddadbd14 --- /dev/null +++ b/.github/workflows/openai-pull.yaml @@ -0,0 +1,29 @@ +name: openai-pull +on: + pull_request: + paths: + - openai/** +jobs: + build-openai: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + sparse-checkout: openai + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: https://registry.npmjs.org + - name: Install winglang + run: npm i -g winglang + - name: Install dependencies + run: npm install --include=dev + working-directory: openai + - name: Test + run: wing test + working-directory: openai + - name: Pack + run: wing pack + working-directory: openai diff --git a/.github/workflows/openai-release.yaml b/.github/workflows/openai-release.yaml new file mode 100644 index 00000000..3f61b2fe --- /dev/null +++ b/.github/workflows/openai-release.yaml @@ -0,0 +1,54 @@ +name: openai-release +on: + push: + branches: + - main + paths: + - openai/** + - "!openai/package-lock.json" +jobs: + build-openai: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + sparse-checkout: openai + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.x + registry-url: https://registry.npmjs.org + - name: Install winglang + run: npm i -g winglang + - name: Install dependencies + run: npm install --include=dev + working-directory: openai + - name: Test + run: wing test + working-directory: openai + - name: Pack + run: wing pack + working-directory: openai + - name: Get package version + run: echo WINGLIB_VERSION=$(node -p "require('./package.json').version") >> + "$GITHUB_ENV" + working-directory: openai + - name: Publish + run: npm publish --access=public --registry https://registry.npmjs.org --tag + latest *.tgz + working-directory: openai + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Tag commit + uses: tvdias/github-tagger@v0.0.1 + with: + repo-token: ${{ secrets.PROJEN_GITHUB_TOKEN }} + tag: openai-v${{ env.WINGLIB_VERSION }} + - name: GitHub release + uses: softprops/action-gh-release@v1 + with: + name: openai v${{ env.WINGLIB_VERSION }} + tag_name: openai-v${{ env.WINGLIB_VERSION }} + files: "*.tgz" + token: ${{ secrets.PROJEN_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 783e1112..6a5f24e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/node_modules/** target/ **/.env +.history/ diff --git a/.mergify.yml b/.mergify.yml index de54f02f..bc0d934c 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -59,6 +59,9 @@ pull_request_rules: - -check-failure=build-ngrok - -check-pending=build-ngrok - -check-stale=build-ngrok + - -check-failure=build-openai + - -check-pending=build-openai + - -check-stale=build-openai - -check-failure=build-postgres - -check-pending=build-postgres - -check-stale=build-postgres @@ -119,6 +122,9 @@ pull_request_rules: - -check-failure=build-ngrok - -check-pending=build-ngrok - -check-stale=build-ngrok + - -check-failure=build-openai + - -check-pending=build-openai + - -check-stale=build-openai - -check-failure=build-postgres - -check-pending=build-postgres - -check-stale=build-postgres diff --git a/README.md b/README.md index c2d0bf00..ff9571b3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,13 @@ It's so damn easy. Clone this repository: ```sh -git clone git@github.com:winglang/winglibs +git clone https://github.com/winglang/winglibs.git +``` + +Change to the `winglibs` directory: + +```sh +cd winglibs ``` Use the fabulous `mklib.sh` script to scaffold your library: @@ -74,6 +80,9 @@ bring my-awesome-lib ## Writing Wing Libraries See [docs](https://www.winglang.io/docs/libraries#creating-a-wing-library). + +Please note that it refers to writing libraries that are not published here, so it includes instructions for things that you get here automatically when using the `mklib.sh` script to scaffold your library. + ## License This repository is licensed under the [MIT License](./LICENSE), unless otherwise specified in a diff --git a/mklib.sh b/mklib.sh index f732bd1d..9ab90d62 100755 --- a/mklib.sh +++ b/mklib.sh @@ -8,6 +8,7 @@ mkdir $1 cat > $1/package.json < This is an initial version of this library which currently exposes a very small subset of the +> OpenAI API. + +## Prerequisites + +* [winglang](https://winglang.io). + +## Installation + +```sh +npm i @winglibs/openai +``` + +## Example + +```js +bring cloud; +bring openai; + +let key = new cloud.Secret(name: "OAIApiKey"); +let oai = new openai.OpenAI(apiKeySecret: key); + +new cloud.Function(inflight () => { + let joke = oai.createCompletion("tell me a short joke", model: "gpt-3.5-turbo", max_tokens: 2048); + log(joke); +}); +``` + +When running in a `test` context, the `createCompletion` method will return a JSON object which +echos the request under the `mock` key: + +```js +bring expect; + +test "create completion test" { + let r = oai.createCompletion("tell me a short joke"); + expect.equal(r, Json.stringify({ + mock: { + prompt:"tell me a short joke", + params:{"model":"gpt-3.5-turbo","max_tokens":2048} + } + })); +} +``` + +## Usage + +```js +new openai.OpenAI(); +``` + +* `apiKeySecret` - a `cloud.Secret` with the OpenAI API key (required). +* `orgSecret` - a `cloud.Secret` with the OpenAI organization ID (not required). + +You can also specify clear text values through `apiKey` and `org`, but make sure not to commit these +values to a repository :warning:. + +Methods: + +* `inflight createCompletion()` - requests a completion from a model. Options are `model` (defaults + to `gpt-3.5.turbo`) and `max_tokens` (defaults to 2048). + +## Roadmap + +* [ ] Support the rest of the OpenAI API +* [ ] Add more examples +* [ ] Add more tests + +## Maintainers + +* [Shai Ber](https://github.com/shaiber) + +## License + +Licensed under the [MIT License](/LICENSE). diff --git a/openai/api.w b/openai/api.w new file mode 100644 index 00000000..9ea0c07e --- /dev/null +++ b/openai/api.w @@ -0,0 +1,9 @@ +pub struct CompletionParams { + model: str; + max_tokens: num; +} + +// TODO: need to recreate the openai interface with higher fidelity +pub interface IOpenAI { + inflight createCompletion(prompt: str, params: CompletionParams?): str; +} diff --git a/openai/example.main.w b/openai/example.main.w new file mode 100644 index 00000000..ea969c12 --- /dev/null +++ b/openai/example.main.w @@ -0,0 +1,11 @@ +bring expect; +bring "./openai.w" as openai; + +bring cloud; + +let oai = new openai.OpenAI(apiKey: "my-openai-key"); + +new cloud.Function(inflight () => { + let answer = oai.createCompletion("tell me a short joke", model: "gpt-3.5-turbo", max_tokens: 2048); + log(answer); +}) as "tell me a joke"; diff --git a/openai/openai.extern.d.ts b/openai/openai.extern.d.ts new file mode 100644 index 00000000..ddb1e323 --- /dev/null +++ b/openai/openai.extern.d.ts @@ -0,0 +1,10 @@ +export default interface extern { + createNewInflightClient: (apiKey: string, org?: (string) | undefined) => Promise, +} +export interface CompletionParams { + readonly max_tokens: number; + readonly model: string; +} +export interface IOpenAI$Inflight { + readonly createCompletion: (prompt: string, params?: (CompletionParams) | undefined) => Promise; +} \ No newline at end of file diff --git a/openai/openai.js b/openai/openai.js new file mode 100644 index 00000000..0f6c0298 --- /dev/null +++ b/openai/openai.js @@ -0,0 +1,38 @@ +const openai = require('openai'); + +exports.createNewInflightClient = (apiKey, org) => { + const config = { apiKey }; + + if (org) { + config.organization = org; + } + + let client = new openai.OpenAI(config); + + // TODO: this is a hack for now, we should model the openai api in the api.w file with more fidelity + // and then we can just return the client itself, like we do in redis + return { + createCompletion: async (prompt, params = {}) => { + if (!prompt) { + throw new Error("Prompt is required"); + }; + + if (typeof prompt !== "string") { + throw new Error("Prompt must be a string"); + } + + if (!params.model) { + params.model = "gpt-3.5-turbo"; + }; + + if (!params.max_tokens) { + params.max_tokens = 2048; + } + + params.messages = [ { role: 'user', content: prompt } ]; + + const response = await client.chat.completions.create(params); + return response.choices[0]?.message?.content; + } + }; +}; diff --git a/openai/openai.test.w b/openai/openai.test.w new file mode 100644 index 00000000..5ab63fe7 --- /dev/null +++ b/openai/openai.test.w @@ -0,0 +1,19 @@ +bring expect; +bring "./openai.w" as openai; + +bring cloud; + +let key = "my-openai-key"; +let oai = new openai.OpenAI(apiKey: key); + +test "basic completion" { + let answer = oai.createCompletion("tell me a short joke", model :"gpt-3.5-turbo", max_tokens: 1024); + + // in tests, the response is just an echo of the request + expect.equal(answer, Json.stringify({ + mock: { + prompt:"tell me a short joke", + params:{"model":"gpt-3.5-turbo","max_tokens":1024} + } + })); +} diff --git a/openai/openai.w b/openai/openai.w new file mode 100644 index 00000000..be6a4737 --- /dev/null +++ b/openai/openai.w @@ -0,0 +1,60 @@ +bring util; +bring "./api.w" as api; +bring "./utils.w" as utils; +bring cloud; + +pub struct OpenAIProps { + apiKey: str?; + org: str?; + apiKeySecret: cloud.Secret?; + orgSecret: cloud.Secret?; +} + +inflight class Sim impl api.IOpenAI { + pub createCompletion(prompt: str, params: api.CompletionParams?): str { + return Json.stringify({ mock: { prompt: prompt, params: params } }); + } +} + +pub class OpenAI impl api.IOpenAI { + apiKey: cloud.Secret?; + org: cloud.Secret?; + keyOverride: str?; + orgOverride: str?; + + mock: bool; + + inflight openai: api.IOpenAI; + + new(props: OpenAIProps?) { + this.apiKey = props?.apiKeySecret; + this.org = props?.orgSecret; + this.keyOverride = props?.apiKey; + this.orgOverride = props?.org; + this.mock = util.env("WING_TARGET") == "sim" && nodeof(this).app.isTestEnvironment; + } + + inflight new() { + // TODO: https://github.com/winglang/wing/issues/5944 + let UNDEFINED = ""; + let apiKey = this.keyOverride ?? this.apiKey?.value() ?? UNDEFINED; + if apiKey == UNDEFINED { + throw "Either `apiKeySecret` or `apiKey` are required"; + } + + let var org: str? = this.orgOverride; + if org == nil { + org = this.org?.value(); + } + + if this.mock { + this.openai = new Sim(); + } else { + this.openai = utils.createNewInflightClient(apiKey, org); + } + } + + pub inflight createCompletion(prompt: str, params: api.CompletionParams?): str { + return this.openai.createCompletion(prompt, params); + } +} diff --git a/openai/package-lock.json b/openai/package-lock.json new file mode 100644 index 00000000..ea549f32 --- /dev/null +++ b/openai/package-lock.json @@ -0,0 +1,320 @@ +{ + "name": "@winglibs/openai", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@winglibs/openai", + "version": "0.0.1", + "license": "MIT", + "peerDependencies": { + "openai": "^4.28.4" + } + }, + "node_modules/@types/node": { + "version": "18.19.24", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.24.tgz", + "integrity": "sha512-eghAz3gnbQbvnHqB+mgB2ZR3aH6RhdEmHGS48BnV75KceQPHqabkxKI0BbUSsqhqy2Ddhc2xD/VAR9ySZd57Lw==", + "peer": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "peer": true, + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "peer": true, + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, + "node_modules/agentkeepalive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", + "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "peer": true, + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "peer": true + }, + "node_modules/base-64": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz", + "integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==", + "peer": true + }, + "node_modules/charenc": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", + "integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==", + "peer": true, + "engines": { + "node": "*" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "peer": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/crypt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz", + "integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==", + "peer": true, + "engines": { + "node": "*" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "peer": true, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/digest-fetch": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/digest-fetch/-/digest-fetch-1.3.0.tgz", + "integrity": "sha512-CGJuv6iKNM7QyZlM2T3sPAdZWd/p9zQiRNS9G+9COUCwzWFTs0Xp8NF5iePx7wtvhDykReiRRrSeNb4oMmB8lA==", + "peer": true, + "dependencies": { + "base-64": "^0.1.0", + "md5": "^2.3.0" + } + }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "peer": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "peer": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==", + "peer": true + }, + "node_modules/formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "peer": true, + "dependencies": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + }, + "engines": { + "node": ">= 12.20" + } + }, + "node_modules/formdata-node/node_modules/web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", + "peer": true, + "engines": { + "node": ">= 14" + } + }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "peer": true, + "dependencies": { + "ms": "^2.0.0" + } + }, + "node_modules/is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "peer": true + }, + "node_modules/md5": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz", + "integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==", + "peer": true, + "dependencies": { + "charenc": "0.0.2", + "crypt": "0.0.2", + "is-buffer": "~1.1.6" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "peer": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "peer": true, + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "peer": true + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "peer": true, + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "peer": true, + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/openai": { + "version": "4.28.4", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.28.4.tgz", + "integrity": "sha512-RNIwx4MT/F0zyizGcwS+bXKLzJ8QE9IOyigDG/ttnwB220d58bYjYFp0qjvGwEFBO6+pvFVIDABZPGDl46RFsg==", + "peer": true, + "dependencies": { + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "digest-fetch": "^1.3.0", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7", + "web-streams-polyfill": "^3.2.1" + }, + "bin": { + "openai": "bin/cli" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "peer": true + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "peer": true + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "peer": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "peer": true + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "peer": true, + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + } + } +} diff --git a/openai/package.json b/openai/package.json new file mode 100644 index 00000000..3319e2da --- /dev/null +++ b/openai/package.json @@ -0,0 +1,18 @@ +{ + "name": "@winglibs/openai", + "description": "OpenAI library for Wing", + "version": "0.0.1", + "repository": { + "type": "git", + "url": "https://github.com/winglang/winglibs.git", + "directory": "openai" + }, + "author": { + "email": "shaib@wing.cloud", + "name": "Shai Ber" + }, + "license": "MIT", + "peerDependencies": { + "openai": "^4.28.4" + } +} diff --git a/openai/utils.w b/openai/utils.w new file mode 100644 index 00000000..1f080534 --- /dev/null +++ b/openai/utils.w @@ -0,0 +1,5 @@ +bring "./api.w" as api; + +pub class Util { + extern "./openai.js" pub static inflight createNewInflightClient(apiKey: str, org: str?): api.IOpenAI; +} \ No newline at end of file