SIGN IN SIGN UP
openai / openai-node UNCLAIMED

Official JavaScript / TypeScript library for the OpenAI API

0 0 0 TypeScript
2024-02-02 19:53:33 +00:00
## Setting up the environment
2024-12-20 11:54:17 +00:00
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install).
2024-02-02 19:53:33 +00:00
Other package managers may work but are not officially supported for development.
To set up the repository, run:
2024-02-02 19:53:33 +00:00
```sh
$ yarn
$ yarn build
2024-02-02 19:53:33 +00:00
```
This will install all the required dependencies and build output files to `dist/`.
## Modifying/Adding code
2024-09-13 15:29:42 +00:00
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
result in merge conflicts between manual patches and changes from the generator. The generator will never
modify the contents of the `src/lib/` and `examples/` directories.
2024-02-02 19:53:33 +00:00
## Adding and running examples
2024-09-13 15:29:42 +00:00
All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.
2024-02-02 19:53:33 +00:00
```ts
2024-02-02 19:53:33 +00:00
// add an example to examples/<your-example>.ts
#!/usr/bin/env -S npm run tsn -T
```
2024-12-20 11:54:17 +00:00
```sh
$ chmod +x examples/<your-example>.ts
2024-02-02 19:53:33 +00:00
# run the example against your api
2024-12-20 11:54:17 +00:00
$ yarn tsn -T examples/<your-example>.ts
2024-02-02 19:53:33 +00:00
```
## Using the repository from source
If youd like to use the repository from source, you can either install from git or link to a cloned repository:
To install via git:
```sh
$ npm install git+ssh://git@github.com:openai/openai-node.git
2024-02-02 19:53:33 +00:00
```
Alternatively, to link a local copy of the repo:
```sh
2024-02-02 19:53:33 +00:00
# Clone
$ git clone https://www.github.com/openai/openai-node
$ cd openai-node
2024-02-02 19:53:33 +00:00
# With yarn
$ yarn link
$ cd ../my-package
$ yarn link openai
2024-02-02 19:53:33 +00:00
# With pnpm
$ pnpm link --global
$ cd ../my-package
$ pnpm link -—global openai
2024-02-02 19:53:33 +00:00
```
## Running tests
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
2024-02-02 19:53:33 +00:00
```sh
$ npx prism mock path/to/your/openapi.yml
2024-02-02 19:53:33 +00:00
```
```sh
$ yarn run test
2024-02-02 19:53:33 +00:00
```
## Linting and formatting
This repository uses [prettier](https://www.npmjs.com/package/prettier) and
[eslint](https://www.npmjs.com/package/eslint) to format the code in the repository.
To lint:
```sh
$ yarn lint
2024-02-02 19:53:33 +00:00
```
To format and fix all lint issues automatically:
```sh
$ yarn fix
2024-02-02 19:53:33 +00:00
```
## Publishing and releases
Changes made to this repository via the automated release PR pipeline should publish to npm automatically. If
the changes aren't made through the automated pipeline, you may want to make releases manually.
### Publish with a GitHub workflow
You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/openai/openai-node/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.
2024-02-02 19:53:33 +00:00
### Publish manually
If you need to manually release a package, you can run the `bin/publish-npm` script with an `NPM_TOKEN` set on
the environment.