Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,29 @@ jobs:
with:
node-version: '18'

- name: Install dependencies
run: yarn install
- name: Bootstrap
run: ./scripts/bootstrap

- name: Check types
run: ./scripts/lint

build:
name: build
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Check build
run: ./scripts/build


2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.1-alpha.0"
".": "0.7.0"
}
54 changes: 27 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ Other package managers may work but are not officially supported for development

To set up the repository, run:

```bash
yarn
yarn build
```sh
$ yarn
$ yarn build
```

This will install all the required dependencies and build output files to `dist/`.

## Modifying/Adding code

Most of the SDK is generated code, and any modified code will be overridden on the next generation. The
`src/lib/` and `examples/` directories are exceptions and will never be overridden.
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.

## Adding and running examples

All files in the `examples/` directory are not modified by the Stainless generator and can be freely edited or
added to.
All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.

```bash
```ts
// add an example to examples/<your-example>.ts

#!/usr/bin/env -S npm run tsn -T
Expand All @@ -41,38 +41,38 @@ If you’d like to use the repository from source, you can either install from g

To install via git:

```bash
npm install git+ssh://git@github.com:openlayer-ai/openlayer-ts.git
```sh
$ npm install git+ssh://git@github.com:openlayer-ai/openlayer-ts.git
```

Alternatively, to link a local copy of the repo:

```bash
```sh
# Clone
git clone https://www.github.com/openlayer-ai/openlayer-ts
cd openlayer-ts
$ git clone https://www.github.com/openlayer-ai/openlayer-ts
$ cd openlayer-ts

# With yarn
yarn link
cd ../my-package
yarn link openlayer
$ yarn link
$ cd ../my-package
$ yarn link openlayer

# With pnpm
pnpm link --global
cd ../my-package
pnpm link -—global openlayer
$ pnpm link --global
$ cd ../my-package
$ pnpm link -—global openlayer
```

## 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.

```bash
npx prism mock path/to/your/openapi.yml
```sh
$ npx prism mock path/to/your/openapi.yml
```

```bash
yarn run test
```sh
$ yarn run test
```

## Linting and formatting
Expand All @@ -82,14 +82,14 @@ This repository uses [prettier](https://www.npmjs.com/package/prettier) and

To lint:

```bash
yarn lint
```sh
$ yarn lint
```

To format and fix all lint issues automatically:

```bash
yarn fix
```sh
$ yarn fix
```

## Publishing and releases
Expand Down
65 changes: 33 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,26 @@ const client = new Openlayer({
});

async function main() {
const dataStreamResponse = await client.inferencePipelines.data.stream(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
{
config: {
inputVariableNames: ['user_query'],
outputColumnName: 'output',
numOfTokenColumnName: 'tokens',
costColumnName: 'cost',
timestampColumnName: 'timestamp',
},
rows: [
{
user_query: 'what is the meaning of life?',
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
},
],
const response = await client.inferencePipelines.data.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
config: {
inputVariableNames: ['user_query'],
outputColumnName: 'output',
numOfTokenColumnName: 'tokens',
costColumnName: 'cost',
timestampColumnName: 'timestamp',
},
);
rows: [
{
user_query: 'what is the meaning of life?',
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1610000000,
},
],
});

console.log(dataStreamResponse.success);
console.log(response.success);
}

main();
Expand Down Expand Up @@ -82,11 +79,11 @@ async function main() {
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
timestamp: 1610000000,
},
],
};
const dataStreamResponse: Openlayer.InferencePipelines.DataStreamResponse =
const response: Openlayer.InferencePipelines.DataStreamResponse =
await client.inferencePipelines.data.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', params);
}

Expand All @@ -104,7 +101,7 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const dataStreamResponse = await client.inferencePipelines.data
const response = await client.inferencePipelines.data
.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
config: {
inputVariableNames: ['user_query'],
Expand All @@ -119,7 +116,7 @@ async function main() {
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
timestamp: 1610000000,
},
],
})
Expand Down Expand Up @@ -166,7 +163,7 @@ const client = new Openlayer({
});

// Or, configure per-request:
await client.inferencePipelines.data.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { config: { inputVariableNames: ['user_query'], outputColumnName: 'output', numOfTokenColumnName: 'tokens', costColumnName: 'cost', timestampColumnName: 'timestamp' }, rows: [{ user_query: 'what is the meaning of life?', output: '42', tokens: 7, cost: 0.02, timestamp: 1620000000 }] }, {
await client.inferencePipelines.data.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { config: { inputVariableNames: ['user_query'], outputColumnName: 'output', numOfTokenColumnName: 'tokens', costColumnName: 'cost', timestampColumnName: 'timestamp' }, rows: [{ user_query: 'what is the meaning of life?', output: '42', tokens: 7, cost: 0.02, timestamp: 1610000000 }] }, {
maxRetries: 5,
});
```
Expand All @@ -183,7 +180,7 @@ const client = new Openlayer({
});

// Override per-request:
await client.inferencePipelines.data.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { config: { inputVariableNames: ['user_query'], outputColumnName: 'output', numOfTokenColumnName: 'tokens', costColumnName: 'cost', timestampColumnName: 'timestamp' }, rows: [{ user_query: 'what is the meaning of life?', output: '42', tokens: 7, cost: 0.02, timestamp: 1620000000 }] }, {
await client.inferencePipelines.data.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { config: { inputVariableNames: ['user_query'], outputColumnName: 'output', numOfTokenColumnName: 'tokens', costColumnName: 'cost', timestampColumnName: 'timestamp' }, rows: [{ user_query: 'what is the meaning of life?', output: '42', tokens: 7, cost: 0.02, timestamp: 1610000000 }] }, {
timeout: 5 * 1000,
});
```
Expand Down Expand Up @@ -219,15 +216,15 @@ const response = await client.inferencePipelines.data
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
timestamp: 1610000000,
},
],
})
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: dataStreamResponse, response: raw } = await client.inferencePipelines.data
const { data: response, response: raw } = await client.inferencePipelines.data
.stream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
config: {
inputVariableNames: ['user_query'],
Expand All @@ -242,13 +239,13 @@ const { data: dataStreamResponse, response: raw } = await client.inferencePipeli
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
timestamp: 1610000000,
},
],
})
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(dataStreamResponse.success);
console.log(response.success);
```

### Making custom/undocumented requests
Expand Down Expand Up @@ -368,7 +365,7 @@ await client.inferencePipelines.data.stream(
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
timestamp: 1610000000,
},
],
},
Expand Down Expand Up @@ -399,3 +396,7 @@ The following runtimes are supported:
Note that React Native is not supported at this time.

If you are interested in other runtime environments, please open or upvote an issue on GitHub.

## Contributing

See [the contributing documentation](./CONTRIBUTING.md).
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openlayer",
"version": "0.0.1-alpha.0",
"version": "0.7.0",
"description": "The official TypeScript library for the Openlayer API",
"author": "Openlayer <support@openlayer.com>",
"types": "dist/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"packageManager": "yarn@1.22.22",
"files": [
"*"
"**/*"
],
"private": false,
"scripts": {
Expand Down Expand Up @@ -41,6 +41,7 @@
"eslint": "^8.49.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"iconv-lite": "^0.6.3",
"jest": "^29.4.0",
"prettier": "^3.0.0",
"ts-jest": "^29.1.0",
Expand Down
3 changes: 3 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ cd "$(dirname "$0")/.."

echo "==> Running eslint"
ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --ext ts,js .

echo "==> Running tsc"
./node_modules/.bin/tsc --noEmit
2 changes: 1 addition & 1 deletion src/_shims/node-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fd from 'formdata-node';
export { type Agent } from 'node:http';
export { type Readable } from 'node:stream';
export { type ReadStream as FsReadStream } from 'node:fs';
export { ReadableStream } from 'web-streams-polyfill';
export { ReadableStream } from 'node:stream/web';

export const fetch: typeof nf.default;

Expand Down
Loading